如何扩展scalatest assert宏
我想谈谈:如何扩展scalatest assert宏,scala,macros,scalatest,Scala,Macros,Scalatest,我想谈谈: eventually { assert(x == 0) } 进入: 并且仍然会收到一条很好的控制台消息: Caused by: org.scalatest.exceptions.TestFailedException: 1 did not equal 0 如何实现验证?验证也必须是宏: import scala.language.experimental.macros import scala.reflect.macros.blackbox class VerifyMacro(
eventually { assert(x == 0) }
进入:
并且仍然会收到一条很好的控制台消息:
Caused by: org.scalatest.exceptions.TestFailedException: 1 did not equal 0
如何实现
验证
?验证
也必须是宏:
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
}
令人惊叹的!谢谢
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
}