File tree Expand file tree Collapse file tree 6 files changed +21
-9
lines changed
approvaltests-tests/src/test/java/org/approvaltests
approvaltests/src/main/java/org/approvaltests Expand file tree Collapse file tree 6 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -24,4 +24,3 @@ __pycache__/
2424* .bak
2525
2626.gitmessage
27- .approval_tests_temp /
Original file line number Diff line number Diff line change 22
33import com .spun .util .io .FileUtils ;
44import org .approvaltests .internal .logs .ApprovedFileLog ;
5+ import org .approvaltests .internal .logs .LoggingUtils ;
56import org .approvaltests .namer .ApprovalNamer ;
67import org .junit .Assert ;
78import org .junit .jupiter .api .Test ;
89
910import java .io .File ;
1011
12+ import static org .junit .jupiter .api .Assertions .assertEquals ;
13+
1114public class ApprovedFileLogTest
1215{
1316 @ Test
@@ -17,9 +20,16 @@ void testLogging()
1720 ApprovalNamer approvalNamer = Approvals .createApprovalNamer ();
1821 File approvedFile = approvalNamer .getApprovedFile (".txt" );
1922 String prelog = FileUtils .readFile (file );
23+ // TODO
2024 Assert .assertFalse (prelog .contains (approvedFile .getAbsolutePath ()));
2125 Approvals .verify ("anything" );
2226 String postlog = FileUtils .readFile (file );
2327 Assert .assertTrue (postlog .contains (approvedFile .getAbsolutePath ()));
2428 }
29+ @ Test
30+ void testTempDirectoryGetsGitIgnore ()
31+ {
32+ String result = FileUtils .readFile (LoggingUtils .getTempDirectory () + "/.gitignore" );
33+ assertEquals ("*\n " , result );
34+ }
2535}
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ public class ApprovedFileLog
1414 }
1515 public static File get ()
1616 {
17- File file = new File (LoggingUtils .APPROVAL_TEMP_DIRECTORY + "/.approved_files.log" );
17+ File file = new File (LoggingUtils .getTempDirectory () + "/.approved_files.log" );
1818 FileUtils .createIfNeeded (file .getAbsolutePath ());
1919 return file ;
2020 }
Original file line number Diff line number Diff line change 55
66import java .io .File ;
77
8- import static org .approvaltests .internal .logs .LoggingUtils .APPROVAL_TEMP_DIRECTORY ;
9-
108public class FailedFileLog
119{
1210 static
@@ -19,7 +17,7 @@ private static void downloadApproveAllScriptIfMissing()
1917 }
2018 public static File get ()
2119 {
22- File file = new File (APPROVAL_TEMP_DIRECTORY + "/.failed_comparison.log" );
20+ File file = new File (LoggingUtils . getTempDirectory () + "/.failed_comparison.log" );
2321 FileUtils .createIfNeeded (file .getAbsolutePath ());
2422 return file ;
2523 }
Original file line number Diff line number Diff line change 99
1010public class LoggingUtils
1111{
12- public static final String APPROVAL_TEMP_DIRECTORY = ".approval_tests_temp" ;
1312 public static void downloadScriptIfMissing (String scriptName )
1413 {
1514 try
1615 {
1716 String extension = SystemUtils .isWindowsEnvironment () ? ".bat" : ".sh" ;
18- File script = new File (APPROVAL_TEMP_DIRECTORY + "/" + scriptName + extension );
17+ File script = new File (getTempDirectory () + "/" + scriptName + extension );
1918 if (!script .exists ())
2019 {
2120 String github = "https://raw.githubusercontent.com/approvals/ApprovalTests.Java/refs/heads/master/" ;
@@ -29,4 +28,10 @@ public static void downloadScriptIfMissing(String scriptName)
2928 // do nothing
3029 }
3130 }
31+ public static File getTempDirectory ()
32+ {
33+ File approvalTestsTempDir = new File (".approval_tests_temp" );
34+ FileUtils .writeFile (new File (approvalTestsTempDir + "/.gitignore" ), "*" );
35+ return approvalTestsTempDir ;
36+ }
3237}
Original file line number Diff line number Diff line change @@ -32,14 +32,14 @@ private static void initializeFile()
3232 }
3333 private static void initializeLinux ()
3434 {
35- scriptFile = new File (LoggingUtils .APPROVAL_TEMP_DIRECTORY + "/" + fileName + ".sh" );
35+ scriptFile = new File (LoggingUtils .getTempDirectory () + "/" + fileName + ".sh" );
3636 FileUtils .createIfNeeded (scriptFile .getAbsolutePath ());
3737 FileUtils .writeFile (scriptFile , "#!/bin/bash\n " );
3838 scriptFile .setExecutable (true );
3939 }
4040 private static void initializeWindows ()
4141 {
42- scriptFile = new File (LoggingUtils .APPROVAL_TEMP_DIRECTORY + "\\ " + fileName + ".bat" );
42+ scriptFile = new File (LoggingUtils .getTempDirectory () + "\\ " + fileName + ".bat" );
4343 FileUtils .createIfNeeded (scriptFile .getAbsolutePath ());
4444 FileUtils .writeFile (scriptFile , "" );
4545 }
You can’t perform that action at this time.
0 commit comments