diff --git a/approvaltests/src/main/java/org/approvaltests/ApprovedFileLog.java b/approvaltests/src/main/java/org/approvaltests/ApprovedFileLog.java index b13ce754..f6d646e9 100644 --- a/approvaltests/src/main/java/org/approvaltests/ApprovedFileLog.java +++ b/approvaltests/src/main/java/org/approvaltests/ApprovedFileLog.java @@ -6,13 +6,14 @@ public class ApprovedFileLog { + public static final String APPROVAL_TEMP_DIRECTORY = ".approval_tests_temp"; static { FileUtils.writeFile(get(), ""); } public static File get() { - File file = new File(".approval_tests_temp/.approved_files.log"); + File file = new File(APPROVAL_TEMP_DIRECTORY + "/.approved_files.log"); FileUtils.createIfNeeded(file.getAbsolutePath()); return file; } diff --git a/approvaltests/src/main/java/org/approvaltests/reporters/ReporterThatCreatesAnApprovalScript.java b/approvaltests/src/main/java/org/approvaltests/reporters/ReporterThatCreatesAnApprovalScript.java new file mode 100644 index 00000000..f8244d6b --- /dev/null +++ b/approvaltests/src/main/java/org/approvaltests/reporters/ReporterThatCreatesAnApprovalScript.java @@ -0,0 +1,45 @@ +package org.approvaltests.reporters; + +import com.spun.util.SystemUtils; +import com.spun.util.io.FileUtils; +import com.spun.util.logger.SimpleLogger; +import org.approvaltests.ApprovedFileLog; +import org.approvaltests.core.ApprovalFailureReporter; + +import java.io.File; + +public class ReporterThatCreatesAnApprovalScript implements ApprovalFailureReporter { + private static String fileName = "approval_script"; + private static File scriptFile = null; + static { + initializeFile(); + + } + + private static void initializeFile() { + if (scriptFile != null) {return;} + if (SystemUtils.isWindowsEnvironment()) { + initializeWindows(); + } else { + initializeLinux(); + } + SimpleLogger.event("Created approval script:\n" + scriptFile.getAbsolutePath()); + } + + private static void initializeLinux() { + + } + + private static void initializeWindows() { + scriptFile = new File(ApprovedFileLog.APPROVAL_TEMP_DIRECTORY + "\\" + fileName + ".bat"); + FileUtils.createIfNeeded(scriptFile.getAbsolutePath()); + FileUtils.writeFile(scriptFile, ""); + } + + @Override + public boolean report(String received, String approved) { + String commandLine = ClipboardReporter.getCommandLine(received, approved); + FileUtils.appendToFile(scriptFile, commandLine + "\r\n"); + return true; + } +}