From 06a3d47ea9fd1b67b3acba9d115a16d18549e377 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Wed, 26 Oct 2016 16:19:35 +0200 Subject: Move sjs, make sure that partest compiles everything in dirs --- test/dotc/tests.scala | 55 ++++++++--------- test/dotty/partest/DPConsoleRunner.scala | 102 +++++++++++-------------------- test/test/CompilerTest.scala | 27 +++++--- 3 files changed, 78 insertions(+), 106 deletions(-) (limited to 'test') diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index 747396c73..d96111dee 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -3,6 +3,7 @@ package dotc import test._ import org.junit.{Before, Test} +import java.io.{ File => JFile } import scala.reflect.io.Directory import scala.io.Source @@ -23,20 +24,34 @@ class tests extends CompilerTest { "-d", defaultOutputDir ) - val classPath = List( + val checkOptions = List( "-Yno-deep-subtypes", "-Yno-double-bindings", "-Yforce-sbt-phases", - "-color:never", - "-classpath", - "./library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar" + - ":./interfaces/target/dotty-interfaces-0.1-SNAPSHOT.jar" + "-color:never" ) + val classPath = { + val paths = List( + "./library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar", + "./target/scala-2.11/dotty-compiler_2.11-0.1-SNAPSHOT.jar", + "./interfaces/target/dotty-interfaces-0.1-SNAPSHOT.jar" + ).map { p => + val file = new JFile(p) + assert( + file.exists, + s"""File "$p" couldn't be found. Run `packageAll` from build tool before testing""" + ) + file.getAbsolutePath + }.mkString(":") + + List("-classpath", paths) + } + implicit val defaultOptions = noCheckOptions ++ { if (isRunByJenkins) List("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef") // should be Ycheck:all, but #725 else List("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef") - } ++ classPath + } ++ checkOptions ++ classPath val testPickling = List("-Xprint-types", "-Ytest-pickler", "-Ystop-after:pickler", "-Yprintpos") @@ -189,32 +204,10 @@ class tests extends CompilerTest { @Test def compileIndexedSeq = compileLine("./scala-scala/src/library/scala/collection/immutable/IndexedSeq.scala") // Not a junit test anymore since it is order dependent - def dottyBootedLib = compileDir( - libDir, - ".", - List( - "-deep", "-Ycheck-reentrant", "-strict", "-classpath", defaultOutputDir + - ":./target/scala-2.11/dotty-compiler_2.11-0.1-SNAPSHOT.jar" + - ":./interfaces/target/dotty-interfaces-0.1-SNAPSHOT.jar" + - ":./library/target/scala-2.11/dotty-library_2.11-0.1-SNAPSHOT.jar" - ) - )(allowDeepSubtypes) // note the -deep argument + def dottyBootedLib = compileDir(libDir, ".")(allowDeepSubtypes) // note the -deep argument // Not a junit test anymore since it is order dependent - def dottyDependsOnBootedLib = compileDir( - dottyDir, - ".", - List( - "-deep", "-Ycheck-reentrant", "-strict", "-classpath", defaultOutputDir + - ":./dotty-lib.jar" + - ":./interfaces/target/dotty-interfaces-0.1-SNAPSHOT.jar" + - // this needs to get compiled together with the compiler: - //":./target/scala-2.11/src_managed/main/scalajs-ir-src/" - // but falling back to: - ":/home/fixel/.ivy2/cache/org.scala-js/scalajs-ir_2.11/jars/scalajs-ir_2.11-0.6.8.jar" - // for the time being. - ) - )(allowDeepSubtypes) // note the -deep argument + @Test def dottyDependsOnBootedLib = compileDir(dottyDir, ".")(allowDeepSubtypes) // note the -deep argument @Test def dotc_ast = compileDir(dotcDir, "ast") @Test def dotc_config = compileDir(dotcDir, "config") @@ -279,7 +272,7 @@ class tests extends CompilerTest { "scalaPrimitives.scala" ) map (s"${backendDir}jvm/" + _), testPickling) - @Test def tasty_backend_sjs = compileDir(s"${backendDir}", "sjs", testPickling) + //@Test def tasty_backend_sjs = compileDir(s"${backendDir}", "sjs", testPickling) @Test def tasty_dotc = compileDir(toolsDir, "dotc", testPickling) @Test def tasty_dotc_ast = compileDir(dotcDir, "ast", testPickling) diff --git a/test/dotty/partest/DPConsoleRunner.scala b/test/dotty/partest/DPConsoleRunner.scala index 27d53159b..4552d1137 100644 --- a/test/dotty/partest/DPConsoleRunner.scala +++ b/test/dotty/partest/DPConsoleRunner.scala @@ -30,10 +30,6 @@ object DPConsoleRunner { case Nil => sys.error("Error: DPConsoleRunner needs \"-dottyJars *\".") case jarFinder(nr, jarString) :: Nil => val jars = jarString.split(" ").toList - println("------------------------------------------------------------") - println("jars:") - jars.foreach(println) - println("------------------------------------------------------------") val count = nr.toInt if (jars.length < count) sys.error("Error: DPConsoleRunner found wrong number of dottyJars: " + jars + ", expected: " + nr) @@ -155,11 +151,7 @@ class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runn "-d", outDir.getAbsolutePath, "-classpath", - joinPaths(outDir :: extraClasspath.filter { fp => - fp.endsWith("dotty-lib.jar") || - fp.endsWith("scala-library-2.11.5.jar") || - fp.endsWith("scala-reflect-2.11.5.jar") - }) + joinPaths(outDir :: extraClasspath ++ testClassPath) ) ++ files.map(_.getAbsolutePath) pushTranscript(args mkString " ") @@ -172,58 +164,35 @@ class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runn } } - override def run(): TestState = { - if (kind == "run") { - // javac runner, for one, would merely append to an existing log file, so - // just delete it before we start - logFile.delete() - runTestCommon(execTest(outDir, logFile) && diffIsOk) - lastState - } else super.run() - } - - // Re-implemented for running tests - def execTest(outDir: File, logFile: File): Boolean = { - val argsFile = testFile changeExtension "javaopts" - val argString = file2String(argsFile) - if (argString != "") NestUI.verbose( - "Found javaopts file '%s', using options: '%s'".format(argsFile, argString) - ) - - val classpath = joinPaths { - val sep = sys.props("path.separator") - val fps = extraClasspath.filter { fp => - fp.endsWith("dotty-lib.jar") || - fp.endsWith("scala-library-2.11.5.jar") || - fp.endsWith("scala-reflect-2.11.5.jar") + // Overriden in order to recursively get all sources that should be handed to + // the compiler. Otherwise only sources in the top dir is compiled - works + // because the compiler is on the classpath. + override def sources(file: File): List[File] = + if (file.isDirectory) + file.listFiles.toList.flatMap { f => + if (f.isDirectory) sources(f) + else if (f.isJavaOrScala) List(f) + else Nil } - - fps ++ fileManager.testClassPath - } - - val javaOpts: List[String] = ( - suiteRunner.javaOpts.split(' ') ++ - extraJavaOptions ++ - argString.split(' ') - ).map(_.trim).filter(_ != "").toList - - val cmd: List[String] = (suiteRunner.javaCmdPath :: javaOpts) ++ ( - "-classpath" :: join(outDir.toString, classpath) :: - "Test" :: "jvm" :: // default argument to Test class in super is "jvm" - Nil - ) - - pushTranscript((cmd mkString s" \\$EOL ") + " > " + logFile.getName) - nextTestAction(runCommand(cmd, logFile)) { - case false => - //_transcript append EOL + logFile.fileContents - // think this is equivalent: - val contents = logFile.fileContents - println(contents) - pushTranscript(contents) - genFail("non-zero exit code") - } - } + else List(file) + + // Enable me to "fix" the depth issue - remove once completed + //override def compilationRounds(file: File): List[CompileRound] = { + // val srcs = sources(file) match { + // case Nil => + // System.err.println { + // s"""|================================================================================ + // |Warning! You attempted to compile sources from: + // | $file + // |but partest was unable to find any sources - uncomment DPConsoleRunner#sources + // |================================================================================""".stripMargin + // } + // List(new File("./examples/hello.scala")) // "just compile some crap" - Guillaume + // case xs => + // xs + // } + // (groupedFiles(srcs) map mixedCompileGroup).flatten + //} // 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 @@ -371,16 +340,17 @@ class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runn } // override to add dotty and scala jars to classpath - override def extraClasspath = { - val cp = suiteRunner.fileManager.asInstanceOf[DottyFileManager].extraJarList ::: super.extraClasspath - //println(s"extraClasspath: $cp") - cp - } + override def extraClasspath = + suiteRunner.fileManager.asInstanceOf[DottyFileManager].extraJarList ::: super.extraClasspath // override to keep class files if failed and delete clog if ok - override def cleanup = if (lastState.isOk) { + override def cleanup = if (lastState.isOk) try { logFile.delete cLogFile.delete Directory(outDir).deleteRecursively + } catch { + case t: Throwable => + println("whhhhhhhhhhhhhhhhhhhhhhhhhhhaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat") + throw t } } diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala index 5a4a9830a..05a7d62b8 100644 --- a/test/test/CompilerTest.scala +++ b/test/test/CompilerTest.scala @@ -442,8 +442,14 @@ 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) ++ - List(s"-classpath $partestOutput") // Required for separate compilation tests + + val altOutput = + source.getParentFile.getAbsolutePath.map(x => if (x == JFile.separatorChar) '_' else x) + + val (beforeCp, remaining) = oldFlags + .map(f => if (f == oldOutput) partestOutput else f) + .span(_ != "-classpath") + val flags = beforeCp ++ List("-classpath", (partestOutput :: remaining.drop(1)).mkString(":")) val difference = getExisting(dest).isDifferent(source, flags, nerr) difference match { @@ -451,8 +457,12 @@ abstract class CompilerTest { case ExistsSame => // nothing else to do case ExistsDifferent => val nextDest = dest.parent / (dest match { - case d: Directory => Directory(replaceVersion(d.name, nr)) - case f => SFile(replaceVersion(f.stripExtension, nr)).addExtension(f.extension) + case d: Directory => + val newVersion = replaceVersion(d.name, nr).getOrElse(altOutput) + Directory(newVersion) + case f => + val newVersion = replaceVersion(f.stripExtension, nr).getOrElse(altOutput) + SFile(newVersion).addExtension(f.extension) }) computeDestAndCopyFiles(source, nextDest, kind, flags, nerr, nr + 1, partestOutput) } @@ -555,13 +565,12 @@ abstract class CompilerTest { import scala.util.matching.Regex val nrFinder = """(.*_v)(\d+)""".r /** Changes the version number suffix in the name (without extension). */ - private def replaceVersion(name: String, nr: Int): String = { + private def replaceVersion(name: String, nr: Int): Option[String] = { val nrString = nr.toString name match { - case nrFinder(prefix, `nrString`) => prefix + (nr + 1) - case _ => - assert(nr == 0, "DPCompilerTest couldn't create new version of files, match error") - name + "_v1" + case nrFinder(prefix, `nrString`) => Some(prefix + (nr + 1)) + case _ if nr != 0 => None + case _ => Some(name + "_v1") } } -- cgit v1.2.3