aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvsalvis <salvisbergvera@gmail.com>2015-06-24 16:41:37 +0200
committervsalvis <salvisbergvera@gmail.com>2015-06-24 16:41:37 +0200
commit4b42a198a1db7bb2613e9553e7e4250e6c66f4e3 (patch)
tree32caf9cc8730393b015818f1367f8c8c7f8008a9
parent5e4e0cf35036906423e13eb74093af07a29f0521 (diff)
downloaddotty-4b42a198a1db7bb2613e9553e7e4250e6c66f4e3.tar.gz
dotty-4b42a198a1db7bb2613e9553e7e4250e6c66f4e3.tar.bz2
dotty-4b42a198a1db7bb2613e9553e7e4250e6c66f4e3.zip
Partest 3/3: Proper compiler output redirection
-rw-r--r--test/dotty/partest/DPConfig.scala7
-rw-r--r--test/dotty/partest/DPConsoleRunner.scala29
-rw-r--r--test/dotty/partest/DPDirectCompiler.scala19
-rw-r--r--test/test/CompilerTest.scala2
4 files changed, 30 insertions, 27 deletions
diff --git a/test/dotty/partest/DPConfig.scala b/test/dotty/partest/DPConfig.scala
index ad9c271ef..640dfd021 100644
--- a/test/dotty/partest/DPConfig.scala
+++ b/test/dotty/partest/DPConfig.scala
@@ -1,7 +1,8 @@
package dotty.partest
-import java.io.File
import scala.collection.JavaConversions._
+import scala.reflect.io.Path
+import java.io.File
/** Dotty Partest runs all tests in the provided testDirs located under
@@ -14,7 +15,9 @@ import scala.collection.JavaConversions._
* otherwise pos/__defaultFlags.flags are used if the file exists).
*/
object DPConfig {
- val testRoot = "./tests/partest-generated"
+ val testRoot = (Path(".") / Path("tests") / Path("partest-generated")).toString
+ val genLog = Path(testRoot) / Path("gen.log")
+
lazy val testDirs = {
val root = new File(testRoot)
val dirs = if (!root.exists) Array.empty[String] else root.listFiles.filter(_.isDirectory).map(_.getName)
diff --git a/test/dotty/partest/DPConsoleRunner.scala b/test/dotty/partest/DPConsoleRunner.scala
index 13ffed050..fa6256398 100644
--- a/test/dotty/partest/DPConsoleRunner.scala
+++ b/test/dotty/partest/DPConsoleRunner.scala
@@ -9,7 +9,7 @@ import scala.tools.partest._
import scala.tools.partest.nest._
import scala.util.matching.Regex
import tools.nsc.io.{ File => NSCFile }
-import java.io.{ File, PrintStream, FileOutputStream }
+import java.io.{ File, PrintStream, FileOutputStream, PrintWriter, FileWriter }
import java.net.URLClassLoader
/** Runs dotty partest from the Console, discovering test sources in
@@ -91,23 +91,11 @@ extends SuiteRunner(testSourcePath, fileManager, updateCheck, failed, javaCmdPat
val state =
try {
- // IO redirection is messy, there are no concurrency guarantees.
- // Parts of test output might end up in the wrong file or get lost.
- Console.out.flush
- Console.err.flush
- val clog = runner.cLogFile
- val stream = new PrintStream(new FileOutputStream(clog.jfile), true)
- val result = Console.withOut(stream)({ Console.withErr(stream)({
- val res = runner.run()
- Console.err.flush
- Console.out.flush
- res
- })})
- result match {
+ runner.run match {
// Append compiler output to transcript if compilation failed,
// printed with --verbose option
case TestState.Fail(f, r@"compilation failed", transcript) =>
- TestState.Fail(f, r, transcript ++ clog.fileLines.dropWhile(_ == ""))
+ TestState.Fail(f, r, transcript ++ runner.cLogFile.fileLines.dropWhile(_ == ""))
case res => res
}
} catch {
@@ -261,11 +249,16 @@ class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runn
override def groupedFiles(sources: List[File]): List[List[File]] = {
val grouped = sources groupBy (_.group)
val flatGroup = List(grouped.keys.toList.sorted.map({ k => grouped(k) sortBy (_.getName) }).flatten)
- try { // try/catch because of bug in partest
+ try { // try/catch because of bug in partest that throws exception
if (flatGroup != super.groupedFiles(sources))
- NestUI.echoWarning("Warning: Overriding compilation groups for tests: " + sources)
+ throw new java.lang.UnsupportedOperationException()
} catch {
- case e: java.lang.UnsupportedOperationException => NestUI.echoWarning("Warning: Overriding compilation groups for tests: " + sources)
+ case e: java.lang.UnsupportedOperationException =>
+ val genlogFWriter = new FileWriter(DPConfig.genLog.jfile, true)
+ val genlogWriter = new PrintWriter(genlogFWriter, true)
+ genlogWriter.println("Warning: Overriding compilation groups for tests: " + sources)
+ genlogWriter.close
+ genlogFWriter.close
}
flatGroup
}
diff --git a/test/dotty/partest/DPDirectCompiler.scala b/test/dotty/partest/DPDirectCompiler.scala
index 86e766505..b04214893 100644
--- a/test/dotty/partest/DPDirectCompiler.scala
+++ b/test/dotty/partest/DPDirectCompiler.scala
@@ -1,14 +1,17 @@
package dotty.partest
+import dotty.tools.dotc.reporting.ConsoleReporter
import scala.tools.partest.{ TestState, nest }
-import java.io.File
+import java.io.{ File, PrintWriter, FileWriter }
/* NOTE: Adapted from partest.DirectCompiler and DottyTest */
-class DPDirectCompiler(runner: nest.Runner) extends nest.DirectCompiler(runner) {
+class DPDirectCompiler(runner: DPTestRunner) extends nest.DirectCompiler(runner) {
override def compile(opts0: List[String], sources: List[File]): TestState = {
- println("\ncompiling " + sources.mkString(" ") + "\noptions: " + opts0.mkString(" "))
+ val clogFWriter = new FileWriter(runner.cLogFile.jfile, true)
+ val clogWriter = new PrintWriter(clogFWriter, true)
+ clogWriter.println("\ncompiling " + sources.mkString(" ") + "\noptions: " + opts0.mkString(" "))
implicit var ctx: dotty.tools.dotc.core.Contexts.Context = {
val base = new dotty.tools.dotc.core.Contexts.ContextBase
@@ -18,17 +21,21 @@ class DPDirectCompiler(runner: nest.Runner) extends nest.DirectCompiler(runner)
base.definitions.init(ctx)
ctx
}
-
+
try {
val processor = if (opts0.exists(_.startsWith("#"))) dotty.tools.dotc.Bench else dotty.tools.dotc.Main
- val reporter = processor.process((sources.map(_.toString) ::: opts0).toArray, ctx)
+ val clogger = new ConsoleReporter(writer = clogWriter)(ctx)
+ val reporter = processor.process((sources.map(_.toString) ::: opts0).toArray, ctx, Some(clogger))
if (!reporter.hasErrors) runner.genPass()
else {
reporter.printSummary(ctx)
runner.genFail(s"compilation failed with ${reporter.errorCount} errors")
}
- } catch {
+ } catch {
case t: Throwable => runner.genCrash(t)
+ } finally {
+ clogFWriter.close
+ clogWriter.close
}
}
}
diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala
index 4a8ec6da0..09b608f22 100644
--- a/test/test/CompilerTest.scala
+++ b/test/test/CompilerTest.scala
@@ -344,7 +344,7 @@ object CompilerTest extends App {
lazy val init: SFile = {
scala.reflect.io.Directory(DPConfig.testRoot).deleteRecursively
new JFile(DPConfig.testRoot).mkdirs
- val log = (Path(DPConfig.testRoot) / Path("gen.log")).createFile(true)
+ val log = DPConfig.genLog.createFile(true)
println(s"CompilerTest is generating tests for partest, log: $log")
log
}