Skip to content

Commit

Permalink
Add support for Scala 2.13-M4
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrf committed Mar 29, 2018
1 parent 0a2f1c5 commit b3e8a37
Show file tree
Hide file tree
Showing 20 changed files with 159 additions and 110 deletions.
19 changes: 17 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sbt.CrossVersion

sourceDirectory := file("dummy source directory")

scalaVersionSettings
Expand All @@ -11,7 +13,9 @@ lazy val travisCommit = Option(System.getenv().get("TRAVIS_COMMIT"))

lazy val scalaVersionSettings = Seq(
scalaVersion := "2.12.3",
crossScalaVersions := Seq("2.10.6", "2.11.11", "2.13.0-M3", scalaVersion.value)
// Temporary: we will eventually use 2.13.0-M4, which will be published to maven central
resolvers += "scala-pr" at "https://scala-ci.typesafe.com/artifactory/scala-integration/",
crossScalaVersions := Seq("2.10.6", "2.11.11", "2.13.0-pre-c577876", scalaVersion.value)
)

lazy val sharedSettings = MimaSettings.settings ++ scalaVersionSettings ++ Seq(
Expand Down Expand Up @@ -46,6 +50,17 @@ lazy val sharedSettings = MimaSettings.settings ++ scalaVersionSettings ++ Seq(

unmanagedSourceDirectories in Test += (baseDirectory in LocalRootProject).value / "src" / "test" / "scala",

unmanagedSourceDirectories in Compile ++= {
(unmanagedSourceDirectories in Compile).value.map { dir =>
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => file(dir.getPath ++ "-2.13")
case _ => file(dir.getPath ++ "-2.10-2.12")
}
}
},

libraryDependencies += "org.scala-lang" %% "scala-collection-compat" % "0.1-SNAPSHOT",

resolvers += "sonatype" at "https://oss.sonatype.org/content/repositories/releases",

javacOptions += "-Xmx1024M",
Expand All @@ -55,7 +70,7 @@ lazy val sharedSettings = MimaSettings.settings ++ scalaVersionSettings ++ Seq(
"-encoding", "UTF-8",
"-feature",
"-unchecked",
"-Xfatal-warnings",
//"-Xfatal-warnings", Disabled because “import scala.collection.compat._” causes “Unused import” warnings on 2.13.
"-Xfuture",
"-Yno-adapted-args",
"-Ywarn-dead-code",
Expand Down
8 changes: 4 additions & 4 deletions doc/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -873,15 +873,15 @@ object CounterSpecification extends Commands {
* (a singleton [[Sut]]), implement this method the following way:
*
* {{{
* def canCreateNewSut(newState: State, initSuts: Traversable[State]
* runningSuts: Traversable[Sut]
* def canCreateNewSut(newState: State, initSuts: Iterable[State]
* runningSuts: Iterable[Sut]
* ) = {
* initSuts.isEmpty && runningSuts.isEmpty
* }
* }}}
*/
def canCreateNewSut(newState: State, initSuts: Traversable[State],
runningSuts: Traversable[Sut]): Boolean = true
def canCreateNewSut(newState: State, initSuts: Iterable[State],
runningSuts: Iterable[Sut]): Boolean = true

/** The precondition for the initial state, when no commands yet have
* run. This is used by ScalaCheck when command sequences are shrinked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ object LevelDBSpec extends Commands {
def path = s"db_$name"
}

def canCreateNewSut(newState: State, initSuts: Traversable[State],
runningSuts: Traversable[Sut]
def canCreateNewSut(newState: State, initSuts: Iterable[State],
runningSuts: Iterable[Sut]
) = {
!initSuts.exists(_.name == newState.name) &&
!runningSuts.exists(_.name == newState.name)
Expand Down
4 changes: 2 additions & 2 deletions examples/commands-nix/src/test/scala/CommandsNix.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ object MachineSpec extends Commands {
type Sut = Map[String, org.libvirt.Domain]

// TODO we should check for example total amount of memory used here
def canCreateNewSut(newState: State, initSuts: Traversable[State],
runningSuts: Traversable[Sut]
def canCreateNewSut(newState: State, initSuts: Iterable[State],
runningSuts: Iterable[Sut]
): Boolean = true

def newSut(state: State): Sut = {
Expand Down
4 changes: 2 additions & 2 deletions examples/commands-redis/src/test/scala/CommandsRedis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ object RedisSpec extends Commands {
connected: Boolean
)

def canCreateNewSut(newState: State, initSuts: Traversable[State],
runningSuts: Traversable[Sut]
def canCreateNewSut(newState: State, initSuts: Iterable[State],
runningSuts: Iterable[Sut]
): Boolean = {
initSuts.isEmpty && runningSuts.isEmpty
}
Expand Down
2 changes: 1 addition & 1 deletion jvm/src/test/scala/org/scalacheck/GenSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ object GenSpecification extends Properties("Gen") {
property("distributed pick") = {
val lst = (0 to 7).toIterable
val n = 2
forAll(pick(n, lst)) { xs: Seq[Int] =>
forAll(pick(n, lst)) { xs: collection.Seq[Int] =>
xs.map { x: Int =>
Prop.collect(x) {
xs.size == n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ object CommandsSpecification extends Properties("Commands") {

override def shrinkState: Shrink[Int] = implicitly

def canCreateNewSut(newState: State, initSuts: Traversable[State],
runningSuts: Traversable[Sut]) = true
def canCreateNewSut(newState: State, initSuts: Iterable[State],
runningSuts: Iterable[Sut]) = true

def newSut(state: State): Sut = Counter(state)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.scalacheck.util

import java.util
import java.util.ArrayList

import scala.collection.mutable

private[scalacheck] class ArrayListBuilder[T]
extends mutable.Builder[T, util.ArrayList[T]] {
val al = new ArrayList[T]
def +=(x: T) = {
al.add(x)
this
}
def clear() = al.clear()
def result() = al
}
17 changes: 17 additions & 0 deletions src/main/scala-2.13/org/scalacheck/util/ArrayListBuilder.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.scalacheck.util

import java.util
import java.util.ArrayList

import scala.collection.mutable

private[scalacheck] class ArrayListBuilder[T]
extends mutable.Builder[T, util.ArrayList[T]] {
val al = new ArrayList[T]
def addOne(x: T) = {
al.add(x)
this
}
def clear() = al.clear()
def result() = al
}
4 changes: 2 additions & 2 deletions src/main/scala/org/scalacheck/Arbitrary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,14 @@ private[scalacheck] sealed trait ArbitraryLowPriority {
* (such as lists, arrays, streams, etc). The maximum size of the container
* depends on the size generation parameter. */
implicit def arbContainer[C[_],T](implicit
a: Arbitrary[T], b: Buildable[T,C[T]], t: C[T] => Traversable[T]
a: Arbitrary[T], b: Buildable[T,C[T]], t: C[T] => Iterable[T]
): Arbitrary[C[T]] = Arbitrary(buildableOf[C[T],T](arbitrary[T]))

/** Arbitrary instance of any [[org.scalacheck.util.Buildable]] container
* (such as maps). The maximum size of the container depends on the size
* generation parameter. */
implicit def arbContainer2[C[_,_],T,U](implicit
a: Arbitrary[(T,U)], b: Buildable[(T,U),C[T,U]], t: C[T,U] => Traversable[(T,U)]
a: Arbitrary[(T,U)], b: Buildable[(T,U),C[T,U]], t: C[T,U] => Iterable[(T,U)]
): Arbitrary[C[T,U]] = Arbitrary(buildableOf[C[T,U],(T,U)](arbitrary[(T,U)]))

implicit def arbEnum[A <: java.lang.Enum[A]](implicit A: reflect.ClassTag[A]): Arbitrary[A] = {
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/org/scalacheck/Cogen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import scala.concurrent.duration.{Duration, FiniteDuration}
import java.math.BigInteger
import rng.Seed

import scala.collection.compat._

sealed trait Cogen[T] extends Serializable {

def perturb(seed: Seed, t: T): Seed
Expand Down Expand Up @@ -115,7 +117,7 @@ object Cogen extends CogenArities with CogenLowPriority {
Cogen[String].contramap(_.name)

implicit def cogenList[A: Cogen]: Cogen[List[A]] =
Cogen.it(_.iterator)
Cogen.it(_.iterator())

implicit def cogenVector[A: Cogen]: Cogen[Vector[A]] =
Cogen.it(_.iterator)
Expand Down
24 changes: 12 additions & 12 deletions src/main/scala/org/scalacheck/Gen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ object Gen extends GenArities{

/** Sequences generators. If any of the given generators fails, the
* resulting generator will also fail. */
def sequence[C,T](gs: Traversable[Gen[T]])(implicit b: Buildable[T,C]): Gen[C] = {
def sequence[C,T](gs: Iterable[Gen[T]])(implicit b: Buildable[T,C]): Gen[C] = {
val g = gen { (p, seed) =>
gs.foldLeft(r(Some(Vector.empty[T]), seed)) {
case (rs,g) =>
Expand Down Expand Up @@ -595,55 +595,55 @@ object Gen extends GenArities{

//// List Generators ////

/** Generates a container of any Traversable type for which there exists an
/** Generates a container of any Iterable type for which there exists an
* implicit [[org.scalacheck.util.Buildable]] instance. The elements in the
* container will be generated by the given generator. The size of the
* generated container is limited by `n`. Depending on what kind of container
* that is generated, the resulting container may contain fewer elements than
* `n`, but not more. If the given generator fails generating a value, the
* complete container generator will also fail. */
def buildableOfN[C,T](n: Int, g: Gen[T])(implicit
evb: Buildable[T,C], evt: C => Traversable[T]
evb: Buildable[T,C], evt: C => Iterable[T]
): Gen[C] =
sequence[C,T](Traversable.fill(n)(g)) suchThat { c =>
sequence[C,T](Iterable.fill(n)(g)) suchThat { c =>
// TODO: Can we guarantee c.size == n (See issue #89)?
c.forall(g.sieveCopy)
}

/** Generates a container of any Traversable type for which there exists an
/** Generates a container of any Iterable type for which there exists an
* implicit [[org.scalacheck.util.Buildable]] instance. The elements in the
* container will be generated by the given generator. The size of the
* container is bounded by the size parameter used when generating values. */
def buildableOf[C,T](g: Gen[T])(implicit
evb: Buildable[T,C], evt: C => Traversable[T]
evb: Buildable[T,C], evt: C => Iterable[T]
): Gen[C] =
sized(s => choose(0, s max 0).flatMap(buildableOfN[C,T](_,g))) suchThat { c =>
if (c == null) g.sieveCopy(null) else c.forall(g.sieveCopy)
}

/** Generates a non-empty container of any Traversable type for which there
/** Generates a non-empty container of any Iterable type for which there
* exists an implicit [[org.scalacheck.util.Buildable]] instance. The
* elements in the container will be generated by the given generator. The
* size of the container is bounded by the size parameter used when
* generating values. */
def nonEmptyBuildableOf[C,T](g: Gen[T])(implicit
evb: Buildable[T,C], evt: C => Traversable[T]
evb: Buildable[T,C], evt: C => Iterable[T]
): Gen[C] =
sized(s => choose(1, s max 1).flatMap(buildableOfN[C,T](_,g))) suchThat(_.size > 0)

/** A convenience method for calling `buildableOfN[C[T],T](n,g)`. */
def containerOfN[C[_],T](n: Int, g: Gen[T])(implicit
evb: Buildable[T,C[T]], evt: C[T] => Traversable[T]
evb: Buildable[T,C[T]], evt: C[T] => Iterable[T]
): Gen[C[T]] = buildableOfN[C[T],T](n,g)

/** A convenience method for calling `buildableOf[C[T],T](g)`. */
def containerOf[C[_],T](g: Gen[T])(implicit
evb: Buildable[T,C[T]], evt: C[T] => Traversable[T]
evb: Buildable[T,C[T]], evt: C[T] => Iterable[T]
): Gen[C[T]] = buildableOf[C[T],T](g)

/** A convenience method for calling `nonEmptyBuildableOf[C[T],T](g)`. */
def nonEmptyContainerOf[C[_],T](g: Gen[T])(implicit
evb: Buildable[T,C[T]], evt: C[T] => Traversable[T]
evb: Buildable[T,C[T]], evt: C[T] => Iterable[T]
): Gen[C[T]] = nonEmptyBuildableOf[C[T],T](g)

/** Generates a list of random length. The maximum length depends on the
Expand Down Expand Up @@ -706,7 +706,7 @@ object Gen extends GenArities{
choose(1, gs.length+2).flatMap(pick(_, g1, g2, gs: _*))

/** A generator that picks a given number of elements from a list, randomly */
def pick[T](n: Int, l: Iterable[T]): Gen[Seq[T]] = {
def pick[T](n: Int, l: Iterable[T]): Gen[collection.Seq[T]] = {
if (n > l.size || n < 0) throw new IllegalArgumentException(s"invalid choice: $n")
else if (n == 0) Gen.const(Nil)
else gen { (p, seed0) =>
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/scalacheck/Properties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Properties(val name: String) {

/** Returns all properties of this collection in a list of name/property
* pairs. */
def properties: Seq[(String,Prop)] = props
def properties: collection.Seq[(String,Prop)] = props

/** Convenience method that checks the properties with the given parameters
* (or default parameters, if not specified)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/scalacheck/ScalaCheckFramework.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private abstract class ScalaCheckRunner extends Runner {
abstract class BaseTask(override val taskDef: TaskDef) extends Task {
val tags: Array[String] = Array()

val props: Seq[(String,Prop)] = {
val props: collection.Seq[(String,Prop)] = {
val fp = taskDef.fingerprint.asInstanceOf[SubclassFingerprint]
val obj = if (fp.isModule) Platform.loadModule(taskDef.fullyQualifiedName,loader)
else Platform.newInstance(taskDef.fullyQualifiedName, loader, Seq())(Seq())
Expand Down
Loading

0 comments on commit b3e8a37

Please sign in to comment.