From e80ec0a6700d3b36a2d959d0ee179954ae42e708 Mon Sep 17 00:00:00 2001 From: jvican Date: Fri, 28 Apr 2017 13:31:43 +0200 Subject: [PATCH] Abstract over `runAll` and `runInParallel` This is the best we can do without using structural types. --- .../main/scala/sbt/test/ScriptedTests.scala | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala b/scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala index 72e62c3be..692ac732e 100644 --- a/scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala +++ b/scripted/sbt/src/main/scala/sbt/test/ScriptedTests.scala @@ -201,17 +201,15 @@ class ScriptedRunner { runAllInParallel(scriptedTestRunners.toParArray) } - def runAll(tests: Seq[ScriptedTests.TestRunner]): Unit = { - val errors = for (test <- tests; err <- test()) yield err - if (errors.nonEmpty) - sys.error(errors.mkString("Failed tests:\n\t", "\n\t", "\n")) - } + private def reportErrors(errors: Seq[String]): Unit = + if (errors.nonEmpty) sys.error(errors.mkString("Failed tests:\n\t", "\n\t", "\n")) else () - def runAllInParallel(tests: ParSeq[ScriptedTests.TestRunner]): Unit = { - val executedTests = tests.flatMap(test => test.apply().toList).toList - if (executedTests.nonEmpty) - sys.error(executedTests.mkString("Failed tests:\n\t", "\n\t", "\n")) - } + def runAll(tests: Seq[ScriptedTests.TestRunner]): Unit = + reportErrors(tests.flatMap(test => test.apply().toSeq)) + + // We cannot reuse `runAll` because parallel collections != collections + def runAllInParallel(tests: ParSeq[ScriptedTests.TestRunner]): Unit = + reportErrors(tests.flatMap(test => test.apply().toSeq).toList) def get(tests: Seq[String], baseDirectory: File, log: Logger): Seq[ScriptedTest] = if (tests.isEmpty) listTests(baseDirectory, log) else parseTests(tests)