From 855bdcc5210402fbb87ce10fe7da3f532fa3049f Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Wed, 1 Jun 2016 02:35:00 +0200 Subject: partest: Enable separate compilation and javac tests partest can separately compile files based on their suffix (_1, _2, ...), it turns out that this feature was never enabled in the dotty version of partest and no one noticed (it prints warnings in ./tests/partest-generated/gen.log which no one reads), tests with *.java files should be compiled both with javac and dotty, but compiling with javac was also disabled. Enabling this revealed some latent bugs that will be fixed in the next few commits. --- test/dotty/partest/DPConsoleRunner.scala | 26 -------------------------- test/test/CompilerTest.scala | 3 ++- 2 files changed, 2 insertions(+), 27 deletions(-) (limited to 'test') diff --git a/test/dotty/partest/DPConsoleRunner.scala b/test/dotty/partest/DPConsoleRunner.scala index baa62579c..c939e6704 100644 --- a/test/dotty/partest/DPConsoleRunner.scala +++ b/test/dotty/partest/DPConsoleRunner.scala @@ -245,32 +245,6 @@ class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runn } getOrElse true } - // override because Dotty currently doesn't handle separate compilation well, - // so we ignore groups (tests suffixed with _1 and _2) - 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 that throws exception - if (flatGroup != super.groupedFiles(sources)) - throw new java.lang.UnsupportedOperationException() - } catch { - 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 - } - - // override to avoid separate compilation of scala and java sources - override def mixedCompileGroup(allFiles: List[File]): List[CompileRound] = List(OnlyDotty(allFiles)) - case class OnlyDotty(fs: List[File]) extends CompileRound { - def description = s"dotc $fsString" - lazy val result = { pushTranscript(description) ; attemptCompile(fs) } - } - // override to add dotty and scala jars to classpath override def extraClasspath = suiteRunner.fileManager.asInstanceOf[DottyFileManager].extraJarList ::: super.extraClasspath diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala index 1d8fb9bf5..56b9e1099 100644 --- a/test/test/CompilerTest.scala +++ b/test/test/CompilerTest.scala @@ -410,7 +410,8 @@ abstract class CompilerTest { nr: Int = 0, oldOutput: String = defaultOutputDir): Unit = { val partestOutput = dest.jfile.getParentFile + JFile.separator + dest.stripExtension + "-" + kind + ".obj" - val flags = oldFlags.map(f => if (f == oldOutput) partestOutput else f) + val flags = oldFlags.map(f => if (f == oldOutput) partestOutput else f) ++ + List(s"-classpath $partestOutput") // Required for separate compilation tests getExisting(dest).isDifferent(source, flags, nerr) match { case NotExists => copyFiles(source, dest, partestOutput, flags, nerr, kind) -- cgit v1.2.3 From 8c35854f9167a7cedd85e4601cadb9f422a83a5e Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Thu, 2 Jun 2016 23:58:42 +0200 Subject: partest: put more stuff on javac classpath Some java tests require the scala-library to be present on the classpath, this fixes tests/pos/java-interop/{t1186, t1235, t1254, t1642}. Also correctly redirect the output of javac so that it will be displayed by partest --verbose --- test/dotty/partest/DPConsoleRunner.scala | 56 ++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'test') diff --git a/test/dotty/partest/DPConsoleRunner.scala b/test/dotty/partest/DPConsoleRunner.scala index c939e6704..d445722c9 100644 --- a/test/dotty/partest/DPConsoleRunner.scala +++ b/test/dotty/partest/DPConsoleRunner.scala @@ -134,6 +134,62 @@ class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runn // override to provide DottyCompiler override def newCompiler = new dotty.partest.DPDirectCompiler(this) + // Adapted from nest.Runner#javac because: + // - Our classpath handling is different and we need to pass extraClassPath + // to java to get the scala-library which is required for some java tests + // - The compiler output should be redirected to cLogFile, like the output of + // dotty itself + override def javac(files: List[File]): TestState = { + import fileManager._ + import suiteRunner._ + import FileManager.joinPaths + // compile using command-line javac compiler + val args = Seq( + javacCmdPath, + "-d", + outDir.getAbsolutePath, + "-classpath", + joinPaths(outDir :: extraClasspath ++ testClassPath) + ) ++ files.map(_.getAbsolutePath) + + pushTranscript(args mkString " ") + + val captured = StreamCapture(runCommand(args, cLogFile)) + if (captured.result) genPass() else { + cLogFile appendAll captured.stderr + cLogFile appendAll captured.stdout + genFail("java compilation failed") + } + } + + // FIXME: This is copy-pasted from nest.Runner where it is private + // Remove this once https://github.com/scala/scala-partest/pull/61 is merged + /** Runs command redirecting standard out and + * error out to output file. + */ + def runCommand(args: Seq[String], outFile: File): Boolean = { + import scala.sys.process.{ Process, ProcessLogger } + //(Process(args) #> outFile !) == 0 or (Process(args) ! pl) == 0 + val pl = ProcessLogger(outFile) + val nonzero = 17 // rounding down from 17.3 + def run: Int = { + val p = Process(args) run pl + try p.exitValue + catch { + case e: InterruptedException => + NestUI verbose s"Interrupted waiting for command to finish (${args mkString " "})" + p.destroy + nonzero + case t: Throwable => + NestUI verbose s"Exception waiting for command to finish: $t (${args mkString " "})" + p.destroy + throw t + } + finally pl.close() + } + (pl buffer run) == 0 + } + // override to provide default dotty flags from file in directory override def flagsForCompilation(sources: List[File]): List[String] = { val specificFlags = super.flagsForCompilation(sources) -- cgit v1.2.3