diff options
| author | chick | 2020-08-14 19:47:53 -0700 |
|---|---|---|
| committer | Jack Koenig | 2020-08-14 19:47:53 -0700 |
| commit | 6fc742bfaf5ee508a34189400a1a7dbffe3f1cac (patch) | |
| tree | 2ed103ee80b0fba613c88a66af854ae9952610ce /src/test/scala/firrtlTests/options | |
| parent | b516293f703c4de86397862fee1897aded2ae140 (diff) | |
All of src/ formatted with scalafmt
Diffstat (limited to 'src/test/scala/firrtlTests/options')
9 files changed, 214 insertions, 198 deletions
diff --git a/src/test/scala/firrtlTests/options/OptionParserSpec.scala b/src/test/scala/firrtlTests/options/OptionParserSpec.scala index e93c9b2c..452e6cb7 100644 --- a/src/test/scala/firrtlTests/options/OptionParserSpec.scala +++ b/src/test/scala/firrtlTests/options/OptionParserSpec.scala @@ -19,66 +19,69 @@ class OptionParserSpec extends AnyFlatSpec with Matchers with firrtl.testutils.U /* An option parser that prepends to a Seq[Int] */ class IntParser extends OptionParser[AnnotationSeq]("Int Parser") { - opt[Int]("integer").abbr("n").unbounded.action( (x, c) => IntAnnotation(x) +: c ) + opt[Int]("integer").abbr("n").unbounded.action((x, c) => IntAnnotation(x) +: c) help("help") } trait DuplicateShortOption { this: OptionParser[AnnotationSeq] => - opt[Int]("not-an-integer").abbr("n").unbounded.action( (x, c) => IntAnnotation(x) +: c ) + opt[Int]("not-an-integer").abbr("n").unbounded.action((x, c) => IntAnnotation(x) +: c) } trait DuplicateLongOption { this: OptionParser[AnnotationSeq] => - opt[Int]("integer").abbr("m").unbounded.action( (x, c) => IntAnnotation(x) +: c ) + opt[Int]("integer").abbr("m").unbounded.action((x, c) => IntAnnotation(x) +: c) } trait WithIntParser { val parser = new IntParser } - behavior of "A default OptionsParser" + behavior.of("A default OptionsParser") it should "call sys.exit if terminate is called" in new WithIntParser { info("exit status of 1 for failure") - catchStatus { parser.terminate(Left("some message")) } should be (Left(1)) + catchStatus { parser.terminate(Left("some message")) } should be(Left(1)) info("exit status of 0 for success") - catchStatus { parser.terminate(Right(())) } should be (Left(0)) + catchStatus { parser.terminate(Right(())) } should be(Left(0)) } it should "print to stderr on an invalid option" in new WithIntParser { - grabStdOutErr{ parser.parse(Array("--foo"), Seq[Annotation]()) }._2 should include ("Unknown option --foo") + grabStdOutErr { parser.parse(Array("--foo"), Seq[Annotation]()) }._2 should include("Unknown option --foo") } - behavior of "An OptionParser with DoNotTerminateOnExit mixed in" + behavior.of("An OptionParser with DoNotTerminateOnExit mixed in") it should "disable sys.exit for terminate method" in { val parser = new IntParser with DoNotTerminateOnExit info("no exit for failure") - catchStatus { parser.terminate(Left("some message")) } should be (Right(())) + catchStatus { parser.terminate(Left("some message")) } should be(Right(())) info("no exit for success") - catchStatus { parser.terminate(Right(())) } should be (Right(())) + catchStatus { parser.terminate(Right(())) } should be(Right(())) } - behavior of "An OptionParser with DuplicateHandling mixed in" + behavior.of("An OptionParser with DuplicateHandling mixed in") it should "detect short duplicates" in { val parser = new IntParser with DuplicateHandling with DuplicateShortOption - intercept[OptionsException] { parser.parse(Array[String](), Seq[Annotation]()) } - .getMessage should startWith ("Duplicate short option") + intercept[OptionsException] { parser.parse(Array[String](), Seq[Annotation]()) }.getMessage should startWith( + "Duplicate short option" + ) } it should "detect long duplicates" in { val parser = new IntParser with DuplicateHandling with DuplicateLongOption - intercept[OptionsException] { parser.parse(Array[String](), Seq[Annotation]()) } - .getMessage should startWith ("Duplicate long option") + intercept[OptionsException] { parser.parse(Array[String](), Seq[Annotation]()) }.getMessage should startWith( + "Duplicate long option" + ) } - behavior of "An OptionParser with ExceptOnError mixed in" + behavior.of("An OptionParser with ExceptOnError mixed in") it should "cause an OptionsException on an invalid option" in { val parser = new IntParser with ExceptOnError - intercept[OptionsException] { parser.parse(Array("--foo"), Seq[Annotation]()) } - .getMessage should include ("Unknown option") + intercept[OptionsException] { parser.parse(Array("--foo"), Seq[Annotation]()) }.getMessage should include( + "Unknown option" + ) } } diff --git a/src/test/scala/firrtlTests/options/OptionsViewSpec.scala b/src/test/scala/firrtlTests/options/OptionsViewSpec.scala index 0c868cb2..504dcdf6 100644 --- a/src/test/scala/firrtlTests/options/OptionsViewSpec.scala +++ b/src/test/scala/firrtlTests/options/OptionsViewSpec.scala @@ -2,10 +2,9 @@ package firrtlTests.options - import firrtl.options.OptionsView import firrtl.AnnotationSeq -import firrtl.annotations.{Annotation,NoTargetAnnotation} +import firrtl.annotations.{Annotation, NoTargetAnnotation} import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers @@ -22,7 +21,7 @@ class OptionsViewSpec extends AnyFlatSpec with Matchers { /* An OptionsView that converts an AnnotationSeq to Option[Foo] */ implicit object FooView extends OptionsView[Foo] { private def append(foo: Foo, anno: Annotation): Foo = anno match { - case NameAnnotation(n) => foo.copy(name = Some(n)) + case NameAnnotation(n) => foo.copy(name = Some(n)) case ValueAnnotation(v) => foo.copy(value = Some(v)) case _ => foo } @@ -40,20 +39,20 @@ class OptionsViewSpec extends AnyFlatSpec with Matchers { def view(options: AnnotationSeq): Bar = options.foldLeft(Bar())(append) } - behavior of "OptionsView" + behavior.of("OptionsView") it should "convert annotations to one of two types" in { /* Some default annotations */ val annos = Seq(NameAnnotation("foo"), ValueAnnotation(42)) info("Foo conversion okay") - FooView.view(annos) should be (Foo(Some("foo"), Some(42))) + FooView.view(annos) should be(Foo(Some("foo"), Some(42))) info("Bar conversion okay") - BarView.view(annos) should be (Bar("foo")) + BarView.view(annos) should be(Bar("foo")) } - behavior of "Viewer" + behavior.of("Viewer") it should "implicitly view annotations as the specified type" in { import firrtl.options.Viewer._ @@ -62,9 +61,9 @@ class OptionsViewSpec extends AnyFlatSpec with Matchers { val annos = Seq[Annotation]() info("Foo view okay") - view[Foo](annos) should be (Foo(None, None)) + view[Foo](annos) should be(Foo(None, None)) info("Bar view okay") - view[Bar](annos) should be (Bar()) + view[Bar](annos) should be(Bar()) } } diff --git a/src/test/scala/firrtlTests/options/PhaseManagerSpec.scala b/src/test/scala/firrtlTests/options/PhaseManagerSpec.scala index 108f3730..f31b96fd 100644 --- a/src/test/scala/firrtlTests/options/PhaseManagerSpec.scala +++ b/src/test/scala/firrtlTests/options/PhaseManagerSpec.scala @@ -2,9 +2,8 @@ package firrtlTests.options - import firrtl.AnnotationSeq -import firrtl.options.{DependencyManagerException, Phase, PhaseManager, Dependency} +import firrtl.options.{Dependency, DependencyManagerException, Phase, PhaseManager} import java.io.{File, PrintWriter} @@ -62,7 +61,6 @@ class F extends IdentityPhase { } } - /** [[Phase]] that requires [[C]] and invalidates [[F]] */ class G extends IdentityPhase { override def prerequisites = Seq(Dependency[C]) @@ -235,7 +233,7 @@ object UnrelatedFixture { trait InvalidatesB8Dep { this: Phase => override def invalidates(a: Phase) = a match { case _: B8Dep => true - case _ => false + case _ => false } } @@ -368,7 +366,7 @@ object OrderingFixture { class B extends IdentityPhase { override def invalidates(phase: Phase): Boolean = phase match { case _: A => true - case _ => false + case _ => false } } @@ -376,7 +374,7 @@ object OrderingFixture { override def prerequisites = Seq(Dependency[A], Dependency[B]) override def invalidates(phase: Phase): Boolean = phase match { case _: B => true - case _ => false + case _ => false } } @@ -423,7 +421,7 @@ class PhaseManagerSpec extends AnyFlatSpec with Matchers { } - behavior of this.getClass.getName + behavior.of(this.getClass.getName) it should "do nothing if all targets are reached" in { val targets = Seq(Dependency[A], Dependency[B], Dependency[C], Dependency[D]) @@ -431,7 +429,7 @@ class PhaseManagerSpec extends AnyFlatSpec with Matchers { writeGraphviz(pm, "test_run_dir/PhaseManagerSpec/DoNothing") - pm.flattenedTransformOrder should be (empty) + pm.flattenedTransformOrder should be(empty) } it should "handle a simple dependency" in { @@ -441,7 +439,7 @@ class PhaseManagerSpec extends AnyFlatSpec with Matchers { writeGraphviz(pm, "test_run_dir/PhaseManagerSpec/SimpleDependency") - pm.flattenedTransformOrder.map(_.getClass) should be (order) + pm.flattenedTransformOrder.map(_.getClass) should be(order) } it should "handle a simple dependency with an invalidation" in { @@ -451,7 +449,7 @@ class PhaseManagerSpec extends AnyFlatSpec with Matchers { writeGraphviz(pm, "test_run_dir/PhaseManagerSpec/OneInvalidate") - pm.flattenedTransformOrder.map(_.getClass) should be (order) + pm.flattenedTransformOrder.map(_.getClass) should be(order) } it should "handle a dependency with two invalidates optimally" in { @@ -460,7 +458,7 @@ class PhaseManagerSpec extends AnyFlatSpec with Matchers { writeGraphviz(pm, "test_run_dir/PhaseManagerSpec/TwoInvalidates") - pm.flattenedTransformOrder.size should be (targets.size) + pm.flattenedTransformOrder.size should be(targets.size) } it should "throw an exception for cyclic prerequisites" in { @@ -469,8 +467,9 @@ class PhaseManagerSpec extends AnyFlatSpec with Matchers { writeGraphviz(pm, "test_run_dir/PhaseManagerSpec/CyclicPrerequisites") - intercept[DependencyManagerException]{ pm.flattenedTransformOrder } - .getMessage should startWith ("No transform ordering possible") + intercept[DependencyManagerException] { pm.flattenedTransformOrder }.getMessage should startWith( + "No transform ordering possible" + ) } it should "throw an exception for cyclic invalidates" in { @@ -479,8 +478,9 @@ class PhaseManagerSpec extends AnyFlatSpec with Matchers { writeGraphviz(pm, "test_run_dir/PhaseManagerSpec/CyclicInvalidates") - intercept[DependencyManagerException]{ pm.flattenedTransformOrder } - .getMessage should startWith ("No transform ordering possible") + intercept[DependencyManagerException] { pm.flattenedTransformOrder }.getMessage should startWith( + "No transform ordering possible" + ) } it should "handle a complicated graph" in { @@ -491,41 +491,31 @@ class PhaseManagerSpec extends AnyFlatSpec with Matchers { writeGraphviz(pm, "test_run_dir/PhaseManagerSpec/Complicated") info("only one phase was recomputed") - pm.flattenedTransformOrder.size should be (targets.size + 1) + pm.flattenedTransformOrder.size should be(targets.size + 1) } it should "handle repeated recomputed analyses" in { val f = RepeatedAnalysisFixture val targets = Seq(Dependency[f.A], Dependency[f.B], Dependency[f.C]) val order = - Seq( classOf[f.Analysis], - classOf[f.A], - classOf[f.Analysis], - classOf[f.B], - classOf[f.Analysis], - classOf[f.C]) + Seq(classOf[f.Analysis], classOf[f.A], classOf[f.Analysis], classOf[f.B], classOf[f.Analysis], classOf[f.C]) val pm = new PhaseManager(targets) writeGraphviz(pm, "test_run_dir/PhaseManagerSpec/RepeatedAnalysis") - pm.flattenedTransformOrder.map(_.getClass) should be (order) + pm.flattenedTransformOrder.map(_.getClass) should be(order) } it should "handle inverted repeated recomputed analyses" in { val f = InvertedAnalysisFixture val targets = Seq(Dependency[f.A], Dependency[f.B], Dependency[f.C]) val order = - Seq( classOf[f.Analysis], - classOf[f.C], - classOf[f.Analysis], - classOf[f.B], - classOf[f.Analysis], - classOf[f.A]) + Seq(classOf[f.Analysis], classOf[f.C], classOf[f.Analysis], classOf[f.B], classOf[f.Analysis], classOf[f.A]) val pm = new PhaseManager(targets) writeGraphviz(pm, "test_run_dir/PhaseManagerSpec/InvertedRepeatedAnalysis") - pm.flattenedTransformOrder.map(_.getClass) should be (order) + pm.flattenedTransformOrder.map(_.getClass) should be(order) } /** This test shows how the optionalPrerequisiteOf member can be used to run one transform before another. */ @@ -535,7 +525,7 @@ class PhaseManagerSpec extends AnyFlatSpec with Matchers { info("without the custom transform it runs: First -> Second") val pm = new PhaseManager(Seq(Dependency[f.Second])) val orderNoCustom = Seq(classOf[f.First], classOf[f.Second]) - pm.flattenedTransformOrder.map(_.getClass) should be (orderNoCustom) + pm.flattenedTransformOrder.map(_.getClass) should be(orderNoCustom) info("with the custom transform it runs: First -> Custom -> Second") val pmCustom = new PhaseManager(Seq(Dependency[f.Custom], Dependency[f.Second])) @@ -543,7 +533,7 @@ class PhaseManagerSpec extends AnyFlatSpec with Matchers { writeGraphviz(pmCustom, "test_run_dir/PhaseManagerSpec/SingleDependent") - pmCustom.flattenedTransformOrder.map(_.getClass) should be (orderCustom) + pmCustom.flattenedTransformOrder.map(_.getClass) should be(orderCustom) } it should "handle chained invalidation" in { @@ -553,11 +543,11 @@ class PhaseManagerSpec extends AnyFlatSpec with Matchers { val current = Seq(Dependency[f.B], Dependency[f.C], Dependency[f.D]) val pm = new PhaseManager(targets, current) - val order = Seq( classOf[f.A], classOf[f.B], classOf[f.C], classOf[f.D], classOf[f.E] ) + val order = Seq(classOf[f.A], classOf[f.B], classOf[f.C], classOf[f.D], classOf[f.E]) writeGraphviz(pm, "test_run_dir/PhaseManagerSpec/ChainedInvalidate") - pm.flattenedTransformOrder.map(_.getClass) should be (order) + pm.flattenedTransformOrder.map(_.getClass) should be(order) } it should "maintain the order of input targets" in { @@ -565,62 +555,70 @@ class PhaseManagerSpec extends AnyFlatSpec with Matchers { /** A bunch of unrelated Phases. This ensures that these run in the order in which they are specified. */ val targets = - Seq( Dependency[f.B0], - Dependency[f.B1], - Dependency[f.B2], - Dependency[f.B3], - Dependency[f.B4], - Dependency[f.B5], - Dependency[f.B6], - Dependency[f.B7], - Dependency[f.B8], - Dependency[f.B9], - Dependency[f.B10], - Dependency[f.B11], - Dependency[f.B12], - Dependency[f.B13], - Dependency[f.B14], - Dependency[f.B15] ) + Seq( + Dependency[f.B0], + Dependency[f.B1], + Dependency[f.B2], + Dependency[f.B3], + Dependency[f.B4], + Dependency[f.B5], + Dependency[f.B6], + Dependency[f.B7], + Dependency[f.B8], + Dependency[f.B9], + Dependency[f.B10], + Dependency[f.B11], + Dependency[f.B12], + Dependency[f.B13], + Dependency[f.B14], + Dependency[f.B15] + ) + /** A sequence of custom transforms that should all run after B6 and before B7. This exercises correct ordering of the * prerequisiteGraph and optionalPrerequisiteOfGraph. */ val prerequisiteTargets = - Seq( Dependency[f.B6_0], - Dependency[f.B6_1], - Dependency[f.B6_2], - Dependency[f.B6_3], - Dependency[f.B6_4], - Dependency[f.B6_5], - Dependency[f.B6_6], - Dependency[f.B6_7], - Dependency[f.B6_8], - Dependency[f.B6_9], - Dependency[f.B6_10], - Dependency[f.B6_11], - Dependency[f.B6_12], - Dependency[f.B6_13], - Dependency[f.B6_14], - Dependency[f.B6_15] ) + Seq( + Dependency[f.B6_0], + Dependency[f.B6_1], + Dependency[f.B6_2], + Dependency[f.B6_3], + Dependency[f.B6_4], + Dependency[f.B6_5], + Dependency[f.B6_6], + Dependency[f.B6_7], + Dependency[f.B6_8], + Dependency[f.B6_9], + Dependency[f.B6_10], + Dependency[f.B6_11], + Dependency[f.B6_12], + Dependency[f.B6_13], + Dependency[f.B6_14], + Dependency[f.B6_15] + ) + /** A sequence of transforms that are invalidated by B0 and only define optionalPrerequisiteOf on B8. This exercises * the ordering defined by "otherPrerequisites". */ val current = - Seq( Dependency[f.B8_0], - Dependency[f.B8_1], - Dependency[f.B8_2], - Dependency[f.B8_3], - Dependency[f.B8_4], - Dependency[f.B8_5], - Dependency[f.B8_6], - Dependency[f.B8_7], - Dependency[f.B8_8], - Dependency[f.B8_9], - Dependency[f.B8_10], - Dependency[f.B8_11], - Dependency[f.B8_12], - Dependency[f.B8_13], - Dependency[f.B8_14], - Dependency[f.B8_15] ) + Seq( + Dependency[f.B8_0], + Dependency[f.B8_1], + Dependency[f.B8_2], + Dependency[f.B8_3], + Dependency[f.B8_4], + Dependency[f.B8_5], + Dependency[f.B8_6], + Dependency[f.B8_7], + Dependency[f.B8_8], + Dependency[f.B8_9], + Dependency[f.B8_10], + Dependency[f.B8_11], + Dependency[f.B8_12], + Dependency[f.B8_13], + Dependency[f.B8_14], + Dependency[f.B8_15] + ) /** The resulting order: B0--B6, B6_0--B6_B15, B7, B8_0--B8_15, B8--B15 */ val expectedDeps = targets.slice(0, 7) ++ prerequisiteTargets ++ Some(targets(7)) ++ current ++ targets.drop(8) @@ -630,7 +628,7 @@ class PhaseManagerSpec extends AnyFlatSpec with Matchers { writeGraphviz(pm, "test_run_dir/PhaseManagerSpec/DeterministicOrder") - pm.flattenedTransformOrder.map(_.getClass) should be (expectedClasses) + pm.flattenedTransformOrder.map(_.getClass) should be(expectedClasses) } it should "allow conditional placement of custom transforms" in { @@ -642,13 +640,21 @@ class PhaseManagerSpec extends AnyFlatSpec with Matchers { val targetsFull = Seq(Dependency[f.Custom], Dependency[f.DoneFull]) val pmFull = new PhaseManager(targetsFull) - val expectedMinimum = Seq(classOf[f.Root], classOf[f.OptMinimum], classOf[f.AfterOpt], classOf[f.Custom], classOf[f.DoneMinimum]) + val expectedMinimum = + Seq(classOf[f.Root], classOf[f.OptMinimum], classOf[f.AfterOpt], classOf[f.Custom], classOf[f.DoneMinimum]) writeGraphviz(pmMinimum, "test_run_dir/PhaseManagerSpec/CustomAfterOptimization/minimum") - pmMinimum.flattenedTransformOrder.map(_.getClass) should be (expectedMinimum) - - val expectedFull = Seq(classOf[f.Root], classOf[f.OptMinimum], classOf[f.OptFull], classOf[f.AfterOpt], classOf[f.Custom], classOf[f.DoneFull]) + pmMinimum.flattenedTransformOrder.map(_.getClass) should be(expectedMinimum) + + val expectedFull = Seq( + classOf[f.Root], + classOf[f.OptMinimum], + classOf[f.OptFull], + classOf[f.AfterOpt], + classOf[f.Custom], + classOf[f.DoneFull] + ) writeGraphviz(pmFull, "test_run_dir/PhaseManagerSpec/CustomAfterOptimization/full") - pmFull.flattenedTransformOrder.map(_.getClass) should be (expectedFull) + pmFull.flattenedTransformOrder.map(_.getClass) should be(expectedFull) } it should "support optional prerequisites" in { @@ -662,11 +668,12 @@ class PhaseManagerSpec extends AnyFlatSpec with Matchers { val expectedMinimum = Seq(classOf[f.Root], classOf[f.OptMinimum], classOf[f.Custom], classOf[f.DoneMinimum]) writeGraphviz(pmMinimum, "test_run_dir/PhaseManagerSpec/CustomAfterOptimization/minimum") - pmMinimum.flattenedTransformOrder.map(_.getClass) should be (expectedMinimum) + pmMinimum.flattenedTransformOrder.map(_.getClass) should be(expectedMinimum) - val expectedFull = Seq(classOf[f.Root], classOf[f.OptMinimum], classOf[f.OptFull], classOf[f.Custom], classOf[f.DoneFull]) + val expectedFull = + Seq(classOf[f.Root], classOf[f.OptMinimum], classOf[f.OptFull], classOf[f.Custom], classOf[f.DoneFull]) writeGraphviz(pmFull, "test_run_dir/PhaseManagerSpec/CustomAfterOptimization/full") - pmFull.flattenedTransformOrder.map(_.getClass) should be (expectedFull) + pmFull.flattenedTransformOrder.map(_.getClass) should be(expectedFull) } /** This tests a situation the ordering of edges matters. Namely, this test is dependent on the ordering in which @@ -678,13 +685,13 @@ class PhaseManagerSpec extends AnyFlatSpec with Matchers { { val targets = Seq(Dependency[f.A], Dependency[f.B], Dependency[f.C]) val order = Seq(classOf[f.B], classOf[f.A], classOf[f.C], classOf[f.B], classOf[f.A]) - (new PhaseManager(targets)).flattenedTransformOrder.map(_.getClass) should be (order) + (new PhaseManager(targets)).flattenedTransformOrder.map(_.getClass) should be(order) } { val targets = Seq(Dependency[f.A], Dependency[f.B], Dependency[f.Cx]) val order = Seq(classOf[f.B], classOf[f.A], classOf[f.Cx], classOf[f.B], classOf[f.A]) - (new PhaseManager(targets)).flattenedTransformOrder.map(_.getClass) should be (order) + (new PhaseManager(targets)).flattenedTransformOrder.map(_.getClass) should be(order) } } diff --git a/src/test/scala/firrtlTests/options/RegistrationSpec.scala b/src/test/scala/firrtlTests/options/RegistrationSpec.scala index fa6b0fa0..821ac8b3 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.AnyFlatSpec import org.scalatest.matchers.should.Matchers import java.util.ServiceLoader -import firrtl.options.{RegisteredTransform, RegisteredLibrary, ShellOption} +import firrtl.options.{RegisteredLibrary, RegisteredTransform, ShellOption} import firrtl.passes.Pass import firrtl.ir.Circuit import firrtl.annotations.NoTargetAnnotation @@ -19,10 +19,8 @@ class FooTransform extends Pass with RegisteredTransform { def run(c: Circuit): Circuit = c val options = Seq( - new ShellOption[Unit]( - longOption = "hello", - toAnnotationSeq = _ => Seq(HelloAnnotation), - helpText = "Hello option") ) + new ShellOption[Unit](longOption = "hello", toAnnotationSeq = _ => Seq(HelloAnnotation), helpText = "Hello option") + ) } @@ -30,15 +28,13 @@ class BarLibrary extends RegisteredLibrary { def name: String = "Bar" val options = Seq( - new ShellOption[Unit]( - longOption = "world", - toAnnotationSeq = _ => Seq(HelloAnnotation), - helpText = "World option") ) + new ShellOption[Unit](longOption = "world", toAnnotationSeq = _ => Seq(HelloAnnotation), helpText = "World option") + ) } class RegistrationSpec extends AnyFlatSpec with Matchers { - behavior of "RegisteredTransform" + behavior.of("RegisteredTransform") it should "FooTransform should be discovered by Java.util.ServiceLoader" in { val iter = ServiceLoader.load(classOf[RegisteredTransform]).iterator() @@ -46,10 +42,10 @@ class RegistrationSpec extends AnyFlatSpec with Matchers { while (iter.hasNext) { transforms += iter.next() } - transforms.map(_.getClass.getName) should contain ("firrtlTests.options.FooTransform") + transforms.map(_.getClass.getName) should contain("firrtlTests.options.FooTransform") } - behavior of "RegisteredLibrary" + behavior.of("RegisteredLibrary") it should "BarLibrary be discovered by Java.util.ServiceLoader" in { val iter = ServiceLoader.load(classOf[RegisteredLibrary]).iterator() @@ -57,6 +53,6 @@ class RegistrationSpec extends AnyFlatSpec with Matchers { while (iter.hasNext) { transforms += iter.next() } - transforms.map(_.getClass.getName) should contain ("firrtlTests.options.BarLibrary") + transforms.map(_.getClass.getName) should contain("firrtlTests.options.BarLibrary") } } diff --git a/src/test/scala/firrtlTests/options/ShellSpec.scala b/src/test/scala/firrtlTests/options/ShellSpec.scala index af6b2669..178b1128 100644 --- a/src/test/scala/firrtlTests/options/ShellSpec.scala +++ b/src/test/scala/firrtlTests/options/ShellSpec.scala @@ -2,7 +2,6 @@ package firrtlTests.options - import firrtl.annotations.NoTargetAnnotation import firrtl.options.Shell import org.scalatest.flatspec.AnyFlatSpec @@ -17,25 +16,26 @@ class ShellSpec extends AnyFlatSpec with Matchers { case object E extends NoTargetAnnotation trait AlphabeticalCli { this: Shell => - parser.opt[Unit]('c', "c-option").unbounded().action( (x, c) => C +: c ) - parser.opt[Unit]('d', "d-option").unbounded().action( (x, c) => D +: c ) - parser.opt[Unit]('e', "e-option").unbounded().action( (x, c) => E +: c ) } + parser.opt[Unit]('c', "c-option").unbounded().action((x, c) => C +: c) + parser.opt[Unit]('d', "d-option").unbounded().action((x, c) => D +: c) + parser.opt[Unit]('e', "e-option").unbounded().action((x, c) => E +: c) + } - behavior of "Shell" + behavior.of("Shell") it should "detect all registered libraries and transforms" in { val shell = new Shell("foo") info("Found FooTransform") - shell.registeredTransforms.map(_.getClass.getName) should contain ("firrtlTests.options.FooTransform") + shell.registeredTransforms.map(_.getClass.getName) should contain("firrtlTests.options.FooTransform") info("Found BarLibrary") - shell.registeredLibraries.map(_.getClass.getName) should contain ("firrtlTests.options.BarLibrary") + shell.registeredLibraries.map(_.getClass.getName) should contain("firrtlTests.options.BarLibrary") } it should "correctly order annotations and options" in { val shell = new Shell("foo") with AlphabeticalCli - shell.parse(Array("-c", "-d", "-e"), Seq(A, B)).toSeq should be (Seq(A, B, C, D, E)) + shell.parse(Array("-c", "-d", "-e"), Seq(A, B)).toSeq should be(Seq(A, B, C, D, E)) } } diff --git a/src/test/scala/firrtlTests/options/phases/AddDefaultsSpec.scala b/src/test/scala/firrtlTests/options/phases/AddDefaultsSpec.scala index 3401a408..f625f991 100644 --- a/src/test/scala/firrtlTests/options/phases/AddDefaultsSpec.scala +++ b/src/test/scala/firrtlTests/options/phases/AddDefaultsSpec.scala @@ -2,7 +2,6 @@ package firrtlTests.options.phases - import firrtl.options.{Phase, TargetDirAnnotation} import firrtl.options.phases.AddDefaults import org.scalatest.flatspec.AnyFlatSpec @@ -16,13 +15,13 @@ class AddDefaultsSpec extends AnyFlatSpec with Matchers { val defaultDir = TargetDirAnnotation(".") } - behavior of classOf[AddDefaults].toString + behavior.of(classOf[AddDefaults].toString) it should "add a TargetDirAnnotation if it does not exist" in new Fixture { - phase.transform(Seq.empty).toSeq should be (Seq(defaultDir)) + phase.transform(Seq.empty).toSeq should be(Seq(defaultDir)) } it should "don't add a TargetDirAnnotation if it exists" in new Fixture { - phase.transform(Seq(targetDir)).toSeq should be (Seq(targetDir)) + phase.transform(Seq(targetDir)).toSeq should be(Seq(targetDir)) } } diff --git a/src/test/scala/firrtlTests/options/phases/ChecksSpec.scala b/src/test/scala/firrtlTests/options/phases/ChecksSpec.scala index 96d6569d..62afed94 100644 --- a/src/test/scala/firrtlTests/options/phases/ChecksSpec.scala +++ b/src/test/scala/firrtlTests/options/phases/ChecksSpec.scala @@ -2,7 +2,6 @@ package firrtlTests.options.phases - import firrtl.AnnotationSeq import firrtl.options.{OptionsException, OutputAnnotationFileAnnotation, Phase, TargetDirAnnotation} import firrtl.options.phases.Checks @@ -20,9 +19,9 @@ class ChecksSpec extends AnyFlatSpec with Matchers { val min = Seq(targetDir) def checkExceptionMessage(phase: Phase, annotations: AnnotationSeq, messageStart: String): Unit = - intercept[OptionsException]{ phase.transform(annotations) }.getMessage should startWith(messageStart) + intercept[OptionsException] { phase.transform(annotations) }.getMessage should startWith(messageStart) - behavior of classOf[Checks].toString + behavior.of(classOf[Checks].toString) it should "enforce exactly one TargetDirAnnotation" in new Fixture { info("0 target directories throws an exception") diff --git a/src/test/scala/firrtlTests/options/phases/GetIncludesSpec.scala b/src/test/scala/firrtlTests/options/phases/GetIncludesSpec.scala index 7d20ac89..95c2a435 100644 --- a/src/test/scala/firrtlTests/options/phases/GetIncludesSpec.scala +++ b/src/test/scala/firrtlTests/options/phases/GetIncludesSpec.scala @@ -2,12 +2,10 @@ package firrtlTests.options.phases - import java.io.{File, PrintWriter} import firrtl.AnnotationSeq -import firrtl.annotations.{AnnotationFileNotFoundException, JsonProtocol, - NoTargetAnnotation} +import firrtl.annotations.{AnnotationFileNotFoundException, JsonProtocol, NoTargetAnnotation} import firrtl.options.phases.GetIncludes import firrtl.options.{InputAnnotationFileAnnotation, Phase} import firrtl.util.BackendCompilationUtilities @@ -29,10 +27,10 @@ class GetIncludesSpec extends AnyFlatSpec with Matchers with BackendCompilationU def checkAnnos(a: AnnotationSeq, b: AnnotationSeq): Unit = { info("read the expected number of annotations") - a.size should be (b.size) + a.size should be(b.size) info("annotations match exact order") - a.zip(b).foreach{ case (ax, bx) => ax should be (bx) } + a.zip(b).foreach { case (ax, bx) => ax should be(bx) } } val files = Seq( @@ -43,19 +41,21 @@ class GetIncludesSpec extends AnyFlatSpec with Matchers with BackendCompilationU new File(dir + "/e.anno.json") -> Seq(E) ) - files.foreach{ case (file, annotations) => - val pw = new PrintWriter(file) - pw.write(JsonProtocol.serialize(annotations)) - pw.close() + files.foreach { + case (file, annotations) => + val pw = new PrintWriter(file) + pw.write(JsonProtocol.serialize(annotations)) + pw.close() } class Fixture { val phase: Phase = new GetIncludes } - behavior of classOf[GetIncludes].toString + behavior.of(classOf[GetIncludes].toString) it should "throw an exception if the annotation file doesn't exit" in new Fixture { - intercept[AnnotationFileNotFoundException]{ phase.transform(Seq(ref("f"))) } - .getMessage should startWith("Annotation file") + intercept[AnnotationFileNotFoundException] { phase.transform(Seq(ref("f"))) }.getMessage should startWith( + "Annotation file" + ) } it should "read annotations from a file" in new Fixture { @@ -75,9 +75,9 @@ class GetIncludesSpec extends AnyFlatSpec with Matchers with BackendCompilationU checkAnnos(out, expect) - Seq("d", "e").foreach{ x => + Seq("d", "e").foreach { x => info(s"a warning about '$x.anno.json' was printed") - stdout should include (s"Warning: Annotation file ($dir/$x.anno.json) already included!") + stdout should include(s"Warning: Annotation file ($dir/$x.anno.json) already included!") } } @@ -90,7 +90,7 @@ class GetIncludesSpec extends AnyFlatSpec with Matchers with BackendCompilationU checkAnnos(out, expect) info("a warning about 'a.anno.json' was printed") - stdout should include (s"Warning: Annotation file ($dir/a.anno.json)") + stdout should include(s"Warning: Annotation file ($dir/a.anno.json)") } } diff --git a/src/test/scala/firrtlTests/options/phases/WriteOutputAnnotationsSpec.scala b/src/test/scala/firrtlTests/options/phases/WriteOutputAnnotationsSpec.scala index 0a3cce67..4fe16041 100644 --- a/src/test/scala/firrtlTests/options/phases/WriteOutputAnnotationsSpec.scala +++ b/src/test/scala/firrtlTests/options/phases/WriteOutputAnnotationsSpec.scala @@ -2,7 +2,6 @@ package firrtlTests.options.phases - import java.io.File import firrtl.AnnotationSeq @@ -15,7 +14,8 @@ import firrtl.options.{ PhaseException, StageOptions, TargetDirAnnotation, - WriteDeletedAnnotation} + WriteDeletedAnnotation +} import firrtl.options.Viewer.view import firrtl.options.phases.{GetIncludes, WriteOutputAnnotations} import org.scalatest.flatspec.AnyFlatSpec @@ -37,33 +37,38 @@ class WriteOutputAnnotationsSpec extends AnyFlatSpec with Matchers with firrtl.t info(s"reading '$f' works") val read = (new GetIncludes) .transform(Seq(InputAnnotationFileAnnotation(f.toString))) - .filterNot{ + .filterNot { case a @ DeletedAnnotation(_, _: InputAnnotationFileAnnotation) => true - case _ => false } + case _ => false + } info(s"annotations in file are expected size") - read.size should be (a.size) + read.size should be(a.size) read .zip(a) - .foreach{ case (read, expected) => - info(s"$read matches") - read should be (expected) } + .foreach { + case (read, expected) => + info(s"$read matches") + read should be(expected) + } f.delete() } class Fixture { val phase: Phase = new WriteOutputAnnotations } - behavior of classOf[WriteOutputAnnotations].toString + behavior.of(classOf[WriteOutputAnnotations].toString) it should "write annotations to a file (excluding DeletedAnnotations)" in new Fixture { val file = new File(dir + "/should-write-annotations-to-a-file.anno.json") - val annotations = Seq( OutputAnnotationFileAnnotation(file.toString), - WriteOutputAnnotationsSpec.FooAnnotation, - WriteOutputAnnotationsSpec.BarAnnotation(0), - WriteOutputAnnotationsSpec.BarAnnotation(1), - DeletedAnnotation("foo", WriteOutputAnnotationsSpec.FooAnnotation) ) + val annotations = Seq( + OutputAnnotationFileAnnotation(file.toString), + WriteOutputAnnotationsSpec.FooAnnotation, + WriteOutputAnnotationsSpec.BarAnnotation(0), + WriteOutputAnnotationsSpec.BarAnnotation(1), + DeletedAnnotation("foo", WriteOutputAnnotationsSpec.FooAnnotation) + ) val expected = annotations.filter { case a: DeletedAnnotation => false case a => true @@ -71,31 +76,35 @@ class WriteOutputAnnotationsSpec extends AnyFlatSpec with Matchers with firrtl.t val out = phase.transform(annotations) info("annotations are unmodified") - out.toSeq should be (annotations) + out.toSeq should be(annotations) fileContainsAnnotations(file, expected) } it should "include DeletedAnnotations if a WriteDeletedAnnotation is present" in new Fixture { val file = new File(dir + "should-include-deleted.anno.json") - val annotations = Seq( OutputAnnotationFileAnnotation(file.toString), - WriteOutputAnnotationsSpec.FooAnnotation, - WriteOutputAnnotationsSpec.BarAnnotation(0), - WriteOutputAnnotationsSpec.BarAnnotation(1), - DeletedAnnotation("foo", WriteOutputAnnotationsSpec.FooAnnotation), - WriteDeletedAnnotation ) + val annotations = Seq( + OutputAnnotationFileAnnotation(file.toString), + WriteOutputAnnotationsSpec.FooAnnotation, + WriteOutputAnnotationsSpec.BarAnnotation(0), + WriteOutputAnnotationsSpec.BarAnnotation(1), + DeletedAnnotation("foo", WriteOutputAnnotationsSpec.FooAnnotation), + WriteDeletedAnnotation + ) val out = phase.transform(annotations) info("annotations are unmodified") - out.toSeq should be (annotations) + out.toSeq should be(annotations) fileContainsAnnotations(file, annotations) } it should "do nothing if no output annotation file is specified" in new Fixture { - val annotations = Seq( WriteOutputAnnotationsSpec.FooAnnotation, - WriteOutputAnnotationsSpec.BarAnnotation(0), - WriteOutputAnnotationsSpec.BarAnnotation(1) ) + val annotations = Seq( + WriteOutputAnnotationsSpec.FooAnnotation, + WriteOutputAnnotationsSpec.BarAnnotation(0), + WriteOutputAnnotationsSpec.BarAnnotation(1) + ) val out = catchWrites { phase.transform(annotations) } match { case Right(a) => @@ -106,14 +115,16 @@ class WriteOutputAnnotationsSpec extends AnyFlatSpec with Matchers with firrtl.t } info("annotations are unmodified") - out.toSeq should be (annotations) + out.toSeq should be(annotations) } it should "write CustomFileEmission annotations" in new Fixture { val file = new File("write-CustomFileEmission-annotations.anno.json") - val annotations = Seq( TargetDirAnnotation(dir), - OutputAnnotationFileAnnotation(file.toString), - WriteOutputAnnotationsSpec.Custom("hello!") ) + val annotations = Seq( + TargetDirAnnotation(dir), + OutputAnnotationFileAnnotation(file.toString), + WriteOutputAnnotationsSpec.Custom("hello!") + ) val serializedFileName = view[StageOptions](annotations).getBuildFileName("Custom", Some(".Emission")) val expected = annotations.map { case _: WriteOutputAnnotationsSpec.Custom => WriteOutputAnnotationsSpec.Replacement(serializedFileName) @@ -123,7 +134,7 @@ class WriteOutputAnnotationsSpec extends AnyFlatSpec with Matchers with firrtl.t val out = phase.transform(annotations) info("annotations are unmodified") - out.toSeq should be (annotations) + out.toSeq should be(annotations) fileContainsAnnotations(new File(dir, file.toString), expected) @@ -133,13 +144,15 @@ class WriteOutputAnnotationsSpec extends AnyFlatSpec with Matchers with firrtl.t it should "error if multiple annotations try to write to the same file" in new Fixture { val file = new File("write-CustomFileEmission-annotations-error.anno.json") - val annotations = Seq( TargetDirAnnotation(dir), - OutputAnnotationFileAnnotation(file.toString), - WriteOutputAnnotationsSpec.Custom("foo"), - WriteOutputAnnotationsSpec.Custom("bar") ) + val annotations = Seq( + TargetDirAnnotation(dir), + OutputAnnotationFileAnnotation(file.toString), + WriteOutputAnnotationsSpec.Custom("foo"), + WriteOutputAnnotationsSpec.Custom("bar") + ) intercept[PhaseException] { phase.transform(annotations) - }.getMessage should startWith ("Multiple CustomFileEmission annotations") + }.getMessage should startWith("Multiple CustomFileEmission annotations") } } |
