Skip to content

Commit

Permalink
Merge pull request #1356 from lf-lang/fix-1354
Browse files Browse the repository at this point in the history
Reduction of output in formatter tests
  • Loading branch information
petervdonovan authored Sep 6, 2022
2 parents de152ef + 707fa29 commit f5f7095
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
38 changes: 21 additions & 17 deletions org.lflang.tests/src/org/lflang/tests/compiler/RoundTripTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,30 @@ public void roundTripTest() throws Exception {

private void run(Path file) throws Exception {
Model originalModel = parse(file);
System.out.printf("Running formatter on %s...%n", file);
Assertions.assertTrue(originalModel.eResource().getErrors().isEmpty());
// TODO: Check that the output is a fixed point
final int smallLineLength = 20;
String squishedTestCase = FormattingUtils.render(originalModel, smallLineLength);
System.out.printf(
"The following is what %s looks like after applying formatting with the preferred line "
+ "length set to %d columns:%n%s%n%n",
file.getFileName(),
smallLineLength,
squishedTestCase
);
Model resultingModel = getResultingModel(file, squishedTestCase);
final String squishedTestCase = FormattingUtils.render(originalModel, smallLineLength);
final Model resultingModel = getResultingModel(file, squishedTestCase);
Assertions.assertNotNull(resultingModel);
if (!resultingModel.eResource().getErrors().isEmpty()) {
resultingModel.eResource().getErrors().forEach(System.err::println);
Assertions.assertTrue(resultingModel.eResource().getErrors().isEmpty());
}
Assertions.assertTrue(new IsEqual(originalModel).doSwitch(resultingModel));
String normalTestCase = FormattingUtils.render(originalModel);
System.out.printf(
"The following is what %s looks like after applying formatting normally:%n%s%n%n",
file.getFileName(),
normalTestCase
);
if (!new IsEqual(originalModel).doSwitch(resultingModel)) {
System.out.printf(
"The following is what %s looks like after applying formatting with the preferred line "
+ "length set to %d columns:%n%s%n%n",
file.getFileName(),
smallLineLength,
squishedTestCase
);
throw new junit.framework.AssertionFailedError(String.format(
"The reformatted version of %s was not equivalent to the original file.",
file.getFileName()
));
}
final String normalTestCase = FormattingUtils.render(originalModel);
try {
Assertions.assertEquals(
Files.readString(file).replaceAll("\\r\\n?", "\n"),
Expand All @@ -84,6 +83,11 @@ private void run(Path file) throws Exception {
file.getFileName(),
file.getFileName()
);
System.out.printf(
"The following is what %s looks like after applying formatting normally:%n%s%n%n",
file.getFileName(),
normalTestCase
);
throw e;
}
}
Expand Down
7 changes: 6 additions & 1 deletion org.lflang.tests/src/org/lflang/tests/lsp/LspTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ private void targetLanguageValidationTest(Target target, ErrorInserter.Builder b
System.out.println(" Success.");
} else {
System.out.println(" but the expected error could not be found.");
System.out.println("The following test failed:\n" + TestBase.THIN_LINE);
System.out.printf(
"%s failed. Content of altered version of %s:%n%s%n",
alteredTest.getPath().getFileName(),
alteredTest.getPath().getFileName(),
TestBase.THIN_LINE
);
System.out.println(alteredTest + "\n" + TestBase.THIN_LINE);
}
return result;
Expand Down

0 comments on commit f5f7095

Please sign in to comment.