Skip to content

Commit

Permalink
Merge pull request #711 from viperproject/test-gobra-messages
Browse files Browse the repository at this point in the history
Fixes Pretty Printer
  • Loading branch information
ArquintL authored Dec 5, 2023
2 parents 9f38d64 + ea83cd1 commit 4dc33c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/main/scala/viper/gobra/ast/internal/PrettyPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ class DefaultPrettyPrinter extends PrettyPrinter with kiama.output.PrettyPrinter
measure match {
case WildcardMeasure(cond) => "_" <+> showCond(cond)
case TupleTerminationMeasure(tuple, cond) =>
hcat(tuple map {
case e: Expr => showExpr(e)
case n => violation(s"Unexpected node $n")
}) <+> showCond(cond)
hcat(tuple map show) <+> showCond(cond)
}
}

Expand Down
13 changes: 11 additions & 2 deletions src/test/scala/viper/gobra/GobraTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import viper.gobra.frontend.Source.FromFileSource
import viper.gobra.frontend.info.Info
import viper.gobra.frontend.{Config, PackageResolver, Parser, Source}
import viper.gobra.reporting.VerifierResult.{Failure, Success}
import viper.gobra.reporting.{NoopReporter, VerifierError}
import viper.gobra.reporting.{GobraMessage, GobraReporter, VerifierError}
import viper.silver.testing.{AbstractOutput, AnnotatedTestInput, ProjectInfo, SystemUnderTest}
import viper.silver.utility.TimingUtils
import viper.gobra.util.{DefaultGobraExecutionContext, GobraExecutionContext}
Expand Down Expand Up @@ -51,7 +51,7 @@ class GobraTests extends AbstractGobraTests with BeforeAndAfterAll {
private def getConfig(source: Source): Config =
Config(
logLevel = Level.INFO,
reporter = NoopReporter,
reporter = StringifyReporter,
packageInfoInputMap = Map(Source.getPackageInfo(source, Path.of("")) -> Vector(source)),
checkConsistency = true,
cacheParserAndTypeChecker = cacheParserAndTypeChecker,
Expand Down Expand Up @@ -120,4 +120,13 @@ class GobraTests extends AbstractGobraTests with BeforeAndAfterAll {
/** A short and unique identifier for this output. */
override def fullId: String = error.id
}

case object StringifyReporter extends GobraReporter {
override val name: String = "StringifyReporter"

override def report(msg: GobraMessage): Unit = {
// by invoking `toString`, we check that messages are printable, which includes pretty-printing AST nodes:
msg.toString
}
}
}

0 comments on commit 4dc33c6

Please sign in to comment.