aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorJim Lawson2018-02-16 17:10:30 -0800
committerGitHub2018-02-16 17:10:30 -0800
commitedcb81a34dbf8a04d0b011aa1ca07c6e19598f23 (patch)
treeaba2e3b8b921f9fdc861ed51687735f6d18d7bff /src/test
parent74a3b302df4422bec47e754cad1703b36ff75cd2 (diff)
Replacematcherror - catch exceptions and convert to internal error. (#424)
* Catch exceptions and convert to internal error. We need to update the displayed message to incorporate a line number and text to be used for the issue. * Cleanup exception handling/throwing. Re-throw expected (or uncorrectable exceptions). Provide Utils.getThrowable() to get the first (eldest) or last throwable in the chain. Update tests to conform to FreeSpec protocol. * Minor cleanup Admit we've updated some deprecated ScalaTest methods.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/firrtlTests/InternalErrorSpec.scala46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/test/scala/firrtlTests/InternalErrorSpec.scala b/src/test/scala/firrtlTests/InternalErrorSpec.scala
new file mode 100644
index 00000000..85c9c67d
--- /dev/null
+++ b/src/test/scala/firrtlTests/InternalErrorSpec.scala
@@ -0,0 +1,46 @@
+// See LICENSE for license details.
+
+package firrtlTests
+
+import java.io.File
+
+import firrtl._
+import firrtl.Utils.getThrowable
+import firrtl.util.BackendCompilationUtilities
+import org.scalatest.{FreeSpec, Matchers}
+
+
+class InternalErrorSpec extends FreeSpec with Matchers with BackendCompilationUtilities {
+ "Unexpected exceptions" - {
+ val input =
+ """
+ |circuit Dummy :
+ | module Dummy :
+ | input clock : Clock
+ | input x : UInt<1>
+ | output y : UInt<1>
+ | output io : { flip in : UInt<16>, out : UInt<16> }
+ | y <= shr(x, UInt(1)); this should generate an exception in PrimOps.scala:127.
+ | """.stripMargin
+
+ var exception: Exception = null
+ "should throw a FIRRTLException" in {
+ val manager = new ExecutionOptionsManager("test") with HasFirrtlOptions {
+ commonOptions = CommonOptions(topName = "Dummy")
+ firrtlOptions = FirrtlExecutionOptions(firrtlSource = Some(input), compilerName = "low")
+ }
+ exception = intercept[FIRRTLException] {
+ firrtl.Driver.execute(manager)
+ }
+ }
+
+ "should contain the expected string" in {
+ assert(exception.getMessage.contains("Internal Error! Please file an issue"))
+ }
+
+ "should contain the name of the file originating the exception in the stack trace" in {
+ val first = true
+ assert(getThrowable(Some(exception), first).getStackTrace exists (_.getFileName.contains("PrimOps.scala")))
+ }
+ }
+}