From fd37852c0499cf0ca3dcc71333e2ab1f638d8f68 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Mon, 27 Mar 2017 16:37:45 +0200 Subject: Add test filtering via `filterTest ` --- .../test/dotty/tools/dotc/CompilationTests.scala | 3 +- .../test/dotty/tools/dotc/ParallelTestTests.scala | 2 + .../test/dotty/tools/dotc/ParallelTesting.scala | 66 ++++++++++++++-------- 3 files changed, 48 insertions(+), 23 deletions(-) (limited to 'compiler/test/dotty') diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 83713748c..93ddab057 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -7,13 +7,14 @@ import java.io.{ File => JFile } import org.junit.experimental.categories.Category - @Category(Array(classOf[ParallelTesting])) class CompilationTests extends ParallelTesting { import CompilationTests._ def interactive: Boolean = !sys.env.contains("DRONE") + def regex: Option[String] = sys.props.get("dotty.partest.filter") + // Positive tests ------------------------------------------------------------ @Test def compilePos: Unit = { diff --git a/compiler/test/dotty/tools/dotc/ParallelTestTests.scala b/compiler/test/dotty/tools/dotc/ParallelTestTests.scala index 572f63410..a22df0ace 100644 --- a/compiler/test/dotty/tools/dotc/ParallelTestTests.scala +++ b/compiler/test/dotty/tools/dotc/ParallelTestTests.scala @@ -12,6 +12,8 @@ class ParallelTestTests extends ParallelTesting { def interactive: Boolean = !sys.env.contains("DRONE") + def regex: Option[String] = None + @Test def missingFile: Unit = try { compileFile("../tests/partest-test/i-dont-exist.scala", defaultOptions).expectFailure.neg() diff --git a/compiler/test/dotty/tools/dotc/ParallelTesting.scala b/compiler/test/dotty/tools/dotc/ParallelTesting.scala index b4452299b..2123e7657 100644 --- a/compiler/test/dotty/tools/dotc/ParallelTesting.scala +++ b/compiler/test/dotty/tools/dotc/ParallelTesting.scala @@ -14,6 +14,7 @@ import scala.io.Source import scala.util.control.NonFatal import scala.util.Try import scala.collection.mutable +import scala.util.matching.Regex import core.Contexts._ import reporting.{ Reporter, TestReporter } @@ -25,6 +26,10 @@ trait ParallelTesting { def interactive: Boolean + def regex: Option[String] + + private lazy val filter: Option[Regex] = regex.map(str => new Regex(str)) + private sealed trait Target { self => def outDir: JFile def flags: Array[String] @@ -121,7 +126,16 @@ trait ParallelTesting { /** Actual compilation run logic, the test behaviour is defined here */ protected def compilationRunnable(target: Target): Runnable - val totalTargets = targets.length + private val allTargets = + if (!filter.isDefined) targets + else targets.filter { + case ConcurrentCompilationTarget(files, _, _) => + files.exists(file => filter.get.findFirstIn(file.getAbsolutePath).isDefined) + case SeparateCompilationTarget(dir, _, _) => + filter.get.findFirstIn(dir.getAbsolutePath).isDefined + } + + val totalTargets = allTargets.length private[this] var _errors = 0 def errors: Int = synchronized { _errors } @@ -271,31 +285,39 @@ trait ParallelTesting { private[ParallelTesting] def execute(): this.type = { assert(_targetsCompiled == 0, "not allowed to re-use a `CompileRun`") - val pool = threadLimit match { - case Some(i) => JExecutors.newWorkStealingPool(i) - case None => JExecutors.newWorkStealingPool() - } - if (interactive && !suppressAllOutput) pool.submit(statusRunner) + if (allTargets.nonEmpty) { + val pool = threadLimit match { + case Some(i) => JExecutors.newWorkStealingPool(i) + case None => JExecutors.newWorkStealingPool() + } - targets.foreach { target => - pool.submit(compilationRunnable(target)) - } + if (interactive && !suppressAllOutput) pool.submit(statusRunner) - pool.shutdown() - if (!pool.awaitTermination(10, TimeUnit.MINUTES)) - throw new TimeoutException("Compiling targets timed out") - - if (didFail) { - echo { - """| - |================================================================================ - |Test Report - |================================================================================ - |Failing tests:""".stripMargin + allTargets.foreach { target => + pool.submit(compilationRunnable(target)) } - failedCompilationTargets.toArray.sorted.foreach(echo) - failureInstructions.iterator.foreach(echo) + + pool.shutdown() + if (!pool.awaitTermination(10, TimeUnit.MINUTES)) + throw new TimeoutException("Compiling targets timed out") + + if (didFail) { + echo { + """| + |================================================================================ + |Test Report + |================================================================================ + |Failing tests:""".stripMargin + } + failedCompilationTargets.toArray.sorted.foreach(echo) + failureInstructions.iterator.foreach(echo) + } + } + else echo { + regex + .map(r => s"""No files matched regex "$r" in test""") + .getOrElse("No tests available under target - erroneous test?") } this -- cgit v1.2.3