From 3c5b09c7730d4746cc40cb90246eaf48ee01ec9f Mon Sep 17 00:00:00 2001 From: Svante Schubert Date: Mon, 6 May 2024 12:07:37 +0200 Subject: [PATCH] Fixed regression tests, which only worked on Linux due to linux line endings --- .../saxon/DecimalBasedFloatingPointTest.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/test/java/net/sf/saxon/DecimalBasedFloatingPointTest.java b/src/test/java/net/sf/saxon/DecimalBasedFloatingPointTest.java index 62962fd..19dca81 100755 --- a/src/test/java/net/sf/saxon/DecimalBasedFloatingPointTest.java +++ b/src/test/java/net/sf/saxon/DecimalBasedFloatingPointTest.java @@ -88,8 +88,11 @@ void testRounding() { if (refFile.exists()) { String referenceResult = Files.readString(Paths.get(refFile.toURI()), Charset.forName("UTF-8")); if (!resultReloaded.equals(referenceResult)) { - compareTextFiles(TARGET_DIR + reportFileName, REFERENCES_DIR + reportFileName); - Assertions.fail("\nRegression test fails as reference was different!\nNote: If the test fails due to a new output (e.g. programming update) copy the new result over the old reference:\n\t" + TARGET_DIR + reportFileName + "\n\t\tto" + "\n\t" + REFERENCES_DIR + reportFileName); + Boolean hasDifference = Boolean.FALSE; + hasDifference = compareTextFiles(TARGET_DIR + reportFileName, REFERENCES_DIR + reportFileName); + if(hasDifference){ + Assertions.fail("\nRegression test fails as reference was different!\nNote: If the test fails due to a new output (e.g. programming update) copy the new result over the old reference:\n\t" + TARGET_DIR + reportFileName + "\n\t\tto" + "\n\t" + REFERENCES_DIR + reportFileName); + } } } } catch (IOException ex) { @@ -141,8 +144,11 @@ void testPrecision() { if (refFile.exists()) { String referenceResult = Files.readString(Paths.get(refFile.toURI()), Charset.forName("UTF-8")); if (!resultReloaded.equals(referenceResult)) { - compareTextFiles(TARGET_DIR + reportFileName, REFERENCES_DIR + reportFileName); - Assertions.fail("\nRegression test fails as reference was different!\nNote: If the test fails due to a new output (e.g. programming update) copy the new result over the old reference:\n\t" + TARGET_DIR + reportFileName + "\n\t\tto" + "\n\t" + REFERENCES_DIR + reportFileName); + Boolean hasDifference = Boolean.FALSE; + hasDifference = compareTextFiles(TARGET_DIR + reportFileName, REFERENCES_DIR + reportFileName); + if(hasDifference){ + Assertions.fail("\nRegression test fails as reference was different!\nNote: If the test fails due to a new output (e.g. programming update) copy the new result over the old reference:\n\t" + TARGET_DIR + reportFileName + "\n\t\tto" + "\n\t" + REFERENCES_DIR + reportFileName); + } } } @@ -162,7 +168,8 @@ public static void main(String[] args) { * Just for showing the different lines, in case the test and reference * files as strings are unequal! */ - private static void compareTextFiles(String firstFilePath, String secondFilePath) { + private static Boolean compareTextFiles(String firstFilePath, String secondFilePath) { + Boolean hasDifference = Boolean.FALSE; try ( BufferedReader bfr1 = Files.newBufferedReader(Paths.get(firstFilePath)); BufferedReader bfr2 = Files.newBufferedReader(Paths.get(secondFilePath));) { String line1; @@ -173,10 +180,13 @@ private static void compareTextFiles(String firstFilePath, String secondFilePath if (!line1.equals(line2)) { System.err.println("### Unmatched Line1: '" + line1 + "'\n"); System.err.println("### Unmatched Line2: '" + line2 + "'\n\n"); + hasDifference = Boolean.TRUE; } } } catch (Exception e) { System.err.println(e.getMessage() + e.toString()); + hasDifference = Boolean.TRUE; } + return hasDifference; } }