Skip to content

Commit 8f673b3

Browse files
LarsEckartJayBazuziisidore
committed
@ r remove duplication. Lazy download the approve-all script
Co-authored-by: Jay Bazuzi <[email protected]> Co-authored-by: Llewellyn Falco <[email protected]>
1 parent e21060c commit 8f673b3

File tree

3 files changed

+22
-34
lines changed

3 files changed

+22
-34
lines changed

approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ void supportedFormats()
5454
VelocityApprovals.verify(c -> c.put("formats", DateScrubber.getSupportedFormats()),
5555
new Options().forFile().withExtension(".md"));
5656
}
57-
5857
@Disabled("use when new examples are shared at https://github.com/approvals/ApprovalTests.Java/issues/112")
5958
@Test
60-
void textExamples() {
59+
void textExamples()
60+
{
6161
String[] examples = """
62-
05/13/2014 11:50:49 PM
63-
2024-12-18T14:04:46-0500
64-
2025-07-17 14:58:02,123456
65-
""".split("\n");
62+
05/13/2014 11:50:49 PM
63+
2024-12-18T14:04:46-0500
64+
2025-07-17 14:58:02,123456
65+
""".split("\n");
6666
Approvals.verifyAll("Date scrubbing", examples, this::verifyScrubbing);
6767
}
6868
}

approvaltests/src/main/java/org/approvaltests/FailedFileLog.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,26 @@
1010

1111
public class FailedFileLog
1212
{
13+
private static boolean downloadedScriptCheck = false;
1314
static
1415
{
1516
FileUtils.writeFile(get(), "");
16-
downloadApproveAllScriptIfMissing();
1717
}
1818
private static void downloadApproveAllScriptIfMissing()
1919
{
20+
if (downloadedScriptCheck)
21+
{ return; }
22+
downloadedScriptCheck = true;
2023
try
2124
{
22-
if (SystemUtils.isWindowsEnvironment())
23-
{
24-
String url = "https://raw.githubusercontent.com/approvals/ApprovalTests.Java/refs/heads/master/resources/approve_all.bat";
25-
File batScript = new File(APPROVAL_TEMP_DIRECTORY + "/approve_all.bat");
26-
if (!batScript.exists())
27-
{
28-
FileUtils.writeFile(batScript, NetUtils.loadWebPage(url, null));
29-
}
30-
}
31-
else
25+
String extension = SystemUtils.isWindowsEnvironment() ? ".bat" : ".sh";
26+
File script = new File(APPROVAL_TEMP_DIRECTORY + "/approve_all" + extension);
27+
if (!script.exists())
3228
{
33-
String url = "https://raw.githubusercontent.com/approvals/ApprovalTests.Java/refs/heads/master/resources/approve_all.sh";
34-
File bashScript = new File(APPROVAL_TEMP_DIRECTORY + "/approve_all.sh");
35-
if (!bashScript.exists())
36-
{
37-
FileUtils.writeFile(bashScript, NetUtils.loadWebPage(url, null));
38-
bashScript.setExecutable(true);
39-
}
29+
String github = "https://raw.githubusercontent.com/approvals/ApprovalTests.Java/refs/heads/master/";
30+
String file = "resources/approve_all" + extension;
31+
FileUtils.writeFile(script, NetUtils.loadWebPage(github + file, null));
32+
script.setExecutable(true);
4033
}
4134
}
4235
catch (Exception e)
@@ -52,6 +45,7 @@ public static File get()
5245
}
5346
public static void log(File received, File approved)
5447
{
48+
downloadApproveAllScriptIfMissing();
5549
File log = get();
5650
FileUtils.appendToFile(log,
5751
String.format("%s -> %s\n", received.getAbsolutePath(), approved.getAbsolutePath()));

approvaltests/src/main/java/org/approvaltests/scrubbers/DateScrubber.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public DateScrubber(String pattern, Function1<Integer, String> replacement)
1717
}
1818
public static SupportedFormat[] getSupportedFormats()
1919
{
20-
return new SupportedFormat[]{__("[a-zA-Z]{3} [a-zA-Z]{3} \\d{2} \\d{2}:\\d{2}:\\d{2}",
21-
"Tue May 13 16:30:00"),
20+
return new SupportedFormat[]{__("[a-zA-Z]{3} [a-zA-Z]{3} \\d{2} \\d{2}:\\d{2}:\\d{2}", "Tue May 13 16:30:00"),
2221
__("[a-zA-Z]{3} [a-zA-Z]{3} \\d{2} \\d{2}:\\d{2}:\\d{2} [a-zA-Z]{3,4} \\d{4}",
2322
"Wed Nov 17 22:28:33 EET 2021"),
2423
__("(Mon|Tue|Wed|Thu|Fri|Sat|Sun), \\d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d{4} \\d{2}:\\d{2}:\\d{2} GMT",
@@ -45,14 +44,9 @@ public static SupportedFormat[] getSupportedFormats()
4544
__("\\d{4}-\\d{1,2}-\\d{1,2}T\\d{1,2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z",
4645
"2024-12-18T14:04:46.746130Z", "2024-12-18T14:04:46Z",
4746
"2024-12-18T14:04:46.746130834Z"),
48-
__("\\d{2}[-/.]\\d{2}[-/.]\\d{4}\\s\\d{2}:\\d{2}(:\\d{2})?( (?:pm|am|PM|AM))?" ,
49-
"13/05/2014 23:50:49",
50-
"13.05.2014 23:50:49",
51-
"13-05-2014 23:50:49",
52-
"13.05.2014 23:50",
53-
"05/13/2014 11:50:49 PM"
54-
),
55-
};
47+
__("\\d{2}[-/.]\\d{2}[-/.]\\d{4}\\s\\d{2}:\\d{2}(:\\d{2})?( (?:pm|am|PM|AM))?",
48+
"13/05/2014 23:50:49", "13.05.2014 23:50:49", "13-05-2014 23:50:49",
49+
"13.05.2014 23:50", "05/13/2014 11:50:49 PM"),};
5650
}
5751
private static SupportedFormat __(String regex, String... examples)
5852
{

0 commit comments

Comments
 (0)