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 scalacheck to cross compile with Dotty #423

Merged
merged 9 commits into from
Aug 28, 2019
2 changes: 1 addition & 1 deletion jvm/src/main/scala/org/scalacheck/Platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private[scalacheck] object Platform {
else {
import concurrent._
val tp = java.util.concurrent.Executors.newFixedThreadPool(workers)
implicit val ec = ExecutionContext.fromExecutor(tp)
implicit val ec: ExecutionContextExecutor = ExecutionContext.fromExecutor(tp)
try {
val fs = List.range(0,workers) map (idx => Future {
params.customClassLoader.map(
Expand Down
6 changes: 3 additions & 3 deletions jvm/src/test/scala/org/scalacheck/CogenSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ object CogenSpecification extends Properties("Cogen") {
}

// Two exceptions are equal if they have the same string representation.
implicit val exceptionEqual = new Equal[Exception] {
implicit val exceptionEqual: Equal[Exception] = new Equal[Exception] {
override def equal(a1: Exception, a2: Exception): Boolean =
a1.toString == a2.toString
}

// Two throwables are equal if they have the same string representation.
implicit val throwableEqual = new Equal[Throwable] {
implicit val throwableEqual: Equal[Throwable] = new Equal[Throwable] {
override def equal(a1: Throwable, a2: Throwable): Boolean =
a1.toString == a2.toString
}
Expand All @@ -57,7 +57,7 @@ object CogenSpecification extends Properties("Cogen") {

// Avoid reimplementing equality for other standard classes.
trait EqualLowPriority {
implicit def universal[A] = new Equal[A] {
implicit def universal[A]: Equal[A] = new Equal[A] {
override def equal(a1: A, a2: A): Boolean = a1 == a2
}
}
Expand Down
7 changes: 3 additions & 4 deletions jvm/src/test/scala/org/scalacheck/GenSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ object GenSpecification extends Properties("Gen") with GenSpecificationVersionSp

property("resultOf3") = {
case class B(n: Int, s: String, b: Boolean)
implicit val arbB = Arbitrary(resultOf(B))
implicit val arbB: Arbitrary[B] = Arbitrary(resultOf(B))
forAll { b:B => true }
}

Expand Down Expand Up @@ -422,9 +422,8 @@ object GenSpecification extends Properties("Gen") with GenSpecificationVersionSp
i21:Int,i22:Int
)

property("22 field case class works") = forAll(Gen.resultOf(Full22.tupled)){
Full22.unapply(_).get.isInstanceOf[Tuple22[_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_]]
}
property("22 field case class works") =
forAll(Gen.resultOf(Full22.tupled)) { _ => true }

type Trilean = Either[Unit, Boolean]

Expand Down
7 changes: 6 additions & 1 deletion project/MimaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ object MimaSettings {
)

private def removedPrivateMethods = Seq(
// lazy val cmdLineParser is now an object
"org.scalacheck.Test.cmdLineParser"
)

private def removedPrivateClasses = Seq(
)

private def otherProblems = Seq(
// New issue added in MiMa 0.4.0
exclude[IncompatibleSignatureProblem]("org.scalacheck.*")
exclude[IncompatibleSignatureProblem]("org.scalacheck.*"),
// Work around weird mima error after cmdLineParser was turned from a lazy
// val into an object.
exclude[InaccessibleMethodProblem]("java.lang.Object.<clinit>"),
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import generic.CanBuildFrom
import scala.collection.mutable.Builder

private[util] trait BuildableVersionSpecific {
implicit def buildableCanBuildFrom[T,F,C](implicit c: CanBuildFrom[F,T,C]) =
implicit def buildableCanBuildFrom[T,F,C](implicit c: CanBuildFrom[F,T,C]): Buildable[T,C] =
new Buildable[T,C] {
def builder = c.apply
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/scalacheck/Arbitrary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import util.SerializableCanBuildFroms._


sealed abstract class Arbitrary[T] extends Serializable {
val arbitrary: Gen[T]
def arbitrary: Gen[T]
}

/** Defines implicit [[org.scalacheck.Arbitrary]] instances for common types.
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/org/scalacheck/Gen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ object Gen extends GenArities with GenVersionSpecific {
): Gen[C] =
sequence[C,T](Traversable.fill(n)(g)) suchThat { c =>
// TODO: Can we guarantee c.size == n (See issue #89)?
c.forall(g.sieveCopy)
evt(c).forall(g.sieveCopy)
}

/** Generates a container of any Traversable type for which there exists an
Expand All @@ -610,7 +610,7 @@ object Gen extends GenArities with GenVersionSpecific {
evb: Buildable[T,C], evt: C => Traversable[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)
if (c == null) g.sieveCopy(null) else evt(c).forall(g.sieveCopy)
}

/** Generates a non-empty container of any Traversable type for which there
Expand All @@ -621,7 +621,7 @@ object Gen extends GenArities with GenVersionSpecific {
def nonEmptyBuildableOf[C,T](g: Gen[T])(implicit
evb: Buildable[T,C], evt: C => Traversable[T]
): Gen[C] =
sized(s => choose(1, s max 1).flatMap(buildableOfN[C,T](_,g))) suchThat(_.size > 0)
sized(s => choose(1, s max 1).flatMap(buildableOfN[C,T](_,g))) suchThat(c => evt(c).size > 0)

/** A convenience method for calling `buildableOfN[C[T],T](n,g)`. */
def containerOfN[C[_],T](n: Int, g: Gen[T])(implicit
Expand Down
13 changes: 6 additions & 7 deletions src/main/scala/org/scalacheck/Prop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package org.scalacheck

import language.implicitConversions
import language.reflectiveCalls

import rng.Seed
import util.{Pretty, ConsoleReporter}
Expand Down Expand Up @@ -100,14 +99,14 @@ sealed abstract class Prop extends Serializable { self =>
* as an application that checks itself on execution. Calls `System.exit`
* with a non-zero exit code if the property check fails. */
def main(args: Array[String]): Unit = {
val ret = Test.cmdLineParser.parseParams(args) match {
val ret = Test.CmdLineParser.parseParams(args) match {
case (applyCmdParams, Nil) =>
val params = applyCmdParams(Test.Parameters.default)
if (Test.check(params, this).passed) 0
else 1
case (_, os) =>
println(s"Incorrect options: $os")
Test.cmdLineParser.printHelp
Test.CmdLineParser.printHelp()
-1
}
if (ret != 0) System.exit(ret)
Expand Down Expand Up @@ -350,13 +349,13 @@ object Prop {
/** Implicit method that makes a number of property operators on values of
* type `Any` available in the current scope.
* See [[Prop.ExtendedAny]] for documentation on the operators. */
implicit def AnyOperators[T](x: => T)(implicit ev: T => Pretty) = new ExtendedAny[T](x)
implicit def AnyOperators[T](x: => T)(implicit ev: T => Pretty): ExtendedAny[T] = new ExtendedAny[T](x)

/** Implicit method that makes a number of property operators on boolean
* values available in the current scope. See [[Prop.ExtendedBoolean]] for
* documentation on the operators. */
@deprecated("Please import Prop.propBoolean instead", since="1.14.1")
implicit def BooleanOperators(b: => Boolean) = new ExtendedBoolean(b)
implicit def BooleanOperators(b: => Boolean): ExtendedBoolean = new ExtendedBoolean(b)

/** Implicit conversion of Boolean values to Prop values. */
implicit def propBoolean(b: Boolean): Prop = Prop(b)
Expand Down Expand Up @@ -451,7 +450,7 @@ object Prop {

/** Collect data for presentation in test report */
def collect[T, P](f: T => P)(implicit ev: P => Prop): T => Prop = t => Prop { prms =>
val prop = f(t)
val prop = ev(f(t))
prop(prms).collect(t)
}

Expand All @@ -471,7 +470,7 @@ object Prop {
/** Wraps and protects a property, turning exceptions thrown
* by the property into test failures. */
def secure[P](p: => P)(implicit ev: P => Prop): Prop =
try (p: Prop) catch { case e: Throwable => exception(e) }
try ev(p) catch { case e: Throwable => exception(e) }

/** Wraps a property to delay its evaluation. The given parameter is
* evaluated each time the wrapper property is evaluated. */
Expand Down
6 changes: 2 additions & 4 deletions src/main/scala/org/scalacheck/Properties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ package org.scalacheck

import org.scalacheck.rng.Seed

import language.reflectiveCalls

import util.ConsoleReporter

/** Represents a collection of properties, with convenient methods
Expand Down Expand Up @@ -61,7 +59,7 @@ class Properties(val name: String) {
* as an application that checks itself on execution. Calls `System.exit`
* with the exit code set to the number of failed properties. */
def main(args: Array[String]): Unit =
Test.cmdLineParser.parseParams(args) match {
Test.CmdLineParser.parseParams(args) match {
case (applyCmdParams, Nil) =>
val params = applyCmdParams(overrideParameters(Test.Parameters.default))
val res = Test.checkProperties(params, this)
Expand All @@ -74,7 +72,7 @@ class Properties(val name: String) {
}
case (_, os) =>
println(s"Incorrect options: $os")
Test.cmdLineParser.printHelp
Test.CmdLineParser.printHelp()
System.exit(-1)
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/scala/org/scalacheck/ScalaCheckFramework.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package org.scalacheck

import sbt.testing._
import scala.language.reflectiveCalls
import java.util.concurrent.atomic.AtomicInteger

import org.scalacheck.Test.Parameters
Expand Down Expand Up @@ -193,7 +192,7 @@ final class ScalaCheckFramework extends Framework {
val args = _args
val remoteArgs = _remoteArgs
val loader = _loader
val (prms,unknownArgs) = Test.cmdLineParser.parseParams(args)
val (prms,unknownArgs) = Test.CmdLineParser.parseParams(args)
val applyCmdParams = prms.andThen {
p => p.withTestCallback(new Test.TestCallback {})
.withCustomClassLoader(Some(loader))
Expand Down Expand Up @@ -225,7 +224,7 @@ final class ScalaCheckFramework extends Framework {
val args = _args
val remoteArgs = _remoteArgs
val loader = _loader
val applyCmdParams = Test.cmdLineParser.parseParams(args)._1.andThen {
val applyCmdParams = Test.CmdLineParser.parseParams(args)._1.andThen {
p => p.withTestCallback(new Test.TestCallback {})
.withCustomClassLoader(Some(loader))
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/scalacheck/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ object Test {
s"Invalid test parameter: workers (${prms.workers}) <= 0")
}

private[scalacheck] lazy val cmdLineParser = new CmdLineParser {
private[scalacheck] object CmdLineParser extends CmdLineParser {
object OptMinSuccess extends IntOpt {
val default = Parameters.default.minSuccessfulTests
val names = Set("minSuccessfulTests", "s")
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/org/scalacheck/commands/Commands.scala
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ trait Commands {
true
} else false
}
if (doRun) runActions(sut,as, removeSut)
if (doRun) runActions(sut,as, removeSut())
else {
removeSut
removeSut()
Prop.undecided
}

Expand Down Expand Up @@ -290,7 +290,7 @@ trait Commands {
): (Prop, List[List[(Command,Try[String])]]) = {
import concurrent._
val tp = java.util.concurrent.Executors.newFixedThreadPool(pcmds.size)
implicit val ec = ExecutionContext.fromExecutor(tp)
implicit val ec: ExecutionContextExecutor = ExecutionContext.fromExecutor(tp)
val memo = collection.mutable.Map.empty[(State,List[Commands]), List[State]]

def endStates(scss: (State, List[Commands])): List[State] = {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/scalacheck/util/FreqMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.scalacheck.ScalaVersionSpecific._

sealed trait FreqMap[T] extends Serializable {
protected val underlying: scala.collection.immutable.Map[T,Int]
val total: Int
def total: Int

def +(t: T): FreqMap[T] = new FreqMap[T] {
private val n = FreqMap.this.underlying.get(t) match {
Expand Down
20 changes: 10 additions & 10 deletions src/main/scala/org/scalacheck/util/Pretty.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object Pretty {
def apply(f: Params => String): Pretty = new Pretty { def apply(p: Params) = f(p) }

def pretty[T](t: T, prms: Params)(implicit ev: T => Pretty): String = {
val p = (t: Pretty) match {
val p = ev(t) match {
case null => prettyAny(null)
case p => p
}
Expand Down Expand Up @@ -106,22 +106,22 @@ object Pretty {
builder.result()
}

implicit def prettyAny(t: Any) = Pretty { p => toStrOrNull(t) }
implicit def prettyAny(t: Any): Pretty = Pretty { p => toStrOrNull(t) }

implicit def prettyString(t: String) = Pretty { p => "\""++escapeControlChars(t)++"\"" }
implicit def prettyString(t: String): Pretty = Pretty { p => "\""++escapeControlChars(t)++"\"" }

implicit def prettyList(l: List[Any]) = Pretty { p =>
implicit def prettyList(l: List[Any]): Pretty = Pretty { p =>
l.map("\""+_+"\"").mkString("List(", ", ", ")")
}

implicit def prettyThrowable(e: Throwable) = Pretty { prms =>
val strs = e.getStackTrace.map { st =>
implicit def prettyThrowable(e: Throwable): Pretty = Pretty { prms =>
val strs = e.getStackTrace.toList.map { st =>
import st._
getClassName+"."+getMethodName + "("+getFileName+":"+getLineNumber+")"
}

val strs2 =
if(prms.verbosity <= 0) Array[String]()
if(prms.verbosity <= 0) List[String]()
else if(prms.verbosity <= 1) strs.take(5)
else strs

Expand All @@ -140,7 +140,7 @@ object Pretty {
}.mkString("\n")
}

implicit def prettyFreqMap(fm: FreqMap[Set[Any]]) = Pretty { prms =>
implicit def prettyFreqMap(fm: FreqMap[Set[Any]]): Pretty = Pretty { prms =>
if(fm.total == 0) ""
else {
"> Collected test data: " / {
Expand All @@ -153,7 +153,7 @@ object Pretty {
}
}

implicit def prettyTestRes(res: Test.Result) = Pretty { prms =>
implicit def prettyTestRes(res: Test.Result): Pretty = Pretty { prms =>
def labels(ls: collection.immutable.Set[String]) =
if(ls.isEmpty) ""
else "> Labels of failing property: " / ls.mkString("\n")
Expand All @@ -180,7 +180,7 @@ object Pretty {
else "%d min %.3f sec ".format(min, sec)
}

implicit def prettyTestParams(prms: Test.Parameters) = Pretty { p =>
implicit def prettyTestParams(prms: Test.Parameters): Pretty = Pretty { p =>
prms.toString
}
}
4 changes: 2 additions & 2 deletions src/test/scala/org/scalacheck/PropSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ object PropSpecification extends Properties("Prop") {
forAll(g,g) { case (p1,p2) => (p1 && p2) == (p2 && p1) }
}
property("Prop.&& Exception") = forAll { p: Prop =>
(p && propException) == exception
(p && propException()) == exception
}
property("Prop.&& Exception 2") = {
(passed && propException) == exception
(passed && propException()) == exception
}
property("Prop.&& Identity") = {
val g = oneOf(proved,passed,falsified,undecided,exception)
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/org/scalacheck/ShrinkSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ object ShrinkSpecification extends Properties("Shrink") {
(n.isFinite && n != Duration.Zero) ==> shrinkClosure(n).contains(Duration.Zero)
}

implicit def vectorShrink[A: Shrink] = Shrink.xmap[List[A],Vector[A]](Vector(_: _*), _.toList)
implicit def vectorShrink[A: Shrink]: Shrink[Vector[A]] = Shrink.xmap[List[A],Vector[A]](Vector(_: _*), _.toList)

property("either shrinks") = forAll { e: Either[Int, Long] =>
!shrink(e).contains(e)
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/org/scalacheck/examples/Examples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object Examples extends Properties("Examples") {

import org.scalacheck.Arbitrary

implicit val arbPerson = Arbitrary(genPerson)
implicit val arbPerson: Arbitrary[Person] = Arbitrary(genPerson)

property("ex1") = Prop.forAll { p: Person =>
p.isTeenager == (p.age >= 13 && p.age <= 19)
Expand Down