From fe1b820b23c5314b6acb9508667a2ba34e4f2c45 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Sun, 7 Jan 2024 19:11:53 -0800 Subject: [PATCH] FormatTests: check AST only if result is parsable --- .../test/scala/org/scalafmt/FormatTests.scala | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/FormatTests.scala b/scalafmt-tests/src/test/scala/org/scalafmt/FormatTests.scala index 772e2dce9b..5a7170940e 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/FormatTests.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/FormatTests.scala @@ -58,19 +58,6 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions { case Formatted.Success(code) => code } debugResults += saveResult(t, obtained, debug) - if ( - t.style.rewrite.rules.isEmpty && - FormatTokensRewrite.getEnabledFactories(t.style).isEmpty && - !t.style.assumeStandardLibraryStripMargin && - !FileOps.isMarkdown(t.filename) && - t.style.onTestFailure.isEmpty - ) - assertFormatPreservesAst( - t.filename, - t.original, - obtained, - result.config.runner - ) val debug2 = new Debug(onlyOne) val result2 = Scalafmt.formatCode( obtained, @@ -95,6 +82,20 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions { t.expected ) } + if ( + result2Either.isRight && + t.style.rewrite.rules.isEmpty && + FormatTokensRewrite.getEnabledFactories(t.style).isEmpty && + !t.style.assumeStandardLibraryStripMargin && + !FileOps.isMarkdown(t.filename) && + t.style.onTestFailure.isEmpty + ) + assertFormatPreservesAst( + t.filename, + t.original, + obtained, + result.config.runner + ) } def testShouldRun(t: DiffTest): Boolean = !onlyOne || t.only