Skip to content

Commit 2e81b64

Browse files
Check that we are keeping the same exception while shrinking
1 parent d6f64c4 commit 2e81b64

File tree

1 file changed

+7
-3
lines changed
  • core/shared/src/main/scala/org/scalacheck

1 file changed

+7
-3
lines changed

core/shared/src/main/scala/org/scalacheck/Prop.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -772,10 +772,13 @@ object Prop {
772772
/*
773773
* Returns the first failed result in Left or success in Right.
774774
*/
775-
def getFirstFailure(xs: Stream[T]): Either[(T,Result),(T,Result)] = {
775+
def getFirstFailure(xs: Stream[T], exceptionFilter: Option[Class[_]]): Either[(T,Result),(T,Result)] = {
776776
assert(!xs.isEmpty, "Stream cannot be empty")
777777
val results = xs.map(x => (x, result(x)))
778-
results.dropWhile(!_._2.failure).headOption match {
778+
results.dropWhile {
779+
case (_, Result(Exception(e), _, _, _)) => !exceptionFilter.contains(e.getClass)
780+
case (_, r) => !r.failure
781+
}.headOption match {
779782
case None => Right(results.head)
780783
case Some(xr) => Left(xr)
781784
}
@@ -784,7 +787,8 @@ object Prop {
784787
def shrinker(x: T, r: Result, shrinks: Int, orig: T): Result = {
785788
val xs = shrink(x)
786789
val res = r.addArg(Arg(labels,x,shrinks,orig,pp(x),pp(orig)))
787-
if(xs.isEmpty) res else getFirstFailure(xs) match {
790+
val originalException = Some(r.status).collect { case Exception(e) => e.getClass() }
791+
if(xs.isEmpty) res else getFirstFailure(xs, originalException) match {
788792
case Right((x2,r2)) => res
789793
case Left((x2,r2)) => shrinker(x2, replOrig(r,r2), shrinks+1, orig)
790794
}

0 commit comments

Comments
 (0)