Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormatAssertions: fail when parsing errors out #3585

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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