Skip to content

Commit 2404f75

Browse files
committed
Cross-build from a single branch
1 parent 39203ee commit 2404f75

File tree

17 files changed

+189
-57
lines changed

17 files changed

+189
-57
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ matrix:
4646
exclude:
4747
- scala: 2.10.7
4848
env: PLATFORM=js SBT_PARALLEL=true WORKERS=1 DEPLOY=true SCALAJS_VERSION=1.0.0-M3
49+
- scala: 2.13.0-M4
50+
env: PLATFORM=js SBT_PARALLEL=true WORKERS=1 DEPLOY=true SCALAJS_VERSION=1.0.0-M3

build.sbt

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
sourceDirectory := file("dummy source directory")
22

3+
val scalaMajorVersion = SettingKey[Int]("scalaMajorVersion")
4+
35
scalaVersionSettings
46

57
lazy val versionNumber = "1.14.1"
@@ -10,7 +12,13 @@ lazy val travisCommit = Option(System.getenv().get("TRAVIS_COMMIT"))
1012

1113
lazy val scalaVersionSettings = Seq(
1214
scalaVersion := "2.12.6",
13-
crossScalaVersions := Seq("2.10.7", "2.11.12", "2.13.0-M4", scalaVersion.value)
15+
crossScalaVersions := Seq("2.10.7", "2.11.12", "2.13.0-M4", scalaVersion.value),
16+
scalaMajorVersion := {
17+
val v = scalaVersion.value
18+
CrossVersion.partialVersion(v).map(_._2.toInt).getOrElse {
19+
throw new RuntimeException(s"could not get Scala major version from $v")
20+
}
21+
}
1422
)
1523

