在scalacheck属性中使用specs匹配器

Jer*_*iho 2 specs scala scalacheck

我正在尝试在scalacheck属性中使用specs mathers.例如,我有一个像这样工作的匹配器:

x must matchMyMatcher(y)
Run Code Online (Sandbox Code Playgroud)

当我想在scalacheck属性中使用此匹配器时,我执行以下操作:

import org.scalacheck._
import org.specs._
...
val prop = Prop.forAll(myGen){
    (x,y) => new matchMyMatcher(x)(y)._1
}
prop must pass
Run Code Online (Sandbox Code Playgroud)

不幸的是,在这种情况下,我删除了我在matcher中放置的调试信息,当属性失败时我需要它.是否有规定的方法在道具内使用匹配器?

Eri*_*ric 6

如果您对匹配器使用"must",您将收到正确的失败消息:

val gen = Gen.oneOf(("a", "a"), ("b", "b2"))
val function = (pair: (String, String)) => pair._1 must myMatcher(pair._2)
gen must pass(function)
Run Code Online (Sandbox Code Playgroud)

然后,在这种情况下,您的示例应该失败:

> A counter-example is '(b,b2)': 'b' is not equal to 'b2' (after 0 tries)