aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/firrtlTests/options/phases/ChecksSpec.scala
diff options
context:
space:
mode:
authorSchuyler Eldridge2018-12-04 01:35:48 -0500
committerSchuyler Eldridge2019-04-25 16:24:15 -0400
commit254e7909f6c9d155f514664584f142566f0a6799 (patch)
treefb2cdc32f8a37f8fc74cbf92ef79ee33240cc96c /src/test/scala/firrtlTests/options/phases/ChecksSpec.scala
parentb2dd0eb845081609d0aec4a873587ab3f22fe3f7 (diff)
Add tests for Annotations/Options refactor
- Add tests for DriverCompatibility.AddImplicitEmitter - Add tests for DriverCompatibility.AddImplicitOutputFile - Use a different top name in DriverSpec emit circuit tests for better coverage - Add tests for DriverCompatibility.WriteEmitted - Add catchWrites firrtlTests utility to intercept file writes - Add tests for WriteOutputAnnotations - Add tests for --custom-transforms reversing Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Diffstat (limited to 'src/test/scala/firrtlTests/options/phases/ChecksSpec.scala')
-rw-r--r--src/test/scala/firrtlTests/options/phases/ChecksSpec.scala48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/test/scala/firrtlTests/options/phases/ChecksSpec.scala b/src/test/scala/firrtlTests/options/phases/ChecksSpec.scala
new file mode 100644
index 00000000..e04ba554
--- /dev/null
+++ b/src/test/scala/firrtlTests/options/phases/ChecksSpec.scala
@@ -0,0 +1,48 @@
+// See LICENSE for license details.
+
+package firrtlTests.options.phases
+
+import org.scalatest.{FlatSpec, Matchers}
+
+import firrtl.AnnotationSeq
+import firrtl.options.{OptionsException, OutputAnnotationFileAnnotation, Phase, TargetDirAnnotation}
+import firrtl.options.phases.Checks
+
+class ChecksSpec extends FlatSpec with Matchers {
+
+ val targetDir = TargetDirAnnotation("foo")
+ val annoOut = OutputAnnotationFileAnnotation("bar")
+
+ /* A minimum annotation Seq that will pass [[Checks]] */
+ val min = Seq(targetDir)
+
+ def checkExceptionMessage(phase: Phase, annotations: AnnotationSeq, messageStart: String): Unit =
+ intercept[OptionsException]{ phase.transform(annotations) }.getMessage should startWith(messageStart)
+
+ class Fixture { val phase: Phase = new Checks }
+
+ behavior of classOf[Checks].toString
+
+ it should "enforce exactly one TargetDirAnnotation" in new Fixture {
+ info("0 target directories throws an exception")
+ checkExceptionMessage(phase, Seq.empty, "Exactly one target directory must be specified")
+
+ info("2 target directories throws an exception")
+ checkExceptionMessage(phase, Seq(targetDir, targetDir), "Exactly one target directory must be specified")
+ }
+
+ it should "enforce zero or one output annotation files" in new Fixture {
+ info("0 output annotation files is okay")
+ phase.transform(Seq(targetDir))
+
+ info("2 output annotation files throws an exception")
+ val in = Seq(targetDir, annoOut, annoOut)
+ checkExceptionMessage(phase, in, "At most one output annotation file can be specified")
+ }
+
+ it should "pass if the minimum annotations are specified" in new Fixture {
+ info(s"""Minimum required: ${min.map(_.getClass.getSimpleName).mkString(", ")}""")
+ phase.transform(min)
+ }
+
+}