diff options
| author | Jack Koenig | 2017-02-09 00:33:17 -0800 |
|---|---|---|
| committer | Andrew Waterman | 2017-02-24 04:50:55 -0800 |
| commit | 55c2bd293473d92f8df1ef83bb627992b173ce8e (patch) | |
| tree | a2f4d12e6f446c3b791c8b9ccd1ce80f855b9956 | |
| parent | a7aafe90c87e0d7931fa15c6214a97f4496a08cb (diff) | |
Escape % in assertion messages
| -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 } + } } |
