aboutsummaryrefslogtreecommitdiff
path: root/compiler/test/dotty/tools/dotc/ParallelTesting.scala
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2017-03-09 16:47:04 +0100
committerFelix Mulder <felix.mulder@gmail.com>2017-03-29 10:33:21 +0200
commit531c7226d9a765aa1530f4437633365e3e140f0f (patch)
treebeee9c07fc07f3b3122ac9a6a8cbf9c54cdf2b16 /compiler/test/dotty/tools/dotc/ParallelTesting.scala
parent5ce54c68f9130dea5b4d31b3b47bb78d76a57952 (diff)
downloaddotty-531c7226d9a765aa1530f4437633365e3e140f0f.tar.gz
dotty-531c7226d9a765aa1530f4437633365e3e140f0f.tar.bz2
dotty-531c7226d9a765aa1530f4437633365e3e140f0f.zip
Add interface for unit tests into `ParallelTesting`
Diffstat (limited to 'compiler/test/dotty/tools/dotc/ParallelTesting.scala')
-rw-r--r--compiler/test/dotty/tools/dotc/ParallelTesting.scala60
1 files changed, 60 insertions, 0 deletions
diff --git a/compiler/test/dotty/tools/dotc/ParallelTesting.scala b/compiler/test/dotty/tools/dotc/ParallelTesting.scala
index 5df9e2e3d..4061517e6 100644
--- a/compiler/test/dotty/tools/dotc/ParallelTesting.scala
+++ b/compiler/test/dotty/tools/dotc/ParallelTesting.scala
@@ -38,4 +38,64 @@ trait ParallelTesting {
files -> reporter.errors
}
+ def compileFilesInDir(f: String, flags: Array[String])(implicit outDir: String): Unit = {
+ val dir = new JFile(f)
+ require(f.contains("/tests"), "only allowed to run integration tests from `tests` dir using this method")
+ require(dir.isDirectory && dir.exists, "passed non-directory to `compileFilesInDir`")
+ require(outDir.last == '/', "please specify an `outDir` with a trailing slash")
+
+ def toCompilerDirFromDir(d: JFile): JFile = {
+ val targetDir = new JFile(outDir + s"${dir.getName}/${d.getName}")
+ // create if not exists
+ targetDir.mkdirs()
+ d.listFiles.foreach(copyToDir(targetDir, _))
+ targetDir
+ }
+ def toCompilerDirFromFile(file: JFile): JFile = {
+ val uniqueSubdir = file.getName.substring(0, file.getName.lastIndexOf('.'))
+ val targetDir = new JFile(outDir + s"${dir.getName}/$uniqueSubdir")
+ // create if not exists
+ targetDir.mkdirs()
+ // copy file to dir:
+ copyToDir(targetDir, file)
+ targetDir
+ }
+ def copyToDir(dir: JFile, file: JFile): Unit = {
+ val target = Paths.get(dir.getAbsolutePath, file.getName)
+ Files.copy(file.toPath, target, REPLACE_EXISTING).toFile
+ }
+
+ val (dirs, files) =
+ dir.listFiles.foldLeft((List.empty[JFile], List.empty[JFile])) { case ((dirs, files), f) =>
+ if (f.isDirectory) (f :: dirs, files)
+ else (dirs, f :: files)
+ }
+
+ // Directories in which to compile all containing files with `flags`:
+ val dirsToCompile = files.map(toCompilerDirFromFile) ++ dirs.map(toCompilerDirFromDir)
+
+ // Progress bar setup
+ val numberOfTargets = dirsToCompile.length
+ var targetsCompiled = 0
+ val start = System.currentTimeMillis
+ var errors = 0
+
+ dirsToCompile.map { dir =>
+ val sourceFiles = dir.listFiles.filter(f => f.getName.endsWith(".scala") || f.getName.endsWith(".java"))
+ targetsCompiled += 1
+ val timestamp = (System.currentTimeMillis - start) / 1000
+ val progress = (targetsCompiled.toDouble / numberOfTargets * 40).toInt
+ print(
+ s"Compiling tests in $f [" +
+ ("=" * (math.max(progress - 1, 0))) +
+ (if (progress > 0) ">" else "") +
+ (" " * (39 - progress)) +
+ s"] $targetsCompiled/$numberOfTargets, ${timestamp}s, errors: $errors\r"
+ )
+ val (_, newErrors ) = compile(sourceFiles, flags ++ Array("-d", dir.getAbsolutePath))
+ errors += newErrors.length
+ }
+ println(s"Compiled tests in $f [========================================] $targetsCompiled/$numberOfTargets, ${(System.currentTimeMillis - start) / 1000}s, errors: $errors ")
+
+ }
}