diff options
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/Assert.scala | 7 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/Assert.scala | 9 |
2 files changed, 13 insertions, 3 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Assert.scala b/chiselFrontend/src/main/scala/chisel3/core/Assert.scala index 5673e298..e3fef5f9 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Assert.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Assert.scala @@ -52,10 +52,11 @@ object assert { // scalastyle:ignore object.name def apply_impl_do(cond: Bool, line: String, message: Option[String], data: Bits*)(implicit sourceInfo: SourceInfo) { when (!(cond || Builder.forcedReset)) { - message match { - case Some(str) => printf.printfWithoutReset(s"Assertion failed: $str\n at $line\n", data:_*) - case None => printf.printfWithoutReset(s"Assertion failed\n at $line\n", data:_*) + val fmt = message match { + case Some(str) => s"Assertion failed: $str\n at $line\n" + case None => s"Assertion failed\n at $line\n" } + printf.printfWithoutReset(fmt.replaceAll("%", "%%"), data:_*) pushCommand(Stop(sourceInfo, Node(Builder.forcedClock), 1)) } } diff --git a/src/test/scala/chiselTests/Assert.scala b/src/test/scala/chiselTests/Assert.scala index 475e18f7..076786cd 100644 --- a/src/test/scala/chiselTests/Assert.scala +++ b/src/test/scala/chiselTests/Assert.scala @@ -44,6 +44,12 @@ class PipelinedResetTester extends BasicTester { } } +class ModuloAssertTester extends BasicTester { + assert((4.U % 2.U) === 0.U) + assert(1.U === 1.U, "I'm 110% sure this will succeed") + stop() +} + class AssertSpec extends ChiselFlatSpec { "A failing assertion" should "fail the testbench" in { assert(!runTester{ new FailingAssertTester }) @@ -54,4 +60,7 @@ class AssertSpec extends ChiselFlatSpec { "An assertion" should "not assert until we come out of reset" in { assertTesterPasses{ new PipelinedResetTester } } + "Assertions" should "allow the modulo operator % in the message" in { + assertTesterPasses{ new ModuloAssertTester } + } } |
