File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
main/scala/chisel3/testing/scalatest
test/scala-2/chiselTests/testing/scalatest Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,11 @@ trait HasConfigMap extends TestSuiteMixin { self: TestSuite =>
4242 *
4343 * This is only valid during a test. It will be `None` if used outside a
4444 * test.
45+ *
46+ * @throws RuntimeException if called outside a Scalatest test
4547 */
46- def configMap : Option [ConfigMap ] = _configMap.value
48+ def configMap : ConfigMap = _configMap.value.getOrElse {
49+ throw new RuntimeException (" configMap may only be accessed inside a Scalatest test" )
50+ }
4751
4852}
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ package chiselTests .testing .scalatest
4+
5+ import chisel3 .testing .scalatest .HasConfigMap
6+ import org .scalatest .flatspec .AnyFlatSpec
7+ import org .scalatest .matchers .should .Matchers
8+
9+ class HasConfigMapSpec extends AnyFlatSpec with Matchers with HasConfigMap {
10+
11+ behavior of " HasConfigMap"
12+
13+ it should " be accessible inside a test" in {
14+ configMap
15+ }
16+
17+ val outsideTestException = intercept[Exception ] {
18+ configMap
19+ }
20+
21+ it should " throw a RuntimeException if used outside a test" in {
22+ outsideTestException shouldBe a[RuntimeException ]
23+ outsideTestException.getMessage should include(" configMap may only be accessed inside a Scalatest test" )
24+ }
25+
26+ }
You can’t perform that action at this time.
0 commit comments