1624
lazy val sharedSettings = MimaSettings.settings ++ scalaVersionSettings ++ Seq(
@@ -43,6 +51,11 @@ lazy val sharedSettings = MimaSettings.settings ++ scalaVersionSettings ++ Seq(
4351

4452
unmanagedSourceDirectories in Compile += (baseDirectory in LocalRootProject).value / "src" / "main" / "scala",
4553

54+
unmanagedSourceDirectories in Compile += {
55+
val s = if (scalaMajorVersion.value >= 13) "+" else "-"
56+
(baseDirectory in LocalRootProject).value / "src" / "main" / s"scala-2.13$s"
57+
},
58+
4659
unmanagedSourceDirectories in Test += (baseDirectory in LocalRootProject).value / "src" / "test" / "scala",
4760

4861
resolvers += "sonatype" at "https://oss.sonatype.org/content/repositories/releases",
@@ -54,17 +67,18 @@ lazy val sharedSettings = MimaSettings.settings ++ scalaVersionSettings ++ Seq(
5467
"-encoding", "UTF-8",
5568
"-feature",
5669
"-unchecked",
57-
"-Xfatal-warnings",
5870
"-Xfuture",
5971
"-Ywarn-dead-code",
6072
"-Ywarn-inaccessible",
6173
"-Ywarn-nullary-override",
6274
"-Ywarn-nullary-unit",
6375
"-Ywarn-numeric-widen") ++ {
64-
scalaBinaryVersion.value match {
65-
case "2.10" => Seq("-Xlint")
66-
case "2.11" => Seq("-Xlint", "-Ywarn-infer-any", "-Ywarn-unused-import")
67-
case _ => Seq("-Xlint:-unused", "-Ywarn-infer-any", "-Ywarn-unused-import", "-Ywarn-unused:-patvars,-implicits,-locals,-privates,-explicits")
76+
val modern = Seq("-Xlint:-unused", "-Ywarn-infer-any", "-Ywarn-unused-import", "-Ywarn-unused:-patvars,-implicits,-locals,-privates,-explicits")
77+
scalaMajorVersion.value match {
78+
case 10 => Seq("-Xfatal-warnings", "-Xlint")
79+
case 11 => Seq("-Xfatal-warnings", "-Xlint", "-Ywarn-infer-any", "-Ywarn-unused-import")
80+
case 12 => "-Xfatal-warnings" +: modern
81+
case 13 => modern
6882
}
6983
},
7084

jvm/src/test/scala/org/scalacheck/CogenSpecification.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import org.scalacheck.Gen.listOfN
55
import org.scalacheck.GenSpecification.arbSeed
66
import org.scalacheck.Prop.forAll
77
import org.scalacheck.rng.Seed
8+
import ScalaVersionSpecific._
9+
810

911
import scala.util.Try
1012
import scala.concurrent.duration.{Duration, FiniteDuration}
@@ -140,6 +142,7 @@ object CogenSpecification extends Properties("Cogen") {
140142
include(cogenLaws[String], "cogenString.")
141143
include(cogenLaws[List[Int]], "cogenList.")
142144
include(cogenLaws[Vector[Int]], "cogenVector.")
145+
include(cogenLaws[Stream[Int]], "cogenStream.")
143146
include(cogenLaws[LazyList[Int]], "cogenLazyList.")
144147
include(cogenLaws[Set[Int]], "cogenSet.")
145148
include(cogenLaws[Map[Int, Int]], "cogenMap.")

jvm/src/test/scala/org/scalacheck/GenSpecification.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Shrink._
1818
import java.util.Date
1919
import scala.util.{Try, Success, Failure}
2020

21-
object GenSpecification extends Properties("Gen") {
21+
object GenSpecification extends Properties("Gen") with GenSpecificationVersionSpecific {
2222

2323
implicit val arbSeed: Arbitrary[Seed] = Arbitrary(
2424
arbitrary[Long] flatMap Seed.apply
@@ -179,6 +179,10 @@ object GenSpecification extends Properties("Gen") {
179179
l.length == 0
180180
}
181181

182+
property("infiniteStream") = forAll(infiniteStream(arbitrary[Int]), arbitrary[Short]) { (s, n) =>
183+
s.drop(n & 0xffff).nonEmpty
184+
}
185+
182186
property("infiniteLazyList") = forAll(infiniteLazyList(arbitrary[Int]), arbitrary[Short]) { (s, n) =>
183187
s.drop(n & 0xffff).nonEmpty
184188
}

project/plugin.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.2.0")
33
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1")
44

55
val scalaJSVersion =
6-
Option(System.getenv("SCALAJS_VERSION")).getOrElse("0.6.22")
6+
Option(System.getenv("SCALAJS_VERSION")).getOrElse("0.6.23")
77

88
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
99

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.scalacheck
2+
3+
import java.util.ArrayList
4+
5+
import scala.collection.{BitSet, Factory}
6+
import scala.collection.mutable.Builder
7+
import rng.Seed
8+
9+
private[scalacheck] object ScalaVersionSpecific {
10+
def toLazyList[T](i: IterableOnce[T]) = i.to(LazyList)
11+
12+
def listFactory[T]: Factory[T, List[T]] =
13+
new Factory[T, List[T]] with Serializable {
14+
def fromSpecific(source: IterableOnce[T]): List[T] = List.from(source)
15+
def newBuilder: Builder[T, List[T]] = List.newBuilder[T]
16+
}
17+
18+
def bitsetFactory[T]: Factory[Int, BitSet] =
19+
new Factory[Int, BitSet] with Serializable {
20+
def fromSpecific(source: IterableOnce[Int]) = BitSet.fromSpecific(source)
21+
def newBuilder: Builder[Int, BitSet] = BitSet.newBuilder
22+
}
23+
24+
def mapFactory[T, U]: Factory[(T, U), Map[T, U]] =
25+
new Factory[(T, U), Map[T, U]] with Serializable {
26+
def fromSpecific(source: IterableOnce[(T, U)]) = Map.from(source)
27+
def newBuilder: Builder[(T, U), Map[T, U]] = Map.newBuilder[T, U]
28+
}
29+
}
30+
31+
private[scalacheck] trait GenVersionSpecific {
32+
33+
/** Generates an infinite lazy list. */
34+
def infiniteLazyList[T](g: => Gen[T]): Gen[LazyList[T]] = {
35+
def unfold[A, S](z: S)(f: S => Option[(A, S)]): LazyList[A] = f(z) match {
36+
case Some((h, s)) => h #:: unfold(s)(f)
37+
case None => LazyList.empty
38+
}
39+
Gen.gen { (p, seed0) =>
40+
new Gen.R[LazyList[T]] {
41+
val result: Option[LazyList[T]] = Some(unfold(seed0)(s => Some(g.pureApply(p, s) -> s.next)))
42+
val seed: Seed = seed0.next
43+
}
44+
}
45+
}
46+
}
47+
48+
private[scalacheck] trait GenSpecificationVersionSpecific
49+
50+
private[scalacheck] trait CogenVersionSpecific {
51+
implicit def cogenStream[A: Cogen]: Cogen[Stream[A]] =
52+
Cogen.it(_.iterator)
53+
}
54+
55+
private[scalacheck] class ArrayListBuilder[T] extends Builder[T, ArrayList[T]] {
56+
private val al = new ArrayList[T]
57+
def addOne(x: T): this.type = {
58+
al.add(x)
59+
this
60+
}
61+
def clear(): Unit = al.clear()
62+
def result(): ArrayList[T] = al
63+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.scalacheck
2+
3+
import java.util.ArrayList
4+
5+
import scala.collection.generic.{CanBuildFrom, Sorted}
6+
import scala.collection.immutable.Stream
7+
import scala.collection.mutable.Builder
8+
import scala.collection.{BitSet, TraversableOnce}
9+
10+
private[scalacheck] object ScalaVersionSpecific {
11+
def toLazyList[T](i: TraversableOnce[T]) = i.toStream
12+
13+
type Factory[-A, +C] = CanBuildFrom[Nothing, A, C]
14+
15+
def listFactory[T]: CanBuildFrom[List[T], T, List[T]] =
16+
new CanBuildFrom[List[T], T, List[T]] with Serializable {
17+
def apply(from: List[T]) = List.newBuilder[T]
18+
def apply() = List.newBuilder[T]
19+
}
20+
21+
def bitsetFactory[T]: CanBuildFrom[BitSet, Int, BitSet] =
22+
new CanBuildFrom[BitSet, Int, BitSet] with Serializable {
23+
def apply(from: BitSet) = BitSet.newBuilder
24+
def apply() = BitSet.newBuilder
25+
}
26+
27+
def mapFactory[T, U]: CanBuildFrom[Map[T, U], (T, U), Map[T, U]] =
28+
new CanBuildFrom[Map[T, U], (T, U), Map[T, U]] with Serializable {
29+
def apply(from: Map[T, U]) = Map.newBuilder[T, U]
30+
def apply() = Map.newBuilder[T, U]
31+
}
32+
33+
implicit class CBFExt[-A, +C](val cbf: CanBuildFrom[Nothing, A, C]) extends AnyVal {
34+
def newBuilder: Builder[A, C] = cbf()
35+
}
36+
37+
type LazyList[+A] = Stream[A]
38+
val LazyList = Stream
39+
40+
implicit class StreamExt[+A](val s: Stream[A]) extends AnyVal {
41+
def lazyAppendedAll[B >: A](rest: => TraversableOnce[B]): Stream[B] = s.append(rest)
42+
}
43+
44+
implicit class SortedExt[K, T <: Sorted[K, T]](val s: Sorted[K, T]) extends AnyVal {
45+
def rangeFrom(from: K): T = s.from(from)
46+
def rangeTo(to: K): T = s.to(to)
47+
def rangeUntil(until: K): T = s.until(until)
48+
}
49+
}
50+
51+
private[scalacheck] trait GenVersionSpecific
52+
private[scalacheck] trait CogenVersionSpecific
53+
54+
// Used in tests
55+
private[scalacheck] trait GenSpecificationVersionSpecific {
56+
def infiniteLazyList[T](g: => Gen[T]): Gen[Stream[T]] = Gen.infiniteStream(g)
57+
}
58+
59+
private[scalacheck] class ArrayListBuilder[T] extends Builder[T, ArrayList[T]] {
60+
private val al = new ArrayList[T]
61+
def +=(x: T): this.type = {
62+
al.add(x)
63+
this
64+
}
65+
def clear(): Unit = al.clear()
66+
def result(): ArrayList[T] = al
67+
}

src/main/scala/org/scalacheck/Cogen.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import scala.util.{Failure, Success, Try}
1616
import scala.concurrent.duration.{Duration, FiniteDuration}
1717
import java.math.BigInteger
1818
import rng.Seed
19+
import ScalaVersionSpecific._
1920

2021
sealed trait Cogen[T] extends Serializable {
2122

@@ -28,7 +29,7 @@ sealed trait Cogen[T] extends Serializable {
2829
Cogen((seed: Seed, s: S) => perturb(seed, f(s)))
2930
}
3031

31-
object Cogen extends CogenArities with CogenLowPriority {
32+
object Cogen extends CogenArities with CogenLowPriority with CogenVersionSpecific {
3233

3334
// for binary compatibility
3435
private[scalacheck] def apply[T](ev: Cogen[T]): Cogen[T] = ev

src/main/scala/org/scalacheck/Gen.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import language.implicitConversions
1515
import rng.Seed
1616
import util.Buildable
1717
import util.SerializableCanBuildFroms._
18+
import ScalaVersionSpecific._
1819

1920
import scala.annotation.tailrec
2021
import scala.collection.immutable.TreeMap
@@ -200,7 +201,7 @@ sealed abstract class Gen[+T] extends Serializable { self =>
200201
Gen.gen((p, seed) => doApply(p, f(seed)))
201202
}
202203

203-
object Gen extends GenArities{
204+
object Gen extends GenArities with GenVersionSpecific {
204205

205206
//// Private interface ////
206207

@@ -656,14 +657,14 @@ object Gen extends GenArities{
656657
def mapOfN[T,U](n: Int, g: Gen[(T,U)]) = buildableOfN[Map[T,U],(T,U)](n,g)
657658

658659
/** Generates an infinite lazy list. */
659-
def infiniteLazyList[T](g: => Gen[T]): Gen[LazyList[T]] = {
660-
def unfold[A, S](z: S)(f: S => Option[(A, S)]): LazyList[A] = f(z) match {
660+
def infiniteStream[T](g: => Gen[T]): Gen[Stream[T]] = {
661+
def unfold[A, S](z: S)(f: S => Option[(A, S)]): Stream[A] = f(z) match {
661662
case Some((h, s)) => h #:: unfold(s)(f)
662-
case None => LazyList.empty
663+
case None => Stream.empty
663664
}
664665
gen { (p, seed0) =>
665-
new R[LazyList[T]] {
666-
val result: Option[LazyList[T]] = Some(unfold(seed0)(s => Some(g.pureApply(p, s) -> s.next)))
666+
new R[Stream[T]] {
667+
val result: Option[Stream[T]] = Some(unfold(seed0)(s => Some(g.pureApply(p, s) -> s.next)))
667668
val seed: Seed = seed0.next
668669
}
669670
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import language.reflectiveCalls
1515
import rng.Seed
1616
import util.{Pretty, ConsoleReporter}
1717
import scala.annotation.tailrec
18+
import ScalaVersionSpecific._
1819

1920
/** Helper class to satisfy ScalaJS compilation. Do not use this directly,
2021
* use `Prop.apply` instead. */

0 commit comments

Comments
 (0)