使用scalatest检查Scala宏的编译错误

时间:2018-02-14 14:54:12

标签: scala scalatest scala-macros

是否有更优雅的方法来测试由Scala-macros生成的编译错误而不是粘贴到下面?

  assert(intercept[TestFailedException](assertCompiles {
    """case class DuplicatedNamed(@named("x") @named("y") z: Int)
      |JsonCodecMaker.make[DuplicatedNamed](CodecMakerConfig())""".stripMargin
  }).getMessage.contains {
    """Duplicated 'com.github.plokhotnyuk.jsoniter_scala.macros.named'
      |defined for 'z' of 'DuplicatedNamed'.""".stripMargin.replace('\n', ' ')
  })

0 个答案:

没有答案