aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorSchuyler Eldridge2019-04-22 21:20:08 -0400
committerSchuyler Eldridge2019-04-25 16:24:15 -0400
commitef8f06f23b9ee6cf86de2450752dfd0fcd32da80 (patch)
tree79e2e8c5753903ca6d14e9b952c26a07442bd980 /src/test
parent47fe781c4ace38dff7f31da7e78f772e131d689e (diff)
Add ShellOption, DeletedWrapper
Abstracts away option writing such that users no longer have to understand scopt semantics. This adds a ShellOption class and a HasShellOptions trait for something which provides one or more ShellOptions. This refactors the FIRRTL codebase to use this style of option specification. Adds and uses DeletedWrapper to automatically generate DeletedAnnotations. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/scala/firrtlTests/options/RegistrationSpec.scala21
-rw-r--r--src/test/scala/firrtlTests/options/phases/ChecksSpec.scala4
-rw-r--r--src/test/scala/firrtlTests/options/phases/GetIncludesSpec.scala1
3 files changed, 16 insertions, 10 deletions
diff --git a/src/test/scala/firrtlTests/options/RegistrationSpec.scala b/src/test/scala/firrtlTests/options/RegistrationSpec.scala
index c060341d..43d71b6d 100644
--- a/src/test/scala/firrtlTests/options/RegistrationSpec.scala
+++ b/src/test/scala/firrtlTests/options/RegistrationSpec.scala
@@ -6,7 +6,7 @@ import org.scalatest.{FlatSpec, Matchers}
import scopt.OptionParser
import java.util.ServiceLoader
-import firrtl.options.{RegisteredTransform, RegisteredLibrary}
+import firrtl.options.{RegisteredTransform, RegisteredLibrary, ShellOption}
import firrtl.passes.Pass
import firrtl.ir.Circuit
import firrtl.annotations.NoTargetAnnotation
@@ -16,16 +16,23 @@ case object HelloAnnotation extends NoTargetAnnotation
class FooTransform extends Pass with RegisteredTransform {
def run(c: Circuit): Circuit = c
- def addOptions(p: OptionParser[AnnotationSeq]): Unit =
- p.opt[Unit]("hello")
- .action( (_, c) => HelloAnnotation +: c )
+
+ val options = Seq(
+ new ShellOption[Unit](
+ longOption = "hello",
+ toAnnotationSeq = _ => Seq(HelloAnnotation),
+ helpText = "Hello option") )
+
}
class BarLibrary extends RegisteredLibrary {
def name: String = "Bar"
- def addOptions(p: OptionParser[AnnotationSeq]): Unit =
- p.opt[Unit]("world")
- .action( (_, c) => HelloAnnotation +: c )
+
+ val options = Seq(
+ new ShellOption[Unit](
+ longOption = "world",
+ toAnnotationSeq = _ => Seq(HelloAnnotation),
+ helpText = "World option") )
}
class RegistrationSpec extends FlatSpec with Matchers {
diff --git a/src/test/scala/firrtlTests/options/phases/ChecksSpec.scala b/src/test/scala/firrtlTests/options/phases/ChecksSpec.scala
index e04ba554..b988f838 100644
--- a/src/test/scala/firrtlTests/options/phases/ChecksSpec.scala
+++ b/src/test/scala/firrtlTests/options/phases/ChecksSpec.scala
@@ -13,14 +13,14 @@ class ChecksSpec extends FlatSpec with Matchers {
val targetDir = TargetDirAnnotation("foo")
val annoOut = OutputAnnotationFileAnnotation("bar")
+ class Fixture { val phase: Phase = new Checks }
+
/* 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 {
diff --git a/src/test/scala/firrtlTests/options/phases/GetIncludesSpec.scala b/src/test/scala/firrtlTests/options/phases/GetIncludesSpec.scala
index 5b07d0e0..1007ca8c 100644
--- a/src/test/scala/firrtlTests/options/phases/GetIncludesSpec.scala
+++ b/src/test/scala/firrtlTests/options/phases/GetIncludesSpec.scala
@@ -21,7 +21,6 @@ case object E extends NoTargetAnnotation
class GetIncludesSpec extends FlatSpec with Matchers with BackendCompilationUtilities with firrtlTests.Utils {
-
val dir = new File("test_run_dir/GetIncludesSpec")
dir.mkdirs()