Skip to content

Commit a65f352

Browse files
committed
- F ReporterThatCreatesAnApprovalScript for Windows
1 parent a53cea9 commit a65f352

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

approvaltests/src/main/java/org/approvaltests/ApprovedFileLog.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
public class ApprovedFileLog
88
{
9+
public static final String APPROVAL_TEMP_DIRECTORY = ".approval_tests_temp";
910
static
1011
{
1112
FileUtils.writeFile(get(), "");
1213
}
1314
public static File get()
1415
{
15-
File file = new File(".approval_tests_temp/.approved_files.log");
16+
File file = new File(APPROVAL_TEMP_DIRECTORY + "/.approved_files.log");
1617
FileUtils.createIfNeeded(file.getAbsolutePath());
1718
return file;
1819
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.approvaltests.reporters;
2+
3+
import com.spun.util.SystemUtils;
4+
import com.spun.util.io.FileUtils;
5+
import com.spun.util.logger.SimpleLogger;
6+
import org.approvaltests.ApprovedFileLog;
7+
import org.approvaltests.core.ApprovalFailureReporter;
8+
9+
import java.io.File;
10+
11+
public class ReporterThatCreatesAnApprovalScript implements ApprovalFailureReporter {
12+
private static String fileName = "approval_script";
13+
private static File scriptFile = null;
14+
static {
15+
initializeFile();
16+
17+
}
18+
19+
private static void initializeFile() {
20+
if (scriptFile != null) {return;}
21+
if (SystemUtils.isWindowsEnvironment()) {
22+
initializeWindows();
23+
} else {
24+
initializeLinux();
25+
}
26+
SimpleLogger.event("Created approval script:\n" + scriptFile.getAbsolutePath());
27+
}
28+
29+
private static void initializeLinux() {
30+
31+
}
32+
33+
private static void initializeWindows() {
34+
scriptFile = new File(ApprovedFileLog.APPROVAL_TEMP_DIRECTORY + "\\" + fileName + ".bat");
35+
FileUtils.createIfNeeded(scriptFile.getAbsolutePath());
36+
FileUtils.writeFile(scriptFile, "");
37+
}
38+
39+
@Override
40+
public boolean report(String received, String approved) {
41+
String commandLine = ClipboardReporter.getCommandLine(received, approved);
42+
FileUtils.appendToFile(scriptFile, commandLine + "\r\n");
43+
return true;
44+
}
45+
}

0 commit comments

Comments
 (0)