From c16ca6390aa5175a3790629435b21c0c0358c952 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Wed, 12 Jul 2023 11:50:41 -0700 Subject: [PATCH] FormatAssertions: fail when parsing errors out --- .../test/scala/org/scalafmt/util/FormatAssertions.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scalafmt-tests/src/test/scala/org/scalafmt/util/FormatAssertions.scala b/scalafmt-tests/src/test/scala/org/scalafmt/util/FormatAssertions.scala index 24610425e0..72cb850878 100644 --- a/scalafmt-tests/src/test/scala/org/scalafmt/util/FormatAssertions.scala +++ b/scalafmt-tests/src/test/scala/org/scalafmt/util/FormatAssertions.scala @@ -11,6 +11,7 @@ import org.scalameta.logger import scala.meta.parsers.{Parse, ParseException} import scala.meta.testkit.StructurallyEqual import scala.meta.{Dialect, Tree} +import scala.meta.internal.inputs._ trait FormatAssertions { @@ -33,9 +34,11 @@ trait FormatAssertions { import scala.meta._ def toInput(code: String) = Scalafmt.toInput(code, filename) toInput(original).parse[T] match { - case Parsed.Error(_, message, _) => - logger.debug(original) - logger.debug(s"original does not parse $message") + case Parsed.Error(pos, message, _) => + val msgWithPos = pos.formatMessage("error", message) + val error = s"original does not parse ($msgWithPos) [$filename]" + logger.debug(error) + throw FormatterOutputDoesNotParse(error, pos.startLine) case Parsed.Success(originalParsed) => toInput(obtained).parse[T] match { case Parsed.Success(obtainedParsed) =>