From 62a1d42c555544dd5b203ec22af47bba5e966181 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Wed, 20 Sep 2017 23:18:37 -0400 Subject: [PATCH 1/3] Fix #3564: Filter scripted tests based on project/build.properties Skip scripted tests where the binary version configured in the build does not match the binary version of sbt used for cross-building. --- build.sbt | 2 +- .../changes/Fail.scala | 1 + .../changes/build.properties | 1 + .../scripted-skip-incompatible/changes/test | 2 ++ .../project/plugins.sbt | 3 ++ .../project/scripted-skip-incompatible/test | 17 +++++++++ .../main/scala/sbt/test/ScriptedTests.scala | 36 +++++++++++++++++-- 7 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 sbt/src/sbt-test/project/scripted-skip-incompatible/changes/Fail.scala create mode 100644 sbt/src/sbt-test/project/scripted-skip-incompatible/changes/build.properties create mode 100644 sbt/src/sbt-test/project/scripted-skip-incompatible/changes/test create mode 100644 sbt/src/sbt-test/project/scripted-skip-incompatible/project/plugins.sbt create mode 100644 sbt/src/sbt-test/project/scripted-skip-incompatible/test diff --git a/build.sbt b/build.sbt index 7e4e6d751..ff598da88 100644 --- a/build.sbt +++ b/build.sbt @@ -230,7 +230,7 @@ lazy val scriptedSbtProj = (project in scriptedPath / "sbt") libraryDependencies ++= Seq(launcherInterface % "provided"), mimaSettings, ) - .configure(addSbtIO, addSbtUtilLogging, addSbtCompilerInterface, addSbtUtilScripted) + .configure(addSbtIO, addSbtUtilLogging, addSbtCompilerInterface, addSbtUtilScripted, addSbtLmCore) lazy val scriptedPluginProj = (project in scriptedPath / "plugin") .dependsOn(sbtProj) diff --git a/sbt/src/sbt-test/project/scripted-skip-incompatible/changes/Fail.scala b/sbt/src/sbt-test/project/scripted-skip-incompatible/changes/Fail.scala new file mode 100644 index 000000000..f011d53a4 --- /dev/null +++ b/sbt/src/sbt-test/project/scripted-skip-incompatible/changes/Fail.scala @@ -0,0 +1 @@ +object Skipped { diff --git a/sbt/src/sbt-test/project/scripted-skip-incompatible/changes/build.properties b/sbt/src/sbt-test/project/scripted-skip-incompatible/changes/build.properties new file mode 100644 index 000000000..a8c2f849b --- /dev/null +++ b/sbt/src/sbt-test/project/scripted-skip-incompatible/changes/build.properties @@ -0,0 +1 @@ +sbt.version=0.12.0 diff --git a/sbt/src/sbt-test/project/scripted-skip-incompatible/changes/test b/sbt/src/sbt-test/project/scripted-skip-incompatible/changes/test new file mode 100644 index 000000000..4ed0b761f --- /dev/null +++ b/sbt/src/sbt-test/project/scripted-skip-incompatible/changes/test @@ -0,0 +1,2 @@ +$ copy-file changes/Fail.scala Skipped.scala +> compile diff --git a/sbt/src/sbt-test/project/scripted-skip-incompatible/project/plugins.sbt b/sbt/src/sbt-test/project/scripted-skip-incompatible/project/plugins.sbt new file mode 100644 index 000000000..529e7d656 --- /dev/null +++ b/sbt/src/sbt-test/project/scripted-skip-incompatible/project/plugins.sbt @@ -0,0 +1,3 @@ +libraryDependencies += { + "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value +} diff --git a/sbt/src/sbt-test/project/scripted-skip-incompatible/test b/sbt/src/sbt-test/project/scripted-skip-incompatible/test new file mode 100644 index 000000000..704535d5b --- /dev/null +++ b/sbt/src/sbt-test/project/scripted-skip-incompatible/test @@ -0,0 +1,17 @@ +# Setup failing test that should be skipped when tests are discovered +$ copy-file changes/Fail.scala src/sbt-test/group/skipped/changes/Fail.scala +$ copy-file changes/build.properties src/sbt-test/group/skipped/project/build.properties +$ copy-file changes/test src/sbt-test/group/skipped/test + +# Should fail when run explicitly +-> scripted group/skipped + +# Should be skipped when discovered +> scripted + +# Setup the same test without a project/build.properties file +$ copy-file changes/Fail.scala src/sbt-test/group/not-skipped/changes/Fail.scala +$ copy-file changes/test src/sbt-test/group/not-skipped/test + +# Running discovered tests should fail +-> scripted diff --git a/scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala b/scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala index 7094b8fb5..759c33358 100644 --- a/scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala +++ b/scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala @@ -6,6 +6,7 @@ package sbt package test import java.io.File +import java.util.Properties import scala.util.control.NonFatal import sbt.internal.scripted._ @@ -343,7 +344,9 @@ class ScriptedRunner { launchOpts: Array[String], prescripted: File => Unit): Unit = { val runner = new ScriptedTests(resourceBaseDirectory, bufferLog, bootProperties, launchOpts) - val allTests = get(tests, resourceBaseDirectory, logger) flatMap { + val sbtVersion = bootProperties.getName.dropWhile(!_.isDigit).dropRight(".jar".length) + val accept = isTestCompatible(resourceBaseDirectory, sbtVersion) _ + val allTests = get(tests, resourceBaseDirectory, accept, logger) flatMap { case ScriptedTest(group, name) => runner.singleScriptedTest(group, name, prescripted, logger) } @@ -399,17 +402,44 @@ class ScriptedRunner { reportErrors(tests.flatMap(test => test.apply().flatten.toSeq).toList) } + @deprecated("No longer used", "1.0.2") def get(tests: Seq[String], baseDirectory: File, log: Logger): Seq[ScriptedTest] = - if (tests.isEmpty) listTests(baseDirectory, log) else parseTests(tests) + get(tests, baseDirectory, _ => true, log) + def get(tests: Seq[String], + baseDirectory: File, + accept: ScriptedTest => Boolean, + log: Logger): Seq[ScriptedTest] = + if (tests.isEmpty) listTests(baseDirectory, accept, log) else parseTests(tests) + @deprecated("No longer used", "1.0.2") def listTests(baseDirectory: File, log: Logger): Seq[ScriptedTest] = - new ListTests(baseDirectory, _ => true, log).listTests + listTests(baseDirectory, _ => true, log) + def listTests(baseDirectory: File, + accept: ScriptedTest => Boolean, + log: Logger): Seq[ScriptedTest] = + (new ListTests(baseDirectory, accept, log)).listTests def parseTests(in: Seq[String]): Seq[ScriptedTest] = for (testString <- in) yield { val Array(group, name) = testString.split("/").map(_.trim) ScriptedTest(group, name) } + + private def isTestCompatible(resourceBaseDirectory: File, sbtVersion: String)( + test: ScriptedTest): Boolean = { + import sbt.internal.librarymanagement.cross.CrossVersionUtil.binarySbtVersion + val buildProperties = new Properties() + val testDir = new File(new File(resourceBaseDirectory, test.group), test.name) + val buildPropertiesFile = new File(new File(testDir, "project"), "build.properties") + + IO.load(buildProperties, buildPropertiesFile) + + Option(buildProperties.getProperty("sbt.version")) match { + case Some(version) => binarySbtVersion(version) == binarySbtVersion(sbtVersion) + case None => true + } + } + } final case class ScriptedTest(group: String, name: String) { From a08a93c5e639a0ffa72fb8cb80edca7554f52af1 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Mon, 25 Sep 2017 13:56:42 -0400 Subject: [PATCH 2/3] Set deprecation version to 1.1.0 --- scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala b/scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala index 759c33358..00781be92 100644 --- a/scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala +++ b/scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala @@ -402,7 +402,7 @@ class ScriptedRunner { reportErrors(tests.flatMap(test => test.apply().flatten.toSeq).toList) } - @deprecated("No longer used", "1.0.2") + @deprecated("No longer used", "1.1.0") def get(tests: Seq[String], baseDirectory: File, log: Logger): Seq[ScriptedTest] = get(tests, baseDirectory, _ => true, log) def get(tests: Seq[String], @@ -411,7 +411,7 @@ class ScriptedRunner { log: Logger): Seq[ScriptedTest] = if (tests.isEmpty) listTests(baseDirectory, accept, log) else parseTests(tests) - @deprecated("No longer used", "1.0.2") + @deprecated("No longer used", "1.1.0") def listTests(baseDirectory: File, log: Logger): Seq[ScriptedTest] = listTests(baseDirectory, _ => true, log) def listTests(baseDirectory: File, From 3a666705a6fe8075410bbad51857a3c82b8d5ea0 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Mon, 25 Sep 2017 14:08:41 -0400 Subject: [PATCH 3/3] Add release note --- notes/1.1.0/filter-scripted-tests.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 notes/1.1.0/filter-scripted-tests.md diff --git a/notes/1.1.0/filter-scripted-tests.md b/notes/1.1.0/filter-scripted-tests.md new file mode 100644 index 000000000..4f216e9c2 --- /dev/null +++ b/notes/1.1.0/filter-scripted-tests.md @@ -0,0 +1,14 @@ +[@jonas]: https://github.com/jonas + +[#3564]: https://github.com/sbt/sbt/issues/3564 +[#3566]: https://github.com/sbt/sbt/pull/3566 + +### Improvements + +- Filter scripted tests based on optional `project/build.properties`. [#3564]/[#3566] by [@jonas] + +### Filtering scripted tests using `project/build.properties`. + +For all scripted tests in which `project/build.properties` exist, the value of the `sbt.version` property is read. If its binary version is different from `sbtBinaryVersion in pluginCrossBuild` the test will be skipped and a message indicating this will be logged. + +This allows you to define scripted tests that track the minimum supported sbt versions, e.g. 0.13.9 and 1.0.0-RC2.