Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to compile with Scala 2.13.0-M4 #411

Closed
wants to merge 10 commits into from
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ scala:
- 2.10.7
- 2.11.12
- 2.12.6
- 2.13.0-M3
- 2.13.0-M4
jdk:
- oraclejdk8
env:
Expand All @@ -38,6 +38,9 @@ matrix:
before_script:
- curl https://raw.githubusercontent.com/scala-native/scala-native/master/scripts/travis_setup.sh | bash -x
sudo: required
addons:
apt:
update: true # https://github.com/rickynils/scalacheck/issues/412
env: PLATFORM=native SBT_PARALLEL=true WORKERS=1 DEPLOY=true
- env: EXAMPLES
script:
Expand All @@ -46,3 +49,5 @@ matrix:
exclude:
- scala: 2.10.7
env: PLATFORM=js SBT_PARALLEL=true WORKERS=1 DEPLOY=true SCALAJS_VERSION=1.0.0-M3
- scala: 2.13.0-M4
env: PLATFORM=js SBT_PARALLEL=true WORKERS=1 DEPLOY=true SCALAJS_VERSION=1.0.0-M3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exclude doesn't make sense like this anymore since the change from scala 2.13.0-M3 to 2.13.0-M4, right?

Copy link
Contributor Author

@lrytz lrytz May 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand.. This exclude skips building with Scala.js 1.0.0-M3 on Scala 2.13.0-M4, because there's no such Scala.js release yet.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A got it 👍

33 changes: 25 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
sourceDirectory := file("dummy source directory")

val scalaMajorVersion = SettingKey[Int]("scalaMajorVersion")

scalaVersionSettings

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

lazy val scalaVersionSettings = Seq(
scalaVersion := "2.12.6",
crossScalaVersions := Seq("2.10.7", "2.11.12", "2.13.0-M3", scalaVersion.value)
crossScalaVersions := Seq("2.10.7", "2.11.12", "2.13.0-M4", scalaVersion.value),
scalaMajorVersion := {
val v = scalaVersion.value
CrossVersion.partialVersion(v).map(_._2.toInt).getOrElse {
throw new RuntimeException(s"could not get Scala major version from $v")
}
}
)

