Skip to content

Commit

Permalink
FormatAssertions: fail when parsing errors out
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jul 12, 2023
1 parent 114c883 commit 0f23519
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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) =>
Expand Down

0 comments on commit 0f23519

Please sign in to comment.