Skip to content

Commit 2b90b8f

Browse files
committed
Merge branch 'cheeseng-dotty-compat-2' into 3.1.x
2 parents 6e03d4d + a8e4320 commit 2b90b8f

27 files changed

+158
-80
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,6 @@ To publish scalactic, scalatest and scalatest-app (for Scala and Scala-js, versi
120120

121121
`$ sbt clean publishSigned "project scalatestAppJS" clean publishSigned ++2.10.6 "project scalatestApp" clean publishSigned "project scalatestAppJS" clean publishSigned`
122122

123-
To publish scalactic, scalatest and scalatest-app (for Scala and Scala-js, version 2.12, and make sure you're on Java 8) to Sonatype, use the following command:
123+
To publish scalactic, scalatest and scalatest-app (for Scala and Scala-js, version 2.12 and 2.13, and make sure you're on Java 8) to Sonatype, use the following command:
124124

125-
`$ sbt ++2.12.0 clean publishSigned "project scalatestAppJS" clean publishSigned`
125+
`$ sbt ++2.12.0 clean publishSigned "project scalatestAppJS" clean publishSigned ++2.13.0-M2 clean publishSigned "project scalatestAppJS" clean publishSigned`
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.scalatest
2+
3+
/**
4+
* This compatibility workaround is taken from https://github.com/scala/scala-parallel-collections/issues/22
5+
*/
6+
private[org] object CompatParColls {
7+
val Converters = {
8+
import Compat._
9+
10+
{
11+
import scala.collection.parallel._
12+
13+
CollectionConverters
14+
}
15+
}
16+
17+
object Compat {
18+
object CollectionConverters
19+
}
20+
}

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.13
1+
sbt.version=0.13.16

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3")
22

33
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.7.0")
44

5-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.17")
5+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.20")

project/scalatest.scala

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ object ScalatestBuild extends Build {
1919

2020
// To temporarily switch sbt to a different Scala version:
2121
// > ++ 2.10.5
22-
val buildScalaVersion = "2.11.8"
22+
val buildScalaVersion = "2.11.11"
2323

2424
val releaseVersion = "3.0.1"
2525

26-
val scalacheckVersion = "1.13.4"
26+
val scalacheckVersion = "1.13.5"
2727

2828
val githubTag = "release-3.0.1" // for scaladoc source urls
2929

@@ -157,8 +157,8 @@ object ScalatestBuild extends Build {
157157
// if scala 2.11+ is used, add dependency on scala-xml module
158158
case Some((2, scalaMajor)) if scalaMajor >= 11 =>
159159
Seq(
160-
"org.scala-lang.modules" %% "scala-xml" % "1.0.5",
161-
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.4",
160+
"org.scala-lang.modules" %% "scala-xml" % "1.0.6",
161+
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.6",
162162
scalacheckDependency("optional")
163163
)
164164
case _ =>
@@ -186,7 +186,17 @@ object ScalatestBuild extends Build {
186186
"org.pegdown" % "pegdown" % "1.4.2" % "optional"
187187
)
188188

189-
def scalatestTestLibraryDependencies =
189+
def crossBuildTestLibraryDependencies(theScalaVersion: String) =
190+
CrossVersion.partialVersion(theScalaVersion) match {
191+
// if scala 2.13+ is used, add dependency on scala-parallel-collections module
192+
case Some((2, scalaMajor)) if scalaMajor >= 13 =>
193+
Seq("org.scala-lang.modules" %% "scala-parallel-collections" % "0.1.2")
194+
195+
case other =>
196+
Seq.empty
197+
}
198+
199+
def scalatestTestLibraryDependencies(theScalaVersion: String) =
190200
Seq(
191201
"commons-io" % "commons-io" % "1.3.2" % "test",
192202
"org.eclipse.jetty" % "jetty-server" % "8.1.18.v20150929" % "test",
@@ -196,7 +206,7 @@ object ScalatestBuild extends Build {
196206

197207
def scalatestJSLibraryDependencies =
198208
Seq(
199-
"org.scala-js" %% "scalajs-test-interface" % "0.6.17"
209+
"org.scala-js" %% "scalajs-test-interface" % "0.6.20"
200210
)
201211

202212
def scalatestTestOptions =
@@ -260,14 +270,16 @@ object ScalatestBuild extends Build {
260270
.settings(sharedSettings: _*)
261271
.settings(
262272
projectTitle := "Common test classes used by scalactic and scalatest",
263-
libraryDependencies += scalacheckDependency("optional")
273+
libraryDependencies += scalacheckDependency("optional"),
274+
libraryDependencies ++= crossBuildTestLibraryDependencies(scalaVersion.value)
264275
).dependsOn(scalacticMacro, LocalProject("scalatest"))
265276

266277
lazy val commonTestJS = Project("commonTestJS", file("common-test.js"))
267278
.settings(sharedSettings: _*)
268279
.settings(
269280
projectTitle := "Common test classes used by scalactic.js and scalatest.js",
270281
libraryDependencies += scalacheckDependency("optional"),
282+
libraryDependencies ++= crossBuildTestLibraryDependencies(scalaVersion.value),
271283
sourceGenerators in Compile += {
272284
Def.task{
273285
GenCommonTestJS.genMain((sourceManaged in Compile).value / "scala" / "org" / "scalatest", version.value, scalaVersion.value)
@@ -535,7 +547,7 @@ object ScalatestBuild extends Build {
535547
organization := "org.scalatest",
536548
libraryDependencies ++= crossBuildLibraryDependencies(scalaVersion.value),
537549
libraryDependencies ++= scalatestLibraryDependencies,
538-
libraryDependencies ++= scalatestTestLibraryDependencies,
550+
libraryDependencies ++= scalatestTestLibraryDependencies(scalaVersion.value),
539551
testOptions in Test := scalatestTestOptions,
540552
logBuffered in Test := false,
541553
//fork in Test := true,

scalactic-test/src/test/scala/org/scalactic/ChainSpec.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ package org.scalactic
1818
import scala.collection.GenTraversable
1919
import scala.collection.mutable.Buffer
2020
import scala.collection.mutable.ListBuffer
21+
// SKIP-SCALATESTJS-START
22+
import org.scalatest.CompatParColls.Converters._
23+
// SKIP-SCALATESTJS-END
2124

2225
class ChainSpec extends UnitSpec {
2326
"A Chain" can "be constructed with one element" in {

scalactic-test/src/test/scala/org/scalactic/EverySpec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import scala.collection.mutable.Buffer
2121
import scala.collection.mutable.ListBuffer
2222
// SKIP-SCALATESTJS-START
2323
import SharedHelpers.serializeRoundtrip
24+
import org.scalatest.CompatParColls.Converters._
2425
// SKIP-SCALATESTJS-END
2526

2627
class EverySpec extends UnitSpec {

scalactic-test/src/test/scala/org/scalactic/FutureSugarSpec.scala

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,15 @@ class FutureSugarSpec extends UnitSpec with Accumulation with FutureSugar with S
3939
Future.successful(10).validating(isRound).futureValue shouldBe 10
4040
// Scala 2.10 has problem compiling the following:
4141
// Future.failed(SomeException("oops")).validating(isRound).failed.futureValue shouldBe SomeException("oops")
42-
if (ScalacticVersions.BuiltForScalaVersion == "2.12") {
43-
// In 2.12, failed always return a Failure now, not Success, and that causing the futureValue to rethrow the exception
44-
val e = intercept[TestFailedException] {
45-
Future.failed[Int](SomeException("oops")).validating(isRound).failed.futureValue
46-
}
47-
e.cause shouldBe Some(SomeException("oops"))
48-
}
49-
else
50-
Future.failed[Int](SomeException("oops")).validating(isRound).failed.futureValue shouldBe SomeException("oops")
42+
Future.failed[Int](SomeException("oops")).validating(isRound).failed.futureValue shouldBe SomeException("oops")
5143
}
5244

5345
it should "allow multiple validation functions to be passed to validating" in {
5446
Future.successful(12).validating(isRound, isDivBy3).failed.futureValue shouldBe ValidationFailedException("12 was not a round number")
5547
Future.successful(10).validating(isRound, isDivBy3).failed.futureValue shouldBe ValidationFailedException("10 was not divisible by 3")
5648
Future.successful(30).validating(isRound, isDivBy3).futureValue shouldBe 30
5749
// Future.failed(SomeException("oops")).validating(isRound).failed.futureValue shouldBe SomeException("oops")
58-
if (ScalacticVersions.BuiltForScalaVersion == "2.12") {
59-
val e = intercept[TestFailedException] {
60-
Future.failed[Int](SomeException("oops")).validating(isRound).failed.futureValue shouldBe SomeException("oops")
61-
}
62-
e.cause shouldBe Some(SomeException("oops"))
63-
}
64-
else
65-
Future.failed[Int](SomeException("oops")).validating(isRound).failed.futureValue shouldBe SomeException("oops")
50+
Future.failed[Int](SomeException("oops")).validating(isRound).failed.futureValue shouldBe SomeException("oops")
6651
}
6752

6853
it should "require at least one parameter to be passed to validating" in {

scalactic-test/src/test/scala/org/scalactic/RequirementsSpec.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ class RequirementsSpec extends FunSpec with Requirements with OptionValues {
525525
val e = intercept[IllegalArgumentException] {
526526
require(a == 3 && { println("hi"); b == 3})
527527
}
528-
if (ScalacticVersions.BuiltForScalaVersion == "2.12")
528+
if (ScalacticVersions.BuiltForScalaVersion == "2.12" || ScalacticVersions.BuiltForScalaVersion == "2.13")
529529
assert(e.getMessage == commaBut(equaled(3, 3), wasFalse("{" + lineSeparator + " scala.Predef.println(\"hi\");" + lineSeparator + " b.==(3)" + lineSeparator + "}")))
530530
else
531531
assert(e.getMessage == commaBut(equaled(3, 3), wasFalse("{" + lineSeparator + " scala.this.Predef.println(\"hi\");" + lineSeparator + " b.==(3)" + lineSeparator + "}")))
@@ -539,7 +539,7 @@ class RequirementsSpec extends FunSpec with Requirements with OptionValues {
539539
val e = intercept[IllegalArgumentException] {
540540
require({ println("hi"); b == 5} && a == 5)
541541
}
542-
if (ScalacticVersions.BuiltForScalaVersion == "2.12")
542+
if (ScalacticVersions.BuiltForScalaVersion == "2.12" || ScalacticVersions.BuiltForScalaVersion == "2.13")
543543
assert(e.getMessage == commaBut(wasTrue("{" + lineSeparator + " scala.Predef.println(\"hi\");" + lineSeparator + " b.==(5)" + lineSeparator + "}"), didNotEqual(3, 5)))
544544
else
545545
assert(e.getMessage == commaBut(wasTrue("{" + lineSeparator + " scala.this.Predef.println(\"hi\");" + lineSeparator + " b.==(5)" + lineSeparator + "}"), didNotEqual(3, 5)))
@@ -1671,7 +1671,7 @@ class RequirementsSpec extends FunSpec with Requirements with OptionValues {
16711671
val e = intercept[IllegalArgumentException] {
16721672
require(a == 3 && { println("hi"); b == 3}, ", dude")
16731673
}
1674-
if (ScalacticVersions.BuiltForScalaVersion == "2.12")
1674+
if (ScalacticVersions.BuiltForScalaVersion == "2.12" || ScalacticVersions.BuiltForScalaVersion == "2.13")
16751675
assert(e.getMessage == commaBut(equaled(3, 3), wasFalse("{" + lineSeparator + " scala.Predef.println(\"hi\");" + lineSeparator + " b.==(3)" + lineSeparator + "}")) + ", dude")
16761676
else
16771677
assert(e.getMessage == commaBut(equaled(3, 3), wasFalse("{" + lineSeparator + " scala.this.Predef.println(\"hi\");" + lineSeparator + " b.==(3)" + lineSeparator + "}")) + ", dude")
@@ -1685,7 +1685,7 @@ class RequirementsSpec extends FunSpec with Requirements with OptionValues {
16851685
val e = intercept[IllegalArgumentException] {
16861686
require({ println("hi"); b == 5} && a == 5, ", dude")
16871687
}
1688-
if (ScalacticVersions.BuiltForScalaVersion == "2.12")
1688+
if (ScalacticVersions.BuiltForScalaVersion == "2.12" || ScalacticVersions.BuiltForScalaVersion == "2.13")
16891689
assert(e.getMessage == commaBut(wasTrue("{" + lineSeparator + " scala.Predef.println(\"hi\");" + lineSeparator + " b.==(5)" + lineSeparator + "}"), didNotEqual(3, 5)) + ", dude")
16901690
else
16911691
assert(e.getMessage == commaBut(wasTrue("{" + lineSeparator + " scala.this.Predef.println(\"hi\");" + lineSeparator + " b.==(5)" + lineSeparator + "}"), didNotEqual(3, 5)) + ", dude")
@@ -2777,7 +2777,7 @@ class RequirementsSpec extends FunSpec with Requirements with OptionValues {
27772777
val e = intercept[IllegalStateException] {
27782778
requireState(a == 3 && { println("hi"); b == 3})
27792779
}
2780-
if (ScalacticVersions.BuiltForScalaVersion == "2.12")
2780+
if (ScalacticVersions.BuiltForScalaVersion == "2.12" || ScalacticVersions.BuiltForScalaVersion == "2.13")
27812781
assert(e.getMessage == commaBut(equaled(3, 3), wasFalse("{" + lineSeparator + " scala.Predef.println(\"hi\");" + lineSeparator + " b.==(3)" + lineSeparator + "}")))
27822782
else
27832783
assert(e.getMessage == commaBut(equaled(3, 3), wasFalse("{" + lineSeparator + " scala.this.Predef.println(\"hi\");" + lineSeparator + " b.==(3)" + lineSeparator + "}")))
@@ -2791,7 +2791,7 @@ class RequirementsSpec extends FunSpec with Requirements with OptionValues {
27912791
val e = intercept[IllegalStateException] {
27922792
requireState({ println("hi"); b == 5} && a == 5)
27932793
}
2794-
if (ScalacticVersions.BuiltForScalaVersion == "2.12")
2794+
if (ScalacticVersions.BuiltForScalaVersion == "2.12" || ScalacticVersions.BuiltForScalaVersion == "2.13")
27952795
assert(e.getMessage == commaBut(wasTrue("{" + lineSeparator + " scala.Predef.println(\"hi\");" + lineSeparator + " b.==(5)" + lineSeparator + "}"), didNotEqual(3, 5)))
27962796
else
27972797
assert(e.getMessage == commaBut(wasTrue("{" + lineSeparator + " scala.this.Predef.println(\"hi\");" + lineSeparator + " b.==(5)" + lineSeparator + "}"), didNotEqual(3, 5)))
@@ -3923,7 +3923,7 @@ class RequirementsSpec extends FunSpec with Requirements with OptionValues {
39233923
val e = intercept[IllegalStateException] {
39243924
requireState(a == 3 && { println("hi"); b == 3}, ", dude")
39253925
}
3926-
if (ScalacticVersions.BuiltForScalaVersion == "2.12")
3926+
if (ScalacticVersions.BuiltForScalaVersion == "2.12" || ScalacticVersions.BuiltForScalaVersion == "2.13")
39273927
assert(e.getMessage == commaBut(equaled(3, 3), wasFalse("{" + lineSeparator + " scala.Predef.println(\"hi\");" + lineSeparator + " b.==(3)" + lineSeparator + "}")) + ", dude")
39283928
else
39293929
assert(e.getMessage == commaBut(equaled(3, 3), wasFalse("{" + lineSeparator + " scala.this.Predef.println(\"hi\");" + lineSeparator + " b.==(3)" + lineSeparator + "}")) + ", dude")
@@ -3937,7 +3937,7 @@ class RequirementsSpec extends FunSpec with Requirements with OptionValues {
39373937
val e = intercept[IllegalStateException] {
39383938
requireState({ println("hi"); b == 5} && a == 5, ", dude")
39393939
}
3940-
if (ScalacticVersions.BuiltForScalaVersion == "2.12")
3940+
if (ScalacticVersions.BuiltForScalaVersion == "2.12" || ScalacticVersions.BuiltForScalaVersion == "2.13")
39413941
assert(e.getMessage == commaBut(wasTrue("{" + lineSeparator + " scala.Predef.println(\"hi\");" + lineSeparator + " b.==(5)" + lineSeparator + "}"), didNotEqual(3, 5)) + ", dude")
39423942
else
39433943
assert(e.getMessage == commaBut(wasTrue("{" + lineSeparator + " scala.this.Predef.println(\"hi\");" + lineSeparator + " b.==(5)" + lineSeparator + "}"), didNotEqual(3, 5)) + ", dude")

scalactic-test/src/test/scala/org/scalactic/anyvals/NonEmptyArraySpec.scala

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ class NonEmptyArraySpec extends UnitSpec {
4949
NonEmptyArray.from(Array(1, 2, 3).par).get shouldBe NonEmptyArray(1, 2, 3)
5050
// SKIP-SCALATESTJS-END
5151
}
52-
it can "be constructed with null elements" in {
53-
noException should be thrownBy NonEmptyArray("hi", null, "ho")
54-
noException should be thrownBy NonEmptyArray(null)
55-
noException should be thrownBy NonEmptyArray("ho", null)
56-
}
52+
// This does not compile with scala 2.10
53+
/*it can "be constructed with null elements" in {
54+
noException should be thrownBy NonEmptyArray[String]("hi", null, "ho")
55+
noException should be thrownBy NonEmptyArray[String](null)
56+
noException should be thrownBy NonEmptyArray[String]("ho", null)
57+
}*/
5758
it can "be deconstructed with NonEmptyArray" in {
5859
NonEmptyArray(1) match {
5960
case NonEmptyArray(x) => x shouldEqual 1
@@ -1493,7 +1494,13 @@ class NonEmptyArraySpec extends UnitSpec {
14931494
}
14941495
it should "have an updated method" in {
14951496
NonEmptyArray(1).updated(0, 2) shouldBe NonEmptyArray(2)
1496-
an [IndexOutOfBoundsException] should be thrownBy { NonEmptyArray(1).updated(1, 2) }
1497+
def willThrowIndexOutOfBoundsException(): Unit = {
1498+
NonEmptyArray(1).updated(1, 2)
1499+
Unit
1500+
}
1501+
an [IndexOutOfBoundsException] should be thrownBy {
1502+
willThrowIndexOutOfBoundsException()
1503+
}
14971504
NonEmptyArray(1, 1, 1).updated(1, 2) shouldBe NonEmptyArray(1, 2, 1)
14981505
NonEmptyArray(1, 1, 1).updated(2, 2) shouldBe NonEmptyArray(1, 1, 2)
14991506
NonEmptyArray(1, 1, 1).updated(0, 2) shouldBe NonEmptyArray(2, 1, 1)

scalactic-test/src/test/scala/org/scalactic/anyvals/PosIntSpec.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,11 @@ class PosIntSpec extends FunSpec with Matchers with GeneratorDrivenPropertyCheck
333333
}
334334

335335
it("should offer 'to' and 'until' methods that are consistent with Int") {
336-
forAll { (pint: PosInt, end: Int, step: Int) =>
336+
forAll { (pint: PosInt, end: Int, generatedStep: PosInt) =>
337+
// We need to make sure the range produced's size is less than or equal to Int.MaxValue,
338+
// so the following code avoid produce range the goes overflow of int values.
339+
val step: Int = if (end < 0) -generatedStep.value else generatedStep.value
340+
337341
Try(pint.to(end)) shouldEqual Try(pint.toInt.to(end))
338342
Try(pint.to(end, step)) shouldEqual Try(pint.toInt.to(end, step))
339343
Try(pint.until(end)) shouldEqual Try(pint.toInt.until(end))

scalactic-test/src/test/scala/org/scalactic/anyvals/PosZIntSpec.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ trait PosZIntSpecSupport {
3636

3737
implicit val arbPosZInt: Arbitrary[PosZInt] = Arbitrary(posZIntGen)
3838

39+
val posIntGen: Gen[PosInt] =
40+
for {i <- choose(0, Int.MaxValue)} yield PosInt.from(i).get
41+
42+
implicit val arbPosInt: Arbitrary[PosInt] = Arbitrary(posIntGen)
43+
3944
implicit def tryEquality[T]: Equality[Try[T]] = new Equality[Try[T]] {
4045
override def areEqual(a: Try[T], b: Any): Boolean = a match {
4146
case Success(double: Double) if double.isNaN => // This is because in scala.js x/0 results to NaN not ArithmetricException like in jvm, and we need to make sure Success(NaN) == Success(NaN) is true to pass the test.
@@ -335,7 +340,11 @@ class PosZIntSpec extends FunSpec with Matchers with GeneratorDrivenPropertyChec
335340
}
336341

337342
it("should offer 'to' and 'until' methods that are consistent with Int") {
338-
forAll { (pzint: PosZInt, end: Int, step: Int) =>
343+
forAll { (pzint: PosZInt, end: Int, generatedStep: PosInt) =>
344+
// We need to make sure the range produced's size is less than or equal to Int.MaxValue,
345+
// so the following code avoid produce range the goes overflow of int values.
346+
val step: Int = if (end < 0) -generatedStep.value else generatedStep.value
347+
339348
Try(pzint.to(end)) shouldEqual Try(pzint.toInt.to(end))
340349
Try(pzint.to(end, step)) shouldEqual Try(pzint.toInt.to(end, step))
341350
Try(pzint.until(end)) shouldEqual Try(pzint.toInt.until(end))

0 commit comments

Comments
 (0)