Open brandon-leapyear opened 3 years ago
:sparkles: This is an old work account. Please reference @brandonchinn178 for all future communication :sparkles:
Currently working around by writing my own Checkers
trait with an implicit function to convert an Assertion
into a Prop
import org.scalacheck.Prop
import org.scalacheck.Prop._
import org.scalatest.Assertion
import org.scalatest.exceptions.DiscardedEvaluationException
import org.scalatestplus.scalacheck
// https://github.com/scalatest/scalatestplus-scalacheck/issues/50
trait Checkers extends scalacheck.Checkers {
implicit def assertionToProp(test: Assertion)
(implicit
asserting: scalacheck.CheckerAsserting[Assertion]
): Prop = {
val (unmetCondition, succeeded, exception) =
try {
val (succeeded, cause) = asserting.succeed(test)
(false, succeeded, cause)
}
catch {
case e: DiscardedEvaluationException => (true, false, None)
case e: Throwable => (false, false, Some(e))
}
!unmetCondition ==> (
if (exception.isEmpty) {
if (succeeded)
Prop.passed
else
Prop.falsified
}
else
Prop.exception(exception.get)
)
}
}
As a follow up to https://github.com/scalatest/scalatest/issues/251,
ScalaCheckDrivenPropertyChecks
isn't good for nested forAlls and is also missing features like forAllNoShrink.It seems like
Checkers
is what I want anyway, to explicitly build up aProp
, then check it. But it currently doesn't work with normal scalatest assertions likeThis currently throws a compile-time error:
It would be nice to augment
Checkers
or provide a separate class to include support for normal scalatest assertions.