lazy val sharedSettings = MimaSettings.settings ++ scalaVersionSettings ++ Seq(
Expand Down Expand Up @@ -43,6 +51,11 @@ lazy val sharedSettings = MimaSettings.settings ++ scalaVersionSettings ++ Seq(

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

unmanagedSourceDirectories in Compile += {
val s = if (scalaMajorVersion.value >= 13) "+" else "-"
(baseDirectory in LocalRootProject).value / "src" / "main" / s"scala-2.13$s"
},

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

resolvers += "sonatype" at "https://oss.sonatype.org/content/repositories/releases",
Expand All @@ -54,18 +67,18 @@ lazy val sharedSettings = MimaSettings.settings ++ scalaVersionSettings ++ Seq(
"-encoding", "UTF-8",
"-feature",
"-unchecked",
"-Xfatal-warnings",
"-Xfuture",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-inaccessible",
"-Ywarn-nullary-override",
"-Ywarn-nullary-unit",
"-Ywarn-numeric-widen") ++ {
scalaBinaryVersion.value match {
case "2.10" => Seq("-Xlint")
case "2.11" => Seq("-Xlint", "-Ywarn-infer-any", "-Ywarn-unused-import")
case _ => Seq("-Xlint:-unused", "-Ywarn-infer-any", "-Ywarn-unused-import", "-Ywarn-unused:-patvars,-implicits,-locals,-privates,-explicits")
val modern = Seq("-Xlint:-unused", "-Ywarn-infer-any", "-Ywarn-unused-import", "-Ywarn-unused:-patvars,-implicits,-locals,-privates,-explicits")
scalaMajorVersion.value match {
case 10 => Seq("-Xfatal-warnings", "-Xlint")
case 11 => Seq("-Xfatal-warnings", "-Xlint", "-Ywarn-infer-any", "-Ywarn-unused-import")
case 12 => "-Xfatal-warnings" +: modern
case 13 => modern
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it mean 2.13 enables -Xfatal-warnings by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No :-) this disables fatal warnings on 2.13 because there are some deprecation warnings due to cross-building (usage of Stream)

Copy link

@jozic jozic Jul 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, one alternative way could be to add silencer for that particular place instead of disabling it in general, but I guess it's not a big deal, as it's enabled for the rest of versions

}
},

Expand All @@ -78,7 +91,11 @@ lazy val sharedSettings = MimaSettings.settings ++ scalaVersionSettings ++ Seq(
// don't use fatal warnings in tests
scalacOptions in Test ~= (_ filterNot (_ == "-Xfatal-warnings")),

mimaPreviousArtifacts := Set("org.scalacheck" %% "scalacheck" % "1.14.0"),
mimaPreviousArtifacts := {
// TODO: re-enable MiMa for 2.13.0-M4 once there is a release out
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a ticket to keep track of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment #410 (comment)

if (scalaMajorVersion.value == 13) Set()
else Set("org.scalacheck" %% "scalacheck" % "1.14.0")
},

publishTo := {
val nexus = "https://oss.sonatype.org/"
Expand Down
20 changes: 10 additions & 10 deletions doc/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,17 +471,17 @@ responsible for generating the individual items. You can use it in the
following way:

```scala
val genIntList = Gen.containerOf[List,Int](Gen.oneOf(1, 3, 5))
val genIntList = Gen.containerOf[List,Int](Gen.oneOf(1, 3, 5))

val genStringStream = Gen.containerOf[Stream,String](Gen.alphaStr)
val genStringLazyList = Gen.containerOf[LazyList,String](Gen.alphaStr)

val genBoolArray = Gen.containerOf[Array,Boolean](true)
val genBoolArray = Gen.containerOf[Array,Boolean](true)
```

By default, ScalaCheck supports generation of `List`, `Stream`, `Set`, `Array`,
and `ArrayList` (from `java.util`). You can add support for additional
containers by adding implicit `Buildable` instances. See `Buildable.scala` for
examples.
By default, ScalaCheck supports generation of `List`, `Stream` (Scala 2.10 -
2.12, deprecated in 2.13), `LazyList` (Scala 2.13), `Set`, `Array`, and
`ArrayList` (from `java.util`). You can add support for additional containers
by adding implicit `Buildable` instances. See `Buildable.scala` for examples.

There is also `Gen.nonEmptyContainerOf` for generating non-empty containers, and
`Gen.containerOfN` for generating containers of a given size.
Expand Down Expand Up @@ -778,9 +778,9 @@ can also define default shrinking methods. This is done by defining an implicit
method that returns a `Shrink[T]` instance. This is done by using the
`Shrink(...)` factory method, which as its only parameter takes a function and
returns an instance of `Shrink[T]`. In turn, the function should take a value
of the given type `T`, and return a `Stream` of shrank variants of the given
value. As an example, look at the implicit `Shrink` instance for a tuple as it
is defined in ScalaCheck:
of the given type `T`, and return a `Stream` (`LazyList` on Scala 2.13) of shrank
variants of the given value. As an example, look at the implicit `Shrink` instance
for a tuple as it is defined in ScalaCheck:

```scala
/** Shrink instance of 2-tuple */
Expand Down
3 changes: 3 additions & 0 deletions jvm/src/test/scala/org/scalacheck/CogenSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import org.scalacheck.Gen.listOfN
import org.scalacheck.GenSpecification.arbSeed
import org.scalacheck.Prop.forAll
import org.scalacheck.rng.Seed
import ScalaVersionSpecific._


import scala.util.Try
import scala.concurrent.duration.{Duration, FiniteDuration}
Expand Down Expand Up @@ -141,6 +143,7 @@ object CogenSpecification extends Properties("Cogen") {
include(cogenLaws[List[Int]], "cogenList.")
include(cogenLaws[Vector[Int]], "cogenVector.")
include(cogenLaws[Stream[Int]], "cogenStream.")
include(cogenLaws[LazyList[Int]], "cogenLazyList.")
include(cogenLaws[Set[Int]], "cogenSet.")
include(cogenLaws[Map[Int, Int]], "cogenMap.")
include(cogenLaws[() => Int], "cogenFunction0.")
Expand Down
8 changes: 6 additions & 2 deletions jvm/src/test/scala/org/scalacheck/GenSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Shrink._
import java.util.Date
import scala.util.{Try, Success, Failure}

object GenSpecification extends Properties("Gen") {
object GenSpecification extends Properties("Gen") with GenSpecificationVersionSpecific {

implicit val arbSeed: Arbitrary[Seed] = Arbitrary(
arbitrary[Long] flatMap Seed.apply
Expand Down Expand Up @@ -183,6 +183,10 @@ object GenSpecification extends Properties("Gen") {
s.drop(n & 0xffff).nonEmpty
}

property("infiniteLazyList") = forAll(infiniteLazyList(arbitrary[Int]), arbitrary[Short]) { (s, n) =>
s.drop(n & 0xffff).nonEmpty
}

property("someOf") = forAll { l: List[Int] =>
forAll(someOf(l))(_.toList.forall(l.contains))
}
Expand All @@ -201,7 +205,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 @@ -26,17 +26,17 @@ object PropertyFilterSpecification extends Properties("PropertyFilter") {

val nl = System.lineSeparator

private def diff(filter: Option[String], actual: Seq[String],
expected: Seq[String]): String = {
private def diff(filter: Option[String], actual: collection.Seq[String],
expected: collection.Seq[String]): String = {
s"filter: ${filter.getOrElse("not supplied")}" +
s"${nl}expected values:$nl" +
s"\t${expected.mkString(s"$nl\t")}" +
s"${nl}actual values:$nl" +
s"\t${actual.mkString(s"$nl\t")}"
}

private def prop(filter: Option[String], actualNames: Seq[String],
expectedNames: Seq[String]): Prop = {
private def prop(filter: Option[String], actualNames: collection.Seq[String],
expectedNames: collection.Seq[String]): Prop = {
def lengthProp = actualNames.length == expectedNames.length

def props = actualNames.forall(expectedNames.contains)
Expand Down
2 changes: 1 addition & 1 deletion project/plugin.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.2.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1")

val scalaJSVersion =
Option(System.getenv("SCALAJS_VERSION")).getOrElse("0.6.22")
Option(System.getenv("SCALAJS_VERSION")).getOrElse("0.6.23")

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

Expand Down
40 changes: 40 additions & 0 deletions src/main/scala-2.13+/org/scalacheck/ScalaVersionSpecific.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*-------------------------------------------------------------------------*\
** ScalaCheck **
** Copyright (c) 2007-2018 Rickard Nilsson. All rights reserved. **
** http://www.scalacheck.org **
** **
** This software is released under the terms of the Revised BSD License. **
** There is NO WARRANTY. See the file LICENSE for the full text. **
\*------------------------------------------------------------------------ */

package org.scalacheck

import rng.Seed

private[scalacheck] object ScalaVersionSpecific {
def toLazyList[T](i: IterableOnce[T]) = LazyList.from(i)
}

private[scalacheck] trait GenVersionSpecific {

/** Generates an infinite lazy list. */
def infiniteLazyList[T](g: => Gen[T]): Gen[LazyList[T]] = {
def unfold[A, S](z: S)(f: S => Option[(A, S)]): LazyList[A] = f(z) match {
case Some((h, s)) => h #:: unfold(s)(f)
case None => LazyList.empty
}
Gen.gen { (p, seed0) =>
new Gen.R[LazyList[T]] {
val result: Option[LazyList[T]] = Some(unfold(seed0)(s => Some(g.pureApply(p, s) -> s.next)))
val seed: Seed = seed0.next
}
}
}
}

private[scalacheck] trait GenSpecificationVersionSpecific

private[scalacheck] trait CogenVersionSpecific {
implicit def cogenLazyList[A: Cogen]: Cogen[LazyList[A]] =
Cogen.it(_.iterator)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*-------------------------------------------------------------------------*\
** ScalaCheck **
** Copyright (c) 2007-2018 Rickard Nilsson. All rights reserved. **
** http://www.scalacheck.org **
** **
** This software is released under the terms of the Revised BSD License. **
** There is NO WARRANTY. See the file LICENSE for the full text. **
\*------------------------------------------------------------------------ */

package org.scalacheck.util

import java.util.ArrayList

import collection.{Map => _, _}
import scala.collection.mutable.Builder


private[util] trait BuildableVersionSpecific {
implicit def buildableFactory[T,C](implicit f: Factory[T,C]) =
new Buildable[T,C] {
def builder = f.newBuilder
}
}

private[util] class ArrayListBuilder[T] extends Builder[T, ArrayList[T]] {
private val al = new ArrayList[T]
def addOne(x: T): this.type = {
al.add(x)
this
}
def clear(): Unit = al.clear()
def result(): ArrayList[T] = al
}

/**
* Factory instances implementing Serializable, so that the objects capturing those can be
* serializable too.
*/
// Named `...CanBuildFroms` for 2.12 source compatibility (`import SerializableCanBuildFroms._`)
// Can be renamed to `SerializableFactories` in a major release.
object SerializableCanBuildFroms {
implicit def listFactory[T]: Factory[T, List[T]] =
new Factory[T, List[T]] with Serializable {
def fromSpecific(source: IterableOnce[T]): List[T] = List.from(source)
def newBuilder: Builder[T, List[T]] = List.newBuilder[T]
}

implicit def bitsetFactory[T]: Factory[Int, BitSet] =
new Factory[Int, BitSet] with Serializable {
def fromSpecific(source: IterableOnce[Int]) = BitSet.fromSpecific(source)
def newBuilder: Builder[Int, BitSet] = BitSet.newBuilder
}

implicit def mapFactory[T, U]: Factory[(T, U), Map[T, U]] =
new Factory[(T, U), Map[T, U]] with Serializable {
def fromSpecific(source: IterableOnce[(T, U)]) = Map.from(source)
def newBuilder: Builder[(T, U), Map[T, U]] = Map.newBuilder[T, U]
}
}
39 changes: 39 additions & 0 deletions src/main/scala-2.13-/org/scalacheck/ScalaVersionSpecific.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*-------------------------------------------------------------------------*\
** ScalaCheck **
** Copyright (c) 2007-2018 Rickard Nilsson. All rights reserved. **
** http://www.scalacheck.org **
** **
** This software is released under the terms of the Revised BSD License. **
** There is NO WARRANTY. See the file LICENSE for the full text. **
\*------------------------------------------------------------------------ */

package org.scalacheck

import scala.collection.generic.Sorted
import scala.collection.immutable.Stream
import scala.collection.TraversableOnce

private[scalacheck] object ScalaVersionSpecific {
def toLazyList[T](i: TraversableOnce[T]) = i.toStream

type LazyList[+A] = Stream[A]
val LazyList = Stream

implicit class StreamExt[+A](val s: Stream[A]) extends AnyVal {
def lazyAppendedAll[B >: A](rest: => TraversableOnce[B]): Stream[B] = s.append(rest)
}

implicit class SortedExt[K, T <: Sorted[K, T]](val s: Sorted[K, T]) extends AnyVal {
def rangeFrom(from: K): T = s.from(from)
def rangeTo(to: K): T = s.to(to)
def rangeUntil(until: K): T = s.until(until)
}
}

private[scalacheck] trait GenVersionSpecific
private[scalacheck] trait CogenVersionSpecific

// Used in tests
private[scalacheck] trait GenSpecificationVersionSpecific {
def infiniteLazyList[T](g: => Gen[T]): Gen[Stream[T]] = Gen.infiniteStream(g)
}
Loading