我想转:
id
成:
bar
仍然可以获得一个很好的控制台消息:
eventually { assert(x == 0) }
如何实施verify { x == 0 }
?
答案 0 :(得分:3)
verify
也必须是一个宏:
import scala.language.experimental.macros
import scala.reflect.macros.blackbox
class VerifyMacro(val c: blackbox.Context) {
import c.universe._
def verifyImpl(condition: Tree): Tree =
q"${c.prefix}.eventually(${c.prefix}.assert($condition))"
}
import org.scalatest._
import org.scalatest.concurrent._
trait Verifications extends Assertions with Eventually {
def verify(condition: Boolean): Assertion = macro VerifyMacro.verifyImpl
}