From abffc3e1bd7ecd17fa0ddf1c3cd2a361d74e2193 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Wed, 14 May 2014 12:30:56 -0400 Subject: [PATCH] Bump expected 2.11 module versions so we can compile with 2.11 Add scala 2.11 test/build verification. * Add 2.11 build configuratoin to travis ci * Create command which runs `safe` unit tests * Create command to test the scala 2.11 build * Update scalacheck to 1.11.4 * Update specs2 to 2.3.11 * Fix various 2.11/deprecation removals and other changes. Fix eval test failure in scala 2.11 with XML not existing. --- .travis.yml | 4 ++-- .../xsbt/api/NameHashingSpecification.scala | 4 ++-- ivy/src/test/scala/ComponentManagerTest.scala | 4 ++-- launch/src/test/scala/LocksTest.scala | 10 +++++--- launch/src/test/scala/ScalaProviderTest.scala | 6 ++--- .../test/scala/sbt/compiler/EvalTest.scala | 4 ++-- main/src/test/scala/ParseKey.scala | 23 +++++++++++++++---- project/Sbt.scala | 15 +++++++++++- project/Util.scala | 13 ++++++----- util/io/src/test/scala/StashSpec.scala | 4 ++-- util/log/src/test/scala/LogWriterTest.scala | 2 +- 11 files changed, 60 insertions(+), 29 deletions(-) diff --git a/.travis.yml b/.travis.yml index 62afa34f1..a072d1287 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,8 +17,8 @@ env: - SCRIPTED_TEST="scripted source-dependencies/*2of3" - SCRIPTED_TEST="scripted source-dependencies/*3of3" - SCRIPTED_TEST="scripted tests/*" - - SCRIPTED_TEST="all launcher/test main-settings/test main/test ivy/test logic/test completion/test" - - SCRIPTED_TEST="all actions/test classpath/test collections/test incremental-compiler/test logging/test run/test task-system/test" + - SCRIPTED_TEST="safeUnitTests" + - SCRIPTED_TEST="checkBuildScala211" # TODO - we'd like to actually test everything, but the process library has a deadlock right now jdk: - openjdk6 diff --git a/compile/api/src/test/scala/xsbt/api/NameHashingSpecification.scala b/compile/api/src/test/scala/xsbt/api/NameHashingSpecification.scala index 9df16d7c8..cb6a54ef7 100644 --- a/compile/api/src/test/scala/xsbt/api/NameHashingSpecification.scala +++ b/compile/api/src/test/scala/xsbt/api/NameHashingSpecification.scala @@ -165,14 +165,14 @@ class NameHashingSpecification extends Specification { } private def assertNameHashEqualForRegularName(name: String, nameHashes1: _internalOnly_NameHashes, - nameHashes2: _internalOnly_NameHashes): Unit = { + nameHashes2: _internalOnly_NameHashes) = { val nameHash1 = nameHashForRegularName(nameHashes1, name) val nameHash2 = nameHashForRegularName(nameHashes1, name) nameHash1 === nameHash2 } private def assertNameHashNotEqualForRegularName(name: String, nameHashes1: _internalOnly_NameHashes, - nameHashes2: _internalOnly_NameHashes): Unit = { + nameHashes2: _internalOnly_NameHashes) = { val nameHash1 = nameHashForRegularName(nameHashes1, name) val nameHash2 = nameHashForRegularName(nameHashes2, name) nameHash1 !=== nameHash2 diff --git a/ivy/src/test/scala/ComponentManagerTest.scala b/ivy/src/test/scala/ComponentManagerTest.scala index 80c3f4639..1995bb304 100644 --- a/ivy/src/test/scala/ComponentManagerTest.scala +++ b/ivy/src/test/scala/ComponentManagerTest.scala @@ -35,13 +35,13 @@ object ComponentManagerTest extends Specification { "return the files for a multi-file component" in { withManager { manager => val hashes = defineFiles(manager, TestID, "a", "b") - checksum(manager.files(TestID)(Fail)) must haveTheSameElementsAs(hashes) + checksum(manager.files(TestID)(Fail)) must containTheSameElementsAs(hashes) } } "return the files for a single-file component" in { withManager { manager => val hashes = defineFiles(manager, TestID, "a") - checksum(manager.files(TestID)(Fail)) must haveTheSameElementsAs(hashes) + checksum(manager.files(TestID)(Fail)) must containTheSameElementsAs(hashes) } } "throw an exception if 'files' is called for a non-existing component" in { diff --git a/launch/src/test/scala/LocksTest.scala b/launch/src/test/scala/LocksTest.scala index b2e45d415..f1e90bc70 100644 --- a/launch/src/test/scala/LocksTest.scala +++ b/launch/src/test/scala/LocksTest.scala @@ -51,8 +51,12 @@ object LocksTest extends Properties("Locks") { (true /: forkWait(n)(impl))(_ && _) private def forkWait(n: Int)(impl: Int => Boolean): Iterable[Boolean] = { - import scala.concurrent.ops.future - val futures = (0 until n).map { i => future { impl(i) } } - futures.toList.map(_()) + import scala.concurrent.Future + import scala.concurrent.ExecutionContext.Implicits.global + import scala.concurrent.Await + import scala.concurrent.duration.Duration.Inf + // TODO - Don't wait forever... + val futures = (0 until n).map { i => Future { impl(i) } } + futures.toList.map(f => Await.result(f, Inf)) } } \ No newline at end of file diff --git a/launch/src/test/scala/ScalaProviderTest.scala b/launch/src/test/scala/ScalaProviderTest.scala index 3188f6246..19ea5bcbc 100644 --- a/launch/src/test/scala/ScalaProviderTest.scala +++ b/launch/src/test/scala/ScalaProviderTest.scala @@ -59,8 +59,8 @@ object ScalaProviderTest extends Specification { testResources.foreach(resource => touch(new File(resourceDirectory, resource.replace('/', File.separatorChar)))) Array(resourceDirectory) } - private def checkScalaLoader(version: String): Unit = withLauncher(checkLauncher(version, mapScalaVersion(version))) - private def checkLauncher(version: String, versionValue: String)(launcher: Launcher): Unit = + private def checkScalaLoader(version: String) = withLauncher(checkLauncher(version, mapScalaVersion(version))) + private def checkLauncher(version: String, versionValue: String)(launcher: Launcher) = { val provider = launcher.getScala(version) val loader = provider.loader @@ -68,7 +68,7 @@ object ScalaProviderTest extends Specification { tryScala(loader) getScalaVersion(loader) must beEqualTo(versionValue) } - private def tryScala(loader: ClassLoader): Unit = Class.forName("scala.Product", false, loader).getClassLoader must be(loader) + private def tryScala(loader: ClassLoader) = Class.forName("scala.Product", false, loader).getClassLoader must be(loader) } object LaunchTest { def testApp(main: String): Application = testApp(main, Array[File]()) diff --git a/main/actions/src/test/scala/sbt/compiler/EvalTest.scala b/main/actions/src/test/scala/sbt/compiler/EvalTest.scala index 9203919b1..efd87b126 100644 --- a/main/actions/src/test/scala/sbt/compiler/EvalTest.scala +++ b/main/actions/src/test/scala/sbt/compiler/EvalTest.scala @@ -66,8 +66,8 @@ val p = { property("explicit import") = forAll(testImport("import math.abs" :: Nil)) property("wildcard import") = forAll(testImport("import math._" :: Nil)) - property("comma-separated imports") = forAll(testImport("import util._, math._, xml._" :: Nil)) - property("multiple imports") = forAll(testImport("import util._" :: "import math._" :: "import xml._" :: Nil)) + property("comma-separated imports") = forAll(testImport("import annotation._, math._, meta._" :: Nil)) + property("multiple imports") = forAll(testImport("import annotation._" :: "import math._" :: "import meta._" :: Nil)) private[this] def testImport(imports: Seq[String]): Int => Prop = i => value(eval.eval("abs(" + i + ")", new EvalImports(imports.zipWithIndex, "imp"))) == math.abs(i) diff --git a/main/src/test/scala/ParseKey.scala b/main/src/test/scala/ParseKey.scala index 5d3f05e1d..637782369 100644 --- a/main/src/test/scala/ParseKey.scala +++ b/main/src/test/scala/ParseKey.scala @@ -106,17 +106,30 @@ object ParseKey extends Properties("Key parser test") { f(parsed) } - def genStructure(implicit genEnv: Gen[Env]): Gen[Structure] = + // Here we're shadowing the in-scope implicit called `mkEnv` for this method + // so that it will use the passed-in `Gen` rather than the one imported + // from TestBuild. + def genStructure(implicit mkEnv: Gen[Env]): Gen[Structure] = structureGenF { (scopes: Seq[Scope], env: Env, current: ProjectRef) => - val settings = for (scope <- scopes; t <- env.tasks) yield Def.setting(ScopedKey(scope, t.key), Def.value("")) + val settings = + for { + scope <- scopes + t <- env.tasks + } yield Def.setting(ScopedKey(scope, t.key), Def.value("")) TestBuild.structure(env, settings, current) } - def structureGenF(f: (Seq[Scope], Env, ProjectRef) => Structure)(implicit genEnv: Gen[Env]): Gen[Structure] = + // Here we're shadowing the in-scope implicit called `mkEnv` for this method + // so that it will use the passed-in `Gen` rather than the one imported + // from TestBuild. + def structureGenF(f: (Seq[Scope], Env, ProjectRef) => Structure)(implicit mkEnv: Gen[Env]): Gen[Structure] = structureGen((s, e, p) => Gen.value(f(s, e, p))) - def structureGen(f: (Seq[Scope], Env, ProjectRef) => Gen[Structure])(implicit genEnv: Gen[Env]): Gen[Structure] = + // Here we're shadowing the in-scope implicit called `mkEnv` for this method + // so that it will use the passed-in `Gen` rather than the one imported + // from TestBuild. + def structureGen(f: (Seq[Scope], Env, ProjectRef) => Gen[Structure])(implicit mkEnv: Gen[Env]): Gen[Structure] = for { - env <- genEnv + env <- mkEnv loadFactor <- choose(0.0, 1.0) scopes <- pickN(loadFactor, env.allFullScopes) current <- oneOf(env.allProjects.unzip._1) diff --git a/project/Sbt.scala b/project/Sbt.scala index 4e660f421..b8f4da141 100644 --- a/project/Sbt.scala +++ b/project/Sbt.scala @@ -23,7 +23,20 @@ object Sbt extends Build { concurrentRestrictions in Global += Util.testExclusiveRestriction, testOptions += Tests.Argument(TestFrameworks.ScalaCheck, "-w", "1"), javacOptions in compile ++= Seq("-target", "6", "-source", "6", "-Xlint", "-Xlint:-serial"), - incOptions := incOptions.value.withNameHashing(true) + incOptions := incOptions.value.withNameHashing(true), + commands += Command.command("checkBuildScala211") { state => + """set scalaVersion in ThisBuild := "2.11.0" """ :: + "set Util.includeTestDependencies in ThisBuild := true" :: + // First compile everything before attempting to test + "all compile test:compile" :: + // Now run known working tests. + "safeUnitTests" :: + state + }, + commands += Command.command("safeUnitTests") { state => + "all launcher/test main-settings/test main/test ivy/test logic/test completion/test actions/test classpath/test collections/test incremental-compiler/test logging/test run/test task-system/test" :: + state + } ) lazy val myProvided = config("provided") intransitive; diff --git a/project/Util.scala b/project/Util.scala index 4228c3e53..7be84a09e 100644 --- a/project/Util.scala +++ b/project/Util.scala @@ -31,7 +31,8 @@ object Util { ) def commonSettings(nameString: String) = Seq( crossVersion in update <<= (crossVersion, nightly211) { (cv, n) => if (n) CrossVersion.full else cv }, - name := nameString + name := nameString, + resolvers += Resolver.typesafeIvyRepo("releases") ) def minProject(path: File, nameString: String) = Project(normalize(nameString), path) settings (commonSettings(nameString) ++ publishPomSettings: _*) def baseProject(path: File, nameString: String) = minProject(path, nameString) settings (base: _*) @@ -49,8 +50,8 @@ object Util { def testDependencies = libraryDependencies <++= includeTestDependencies { incl => if (incl) Seq( - "org.scalacheck" %% "scalacheck" % "1.11.1" % "test", - "org.specs2" %% "specs2" % "1.12.3" % "test", + "org.scalacheck" %% "scalacheck" % "1.11.4" % "test", + "org.specs2" %% "specs2" % "2.3.11" % "test", "junit" % "junit" % "4.11" % "test" ) else Seq() @@ -169,7 +170,7 @@ object Common { lazy val ivy = lib("org.scala-sbt.ivy" % "ivy" % "2.4.0-sbt-d6fca11d63402c92e4167cdf2da91a660d043392") lazy val httpclient = lib("commons-httpclient" % "commons-httpclient" % "3.1") lazy val jsch = lib("com.jcraft" % "jsch" % "0.1.46" intransitive ()) - lazy val sbinary = libraryDependencies <+= Util.nightly211(n => "org.scala-tools.sbinary" % "sbinary" % "0.4.2" cross (if (n) CrossVersion.full else CrossVersion.binary)) + lazy val sbinary = libraryDependencies += "org.scala-tools.sbinary" %% "sbinary" % "0.4.2" lazy val scalaCompiler = libraryDependencies <+= scalaVersion(sv => "org.scala-lang" % "scala-compiler" % sv) lazy val testInterface = lib("org.scala-sbt" % "test-interface" % "1.0") private def scala211Module(name: String, moduleVersion: String) = @@ -177,8 +178,8 @@ object Common { if (scalaVersion startsWith "2.11.") ("org.scala-lang.modules" %% name % moduleVersion) :: Nil else Nil ) - lazy val scalaXml = scala211Module("scala-xml", "1.0.0-RC7") - lazy val scalaParsers = scala211Module("scala-parser-combinators", "1.0.0-RC5") + lazy val scalaXml = scala211Module("scala-xml", "1.0.1") + lazy val scalaParsers = scala211Module("scala-parser-combinators", "1.0.1") } object Licensed { lazy val notice = SettingKey[File]("notice") diff --git a/util/io/src/test/scala/StashSpec.scala b/util/io/src/test/scala/StashSpec.scala index 49b40810f..566e9a347 100644 --- a/util/io/src/test/scala/StashSpec.scala +++ b/util/io/src/test/scala/StashSpec.scala @@ -26,7 +26,7 @@ object CheckStash extends Specification { } } - def checkRestore(seq: Seq[File]) { + def checkRestore(seq: Seq[File]) = { allCorrect(seq) stash0(seq, throw new TestRuntimeException) must beFalse @@ -38,7 +38,7 @@ object CheckStash extends Specification { stash0(seq, throw new TestError) must beFalse noneExist(seq) } - def checkMove(seq: Seq[File]) { + def checkMove(seq: Seq[File]) = { allCorrect(seq) stash0(seq, ()) must beTrue noneExist(seq) diff --git a/util/log/src/test/scala/LogWriterTest.scala b/util/log/src/test/scala/LogWriterTest.scala index d51919ad7..db8250139 100644 --- a/util/log/src/test/scala/LogWriterTest.scala +++ b/util/log/src/test/scala/LogWriterTest.scala @@ -128,7 +128,7 @@ object Escape { def pad(s: String, minLength: Int, extra: Char) = { val diff = minLength - s.length - if (diff <= 0) s else List.make(diff, extra).mkString("", "", s) + if (diff <= 0) s else List.fill(diff)(extra).mkString("", "", s) } /** Replaces a \n character at the end of a string `s` with `nl`.*/ def newline(s: String, nl: String): String =