Skip to content

Commit ef325d3

Browse files
committed
fixup! [testing] Add HasConfigMap Scalatest trait
1 parent 24dbcfd commit ef325d3

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/main/scala/chisel3/testing/scalatest/HasConfigMap.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

0 commit comments

Comments
 (0)