mirror of https://github.com/sbt/sbt.git
Merge pull request #6418 from VlachJosef/develop
Instantiate only test runners needed by current TestDefinitions
This commit is contained in:
commit
966dff9684
|
|
@ -23,15 +23,13 @@ import sbt.internal.util.{ RunningProcesses, Terminal => UTerminal }
|
|||
private[sbt] object ForkTests {
|
||||
def apply(
|
||||
runners: Map[TestFramework, Runner],
|
||||
tests: Vector[TestDefinition],
|
||||
opts: ProcessedOptions,
|
||||
config: Execution,
|
||||
classpath: Seq[File],
|
||||
fork: ForkOptions,
|
||||
log: Logger,
|
||||
tags: (Tag, Int)*
|
||||
): Task[TestOutput] = {
|
||||
val opts = processOptions(config, tests, log)
|
||||
|
||||
import std.TaskExtra._
|
||||
val dummyLoader = this.getClass.getClassLoader // can't provide the loader for test classes, which is in another jvm
|
||||
def all(work: Seq[ClassLoader => Unit]) = work.fork(f => f(dummyLoader))
|
||||
|
|
@ -46,6 +44,19 @@ private[sbt] object ForkTests {
|
|||
}
|
||||
}
|
||||
|
||||
def apply(
|
||||
runners: Map[TestFramework, Runner],
|
||||
tests: Vector[TestDefinition],
|
||||
config: Execution,
|
||||
classpath: Seq[File],
|
||||
fork: ForkOptions,
|
||||
log: Logger,
|
||||
tags: (Tag, Int)*
|
||||
): Task[TestOutput] = {
|
||||
val opts = processOptions(config, tests, log)
|
||||
apply(runners, opts, config, classpath, fork, log, tags: _*)
|
||||
}
|
||||
|
||||
def apply(
|
||||
runners: Map[TestFramework, Runner],
|
||||
tests: Vector[TestDefinition],
|
||||
|
|
|
|||
|
|
@ -308,11 +308,10 @@ object Tests {
|
|||
frameworks: Map[TestFramework, Framework],
|
||||
testLoader: ClassLoader,
|
||||
runners: Map[TestFramework, Runner],
|
||||
discovered: Vector[TestDefinition],
|
||||
o: ProcessedOptions,
|
||||
config: Execution,
|
||||
log: ManagedLogger
|
||||
): Task[Output] = {
|
||||
val o = processOptions(config, discovered, log)
|
||||
testTask(
|
||||
testLoader,
|
||||
frameworks,
|
||||
|
|
@ -326,6 +325,18 @@ object Tests {
|
|||
)
|
||||
}
|
||||
|
||||
def apply(
|
||||
frameworks: Map[TestFramework, Framework],
|
||||
testLoader: ClassLoader,
|
||||
runners: Map[TestFramework, Runner],
|
||||
discovered: Vector[TestDefinition],
|
||||
config: Execution,
|
||||
log: ManagedLogger
|
||||
): Task[Output] = {
|
||||
val o = processOptions(config, discovered, log)
|
||||
apply(frameworks, testLoader, runners, o, config, log)
|
||||
}
|
||||
|
||||
def testTask(
|
||||
loader: ClassLoader,
|
||||
frameworks: Map[TestFramework, Framework],
|
||||
|
|
|
|||
|
|
@ -1502,7 +1502,26 @@ object Defaults extends BuildCommon {
|
|||
strategy: ClassLoaderLayeringStrategy,
|
||||
projectId: String
|
||||
): Initialize[Task[Tests.Output]] = {
|
||||
val runners = createTestRunners(frameworks, loader, config)
|
||||
val processedOptions: Map[Tests.Group, Tests.ProcessedOptions] =
|
||||
groups
|
||||
.map(
|
||||
group => group -> Tests.processOptions(config, group.tests.toVector, s.log)
|
||||
)
|
||||
.toMap
|
||||
|
||||
val testDefinitions: Iterable[TestDefinition] = processedOptions.values.flatMap(_.tests)
|
||||
|
||||
val filteredFrameworks: Map[TestFramework, Framework] = frameworks.filter {
|
||||
case (_, framework) =>
|
||||
TestFramework.getFingerprints(framework).exists { t =>
|
||||
testDefinitions.exists { test =>
|
||||
TestFramework.matches(t, test.fingerprint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val runners = createTestRunners(filteredFrameworks, loader, config)
|
||||
|
||||
val groupTasks = groups map { group =>
|
||||
group.runPolicy match {
|
||||
case Tests.SubProcess(opts) =>
|
||||
|
|
@ -1511,7 +1530,7 @@ object Defaults extends BuildCommon {
|
|||
s.log.debug(s"Forking tests - parallelism = ${forkedConfig.parallel}")
|
||||
ForkTests(
|
||||
runners,
|
||||
group.tests.toVector,
|
||||
processedOptions(group),
|
||||
forkedConfig,
|
||||
cp.files,
|
||||
opts,
|
||||
|
|
@ -1526,7 +1545,7 @@ object Defaults extends BuildCommon {
|
|||
frameworks,
|
||||
loader,
|
||||
runners,
|
||||
group.tests.toVector,
|
||||
processedOptions(group),
|
||||
config.copy(tags = config.tags ++ group.tags),
|
||||
s.log
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
val scalatest = "org.scalatest" %% "scalatest" % "3.2.2"
|
||||
val munit = "org.scalameta" %% "munit" % "0.7.22"
|
||||
|
||||
ThisBuild / scalaVersion := "2.12.12"
|
||||
|
||||
libraryDependencies += scalatest % Test
|
||||
libraryDependencies += munit % Test
|
||||
|
||||
testFrameworks += new TestFramework("munit.Framework")
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package example
|
||||
|
||||
import munit.FunSuite
|
||||
|
||||
class Spec extends FunSuite {
|
||||
test("munit should work") {
|
||||
assertEquals(1, 1)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package example
|
||||
|
||||
import org.scalatest.flatspec.AnyFlatSpec
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
|
||||
class ScalaTestSpec extends AnyFlatSpec with Matchers {
|
||||
"ScalaTest" should "work" in {
|
||||
1 shouldBe 1
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
> testOnly example.MunitSpec example.ScalaTestSpec
|
||||
> testOnly example.MunitSpec -- "--tests=munit"
|
||||
Loading…
Reference in New Issue