aboutsummaryrefslogtreecommitdiff
path: root/compiler/test/dotty/tools/dotc/ParallelTesting.scala
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2017-03-20 15:34:46 +0100
committerFelix Mulder <felix.mulder@gmail.com>2017-03-29 10:33:24 +0200
commit40627780e12fa1b08d57f298e8a95fcde57f0601 (patch)
treee464a34bd5622eec269f6241aacb21de64eb055f /compiler/test/dotty/tools/dotc/ParallelTesting.scala
parent5d36bf9f2ff6bb5339e05a7ca6aac48e90ada174 (diff)
downloaddotty-40627780e12fa1b08d57f298e8a95fcde57f0601.tar.gz
dotty-40627780e12fa1b08d57f298e8a95fcde57f0601.tar.bz2
dotty-40627780e12fa1b08d57f298e8a95fcde57f0601.zip
Fix reflective method lookup to work for both scalac & dotty
Diffstat (limited to 'compiler/test/dotty/tools/dotc/ParallelTesting.scala')
-rw-r--r--compiler/test/dotty/tools/dotc/ParallelTesting.scala49
1 files changed, 28 insertions, 21 deletions
diff --git a/compiler/test/dotty/tools/dotc/ParallelTesting.scala b/compiler/test/dotty/tools/dotc/ParallelTesting.scala
index cdafed36f..884fd155e 100644
--- a/compiler/test/dotty/tools/dotc/ParallelTesting.scala
+++ b/compiler/test/dotty/tools/dotc/ParallelTesting.scala
@@ -15,6 +15,7 @@ import java.nio.file.{ Files, Path, Paths, NoSuchFileException }
import java.util.concurrent.{ Executors => JExecutors, TimeUnit }
import scala.util.control.NonFatal
import scala.util.Try
+import scala.collection.mutable
import java.util.HashMap
trait ParallelTesting {
@@ -539,13 +540,31 @@ trait ParallelTesting {
else (dirs, f :: files)
}
+ private def getCallingMethod(): String = {
+ val seen = mutable.Set.empty[String]
+ Thread.currentThread.getStackTrace
+ .filter { elem =>
+ if (seen.contains(elem.getMethodName)) false
+ else { seen += elem.getMethodName; true }
+ }
+ .take(6).find { elem =>
+ val callingClass = Class.forName(elem.getClassName)
+ classOf[ParallelTesting].isAssignableFrom(callingClass) &&
+ elem.getFileName != "ParallelTesting.scala"
+ }
+ .map(_.getMethodName)
+ .getOrElse {
+ throw new IllegalStateException("Unable to reflectively find calling method")
+ }
+ }
+
def compileFile(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = {
- // each calling method gets its own unique output directory, in which we
- // place the dir being compiled:
- val callingMethod = Thread.currentThread.getStackTrace.apply(3).getMethodName
- val outDir = outDirectory + callingMethod + "/"
val sourceFile = new JFile(f)
val parent = sourceFile.getParentFile
+ val outDir =
+ outDirectory + getCallingMethod + "/" +
+ sourceFile.getName.substring(0, sourceFile.getName.lastIndexOf('.')) + "/"
+
require(
sourceFile.exists && !sourceFile.isDirectory &&
(parent ne null) && parent.exists && parent.isDirectory,
@@ -561,10 +580,7 @@ trait ParallelTesting {
}
def compileDir(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = {
- // each calling method gets its own unique output directory, in which we
- // place the dir being compiled:
- val callingMethod = Thread.currentThread.getStackTrace.apply(3).getMethodName
- val outDir = outDirectory + callingMethod + "/"
+ val outDir = outDirectory + getCallingMethod + "/"
val sourceDir = new JFile(f)
requirements(f, sourceDir, outDir)
@@ -573,7 +589,7 @@ trait ParallelTesting {
else Array(f)
// Directories in which to compile all containing files with `flags`:
- val targetDir = new JFile(outDir)
+ val targetDir = new JFile(outDir + "/" + sourceDir.getName + "/")
targetDir.mkdirs()
val target = ConcurrentCompilationTarget(flatten(sourceDir), flags, targetDir)
@@ -581,10 +597,7 @@ trait ParallelTesting {
}
def compileList(files: List[String], flags: Array[String])(implicit outDirectory: String): CompilationTest = {
- // each calling method gets its own unique output directory, in which we
- // place the dir being compiled:
- val callingMethod = Thread.currentThread.getStackTrace.apply(3).getMethodName
- val outDir = outDirectory + callingMethod + "/"
+ val outDir = outDirectory + getCallingMethod + "/" + testName + "/"
// Directories in which to compile all containing files with `flags`:
val targetDir = new JFile(outDir)
@@ -598,10 +611,7 @@ trait ParallelTesting {
}
def compileFilesInDir(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = {
- // each calling method gets its own unique output directory, in which we
- // place the dir being compiled:
- val callingMethod = Thread.currentThread.getStackTrace.apply(3).getMethodName
- val outDir = outDirectory + callingMethod + "/"
+ val outDir = outDirectory + getCallingMethod + "/"
val sourceDir = new JFile(f)
requirements(f, sourceDir, outDir)
@@ -616,10 +626,7 @@ trait ParallelTesting {
}
def compileShallowFilesInDir(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = {
- // each calling method gets its own unique output directory, in which we
- // place the dir being compiled:
- val callingMethod = Thread.currentThread.getStackTrace.apply(3).getMethodName
- val outDir = outDirectory + callingMethod + "/"
+ val outDir = outDirectory + getCallingMethod + "/"
val sourceDir = new JFile(f)
requirements(f, sourceDir, outDir)