mirror of https://github.com/sbt/sbt.git
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.
This commit is contained in:
parent
4b8d31a9ea
commit
62a1d42c55
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
object Skipped {
|
||||
|
|
@ -0,0 +1 @@
|
|||
sbt.version=0.12.0
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$ copy-file changes/Fail.scala Skipped.scala
|
||||
> compile
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
libraryDependencies += {
|
||||
"org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue