mirror of https://github.com/sbt/sbt.git
parent
b2731717fe
commit
0c9182a4b9
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
))
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
> test-failure
|
||||
> set concurrentRestrictions in Global += Tags.limit(Tags.ForkedTestGroup, 1)
|
||||
> test
|
||||
Loading…
Reference in New Issue