Skip to content

Commit

Permalink
- F ReporterThatCreatesAnApprovalScript for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottBob committed Dec 12, 2024
1 parent a53cea9 commit a65f352
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit a65f352

Please sign in to comment.