From cb7fcd2b18135230dc40f3c7bb98685e7ffde9d5 Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Fri, 22 Dec 2017 09:30:21 -0800 Subject: Fixes format strings in assertions. Fixes #540 (#542) --- src/test/scala/chiselTests/Assert.scala | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/scala/chiselTests/Assert.scala b/src/test/scala/chiselTests/Assert.scala index 994a16fd..075cc4e2 100644 --- a/src/test/scala/chiselTests/Assert.scala +++ b/src/test/scala/chiselTests/Assert.scala @@ -46,7 +46,18 @@ 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 FormattedAssertTester extends BasicTester { + val foobar = Wire(UInt(32.W)) + foobar := 123.U + assert(foobar === 123.U, "Error! Wire foobar =/= %x! This is 100%% wrong.\n", foobar) + stop() +} + +class BadUnescapedPercentAssertTester extends BasicTester { + assert(1.U === 1.U, "I'm 110% sure this is an invalid message") stop() } @@ -63,4 +74,12 @@ class AssertSpec extends ChiselFlatSpec { "Assertions" should "allow the modulo operator % in the message" in { assertTesterPasses{ new ModuloAssertTester } } + they should "allow printf-style format strings with arguments" in { + assertTesterPasses{ new FormattedAssertTester } + } + they should "not allow unescaped % in the message" in { + a [java.util.UnknownFormatConversionException] should be thrownBy { + elaborate { new BadUnescapedPercentAssertTester } + } + } } -- cgit v1.2.3