summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/WarningSpec.scala
blob: 1cef1ffc0c8cec5f9489e01e4a552df6fa882af3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// SPDX-License-Identifier: Apache-2.0

package chiselTests

import chisel3._
import chisel3.util._
import chisel3.stage.ChiselStage
import chisel3.experimental.ChiselEnum
import chisel3.experimental.EnumType

class WarningSpec extends ChiselFlatSpec with Utils {
  behavior.of("Warnings")

  object MyEnum extends ChiselEnum {
    val e0, e1, e2 = Value
  }

  class MyModule extends Module {
    val in = IO(Input(UInt(2.W)))
    val out1 = IO(Output(MyEnum()))
    val out2 = IO(Output(MyEnum()))
    def func(out: EnumType): Unit = {
      out := MyEnum(in)
    }
    func(out1)
    func(out2)
  }

  "Warnings" should "be de-duplicated" in {
    val (log, _) = grabLog(ChiselStage.elaborate(new MyModule))
    def countSubstring(s: String, sub: String) =
      s.sliding(sub.length).count(_ == sub)
    countSubstring(log, "Casting non-literal UInt") should be(1)
  }

  "Warnings" should "be treated as errors with warningsAsErrors" in {
    a[ChiselException] should be thrownBy extractCause[ChiselException] {
      val args = Array("--warnings-as-errors")
      (new ChiselStage).emitChirrtl(new MyModule, args)
    }
  }
}