Fix #2677: Tags.ForkedTestGroup doesn't work

Move tag to correct task
This commit is contained in:
Paul Draper 2016-07-22 10:17:24 -06:00
parent b2731717fe
commit 0c9182a4b9
5 changed files with 48 additions and 3 deletions

View File

@ -9,9 +9,10 @@ import java.net.ServerSocket
import java.io._
import Tests.{ Output => TestOutput, _ }
import ForkMain._
import sbt.ConcurrentRestrictions.Tag
private[sbt] object ForkTests {
def apply(runners: Map[TestFramework, Runner], tests: List[TestDefinition], config: Execution, classpath: Seq[File], fork: ForkOptions, log: Logger): Task[TestOutput] = {
def apply(runners: Map[TestFramework, Runner], tests: List[TestDefinition], config: Execution, classpath: Seq[File], fork: ForkOptions, log: Logger, tag: Tag): Task[TestOutput] = {
val opts = processOptions(config, tests, log)
import std.TaskExtra._
@ -23,7 +24,7 @@ private[sbt] object ForkTests {
constant(TestOutput(TestResult.Passed, Map.empty[String, SuiteResult], Iterable.empty))
else
mainTestTask(runners, opts, classpath, fork, log, config.parallel).tagw(config.tags: _*)
main.dependsOn(all(opts.setup): _*) flatMap { results =>
main.tag(tag).dependsOn(all(opts.setup): _*) flatMap { results =>
all(opts.cleanup).join.map(_ => results)
}
}

View File

@ -566,7 +566,7 @@ object Defaults extends BuildCommon {
s.log.debug(s"javaOptions: ${opts.runJVMOptions}")
val forkedConfig = config.copy(parallel = config.parallel && forkedParallelExecution)
s.log.debug(s"Forking tests - parallelism = ${forkedConfig.parallel}")
ForkTests(runners, tests.toList, forkedConfig, cp.files, opts, s.log) tag Tags.ForkedTestGroup
ForkTests(runners, tests.toList, forkedConfig, cp.files, opts, s.log, Tags.ForkedTestGroup)
case Tests.InProcess =>
if (javaOptions.nonEmpty) {
s.log.warn("javaOptions will be ignored, fork is set to false")

View File

@ -0,0 +1,18 @@
concurrentRestrictions in Global := Seq(Tags.limitAll(4))
libraryDependencies += "org.specs2" %% "specs2-core" % "3.8.4" % Test
inConfig(Test)(Seq(
testGrouping := definedTests.value.map { test => new Tests.Group(test.name, Seq(test), Tests.SubProcess(
ForkOptions(
javaHome.value,
outputStrategy.value,
Nil,
Some(baseDirectory.value),
javaOptions.value,
connectInput.value,
envVars.value
)
))},
TaskKey[Unit]("test-failure") := test.failure.value
))

View File

@ -0,0 +1,23 @@
package example
import java.io.File
import org.specs2.mutable.Specification
trait Test extends Specification {
"spec" should {
"be run one at time" in {
val lock = new File("lock")
lock.mkdir() should beTrue
Thread.sleep(2000)
lock.delete() should beTrue
}
}
}
class Test0 extends Test
class Test1 extends Test
class Test2 extends Test
class Test3 extends Test

View File

@ -0,0 +1,3 @@
> test-failure
> set concurrentRestrictions in Global += Tags.limit(Tags.ForkedTestGroup, 1)
> test