diff --git a/main/src/main/scala/sbt/ScriptedPlugin.scala b/main/src/main/scala/sbt/ScriptedPlugin.scala index 9bbc7380f..2d79de76b 100644 --- a/main/src/main/scala/sbt/ScriptedPlugin.scala +++ b/main/src/main/scala/sbt/ScriptedPlugin.scala @@ -78,7 +78,7 @@ object ScriptedPlugin extends AutoPlugin { scriptedClasspath := getJars(ScriptedConf).value, scriptedTests := scriptedTestsTask.value, scriptedParallelInstances := 1, - scriptedBatchExecution := false, + scriptedBatchExecution := true, scriptedRun := scriptedRunTask.value, scriptedDependencies := { def use[A](@deprecated("unused", "") x: A*): Unit = () // avoid unused warnings diff --git a/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala b/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala index 3386b504d..b0a653598 100644 --- a/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala +++ b/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala @@ -376,7 +376,7 @@ class ScriptedRunner { launchOpts: Array[String], ): Unit = { val logger = TestConsoleLogger() - runInParallel( + run( resourceBaseDirectory, bufferLog, tests, @@ -384,7 +384,8 @@ class ScriptedRunner { launchOpts, prescripted = new java.util.ArrayList[File], LauncherBased(launcherJar), - 1 + 1, + parallelExecution = false, ) } @@ -403,7 +404,7 @@ class ScriptedRunner { prescripted: java.util.List[File], ): Unit = { val logger = TestConsoleLogger() - runInParallel( + run( resourceBaseDirectory, bufferLog, tests, @@ -411,7 +412,8 @@ class ScriptedRunner { launchOpts, prescripted, LauncherBased(launcherJar), - 1 + Int.MaxValue, + parallelExecution = false, ) } @@ -477,6 +479,18 @@ class ScriptedRunner { prescripted: java.util.List[File], prop: RemoteSbtCreatorProp, instances: Int + ) = run(baseDir, bufferLog, tests, logger, launchOpts, prescripted, prop, instances, true) + + private[this] def run( + baseDir: File, + bufferLog: Boolean, + tests: Array[String], + logger: Logger, + launchOpts: Array[String], + prescripted: java.util.List[File], + prop: RemoteSbtCreatorProp, + instances: Int, + parallelExecution: Boolean, ): Unit = { val addTestFile = (f: File) => { prescripted.add(f); () } val runner = new ScriptedTests(baseDir, bufferLog, launchOpts) @@ -490,11 +504,17 @@ class ScriptedRunner { // The scripted tests mapped to the inputs that the user wrote after `scripted`. val scriptedTests = get(tests, baseDir, accept, logger).map(st => (st.group, st.name)) + // Choosing Int.MaxValue will make the groupSize 1 in batchScriptedRunner + val groupCount = if (parallelExecution) instances else Int.MaxValue val scriptedRunners = - runner.batchScriptedRunner(scriptedTests, addTestFile, instances, prop, logger) - val parallelRunners = scriptedRunners.toParArray - parallelRunners.tasksupport = new ForkJoinTaskSupport(new ForkJoinPool(instances)) - runAll(parallelRunners) + runner.batchScriptedRunner(scriptedTests, addTestFile, groupCount, prop, logger) + if (parallelExecution && instances > 1) { + val parallelRunners = scriptedRunners.toParArray + parallelRunners.tasksupport = new ForkJoinTaskSupport(new ForkJoinPool(instances)) + runAll(parallelRunners) + } else { + runAll(scriptedRunners) + } } def runInParallel( baseDir: File,