Skip to content

Commit ffab0c5

Browse files
committed
Merge branch 'cheeseng-fix-generatorspec-2.13' into 3.1.x
2 parents ea75d08 + 68516dc commit ffab0c5

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

project/GenColCompatHelper.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ object GenColCompatHelper {
5656
| object Factory {}
5757
|
5858
| def className(col: scala.collection.Iterable[_]): String = org.scalactic.NameUtil.getSimpleNameOfAnObjectsClass(col)
59+
|
60+
| def newBuilder[A, C](f: Factory[A, C]): scala.collection.mutable.Builder[A, C] = f.newBuilder
5961
|}
6062
|
6163
""".stripMargin
@@ -115,6 +117,7 @@ object GenColCompatHelper {
115117
| }
116118
| def className(col: scala.collection.GenTraversable[_]): String = col.stringPrefix
117119
|
120+
| def newBuilder[A, C](f: Factory[A, C]): scala.collection.mutable.Builder[A, C] = f.apply()
118121
|}
119122
|
120123
""".stripMargin

scalatest-test/src/test/scala/org/scalatest/prop/GeneratorSpec.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,7 +2631,7 @@ class GeneratorSpec extends FunSpec with Matchers {
26312631
}
26322632

26332633
import scala.collection.GenTraversable
2634-
import scala.collection.generic.GenericCompanion
2634+
import org.scalactic.ColCompatHelper
26352635
/**
26362636
* A common test for how we do shrinking in the collection Generators.
26372637
*
@@ -2644,7 +2644,7 @@ class GeneratorSpec extends FunSpec with Matchers {
26442644
* @param generator the Generator for this collection type
26452645
* @tparam F the collection type we are testing
26462646
*/
2647-
def shrinkByStrategery[F[Int] <: GenTraversable[Int]](factory: GenericCompanion[F])(implicit generator: Generator[F[Int]]): Unit = {
2647+
def shrinkByStrategery[F[Int] <: GenTraversable[Int]](factory: ColCompatHelper.Factory[Int, F[Int]])(implicit generator: Generator[F[Int]]): Unit = {
26482648
import GeneratorDrivenPropertyChecks._
26492649
val intGenerator = Generator.intGenerator
26502650
val (intCanonicalsIt, _) = intGenerator.canonicals(Randomizer.default)
@@ -2660,14 +2660,14 @@ class GeneratorSpec extends FunSpec with Matchers {
26602660

26612661
// Then should come one-element Lists of the canonicals of the type
26622662
val phase2 = shrinks.drop(1).take(intCanonicals.length)
2663-
phase2 shouldEqual (intCanonicals.map(i => factory(i)))
2663+
phase2 shouldEqual (intCanonicals.map(i => ColCompatHelper.newBuilder(factory).+=(i).result))
26642664

26652665
// Phase 3 should be one-element lists of all distinct values in the value passed to shrink
26662666
// If xs already is a one-element list, then we don't do this, because then xs would appear in the output.
26672667
val xsList = xs.toList
26682668
val xsDistincts = if (xsList.length > 1) xsList.distinct else Nil
26692669
val phase3 = shrinks.drop(1 + intCanonicals.length).take(xsDistincts.length)
2670-
phase3 shouldEqual (xsDistincts.map(i => factory(i)))
2670+
phase3 shouldEqual (xsDistincts.map(i => ColCompatHelper.newBuilder(factory).+=(i).result))
26712671

26722672
// Phase 4 should be n-element lists that are prefixes cut in half
26732673
val theHalves = shrinks.drop(1 + intCanonicals.length + xsDistincts.length)
@@ -2683,6 +2683,8 @@ class GeneratorSpec extends FunSpec with Matchers {
26832683
}
26842684
}
26852685

2686+
import org.scalactic.ColCompatHelper.Factory._
2687+
26862688
describe("for Lists") {
26872689
it("should offer a List[T] generator that returns a List[T] whose length equals the passed size") {
26882690

0 commit comments

Comments
 (0)