Skip to content

Commit

Permalink
FormatTests: check AST only if result is parsable
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jan 8, 2024
1 parent eee73a0 commit fe1b820
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions scalafmt-tests/src/test/scala/org/scalafmt/FormatTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit fe1b820

Please sign in to comment.