From b7589adec04d2a8f7f22743f344897693f7a3730 Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Wed, 7 May 2008 17:47:27 +0000 Subject: partest now interprets scalac options passed in... partest now interprets scalac options passed in property scalatest.scalac_opts. The compiler/lib build to test can now be specified using the property scalatest.build. Added a partest option for running on JVM 1.4 (--four). --- .../scala/tools/partest/nest/CompileManager.scala | 10 +- .../tools/partest/nest/ConsoleFileManager.scala | 114 ++++++++++++--------- .../scala/tools/partest/nest/ConsoleRunner.scala | 17 +-- .../scala/tools/partest/nest/FileManager.scala | 1 + .../tools/partest/nest/ReflectiveRunner.scala | 43 +++++--- 5 files changed, 113 insertions(+), 72 deletions(-) (limited to 'src/partest') diff --git a/src/partest/scala/tools/partest/nest/CompileManager.scala b/src/partest/scala/tools/partest/nest/CompileManager.scala index 07c88ccc34..5da1913c1c 100644 --- a/src/partest/scala/tools/partest/nest/CompileManager.scala +++ b/src/partest/scala/tools/partest/nest/CompileManager.scala @@ -7,7 +7,7 @@ package scala.tools.partest.nest -import scala.tools.nsc.{Global, Settings} +import scala.tools.nsc.{Global, Settings, CompilerCommand} import scala.tools.nsc.reporters.{Reporter, ConsoleReporter} import java.io.{File, BufferedReader, PrintWriter, FileWriter, StringWriter} @@ -51,7 +51,9 @@ class DirectCompiler(val fileManager: FileManager) extends SimpleCompiler { def compile(file: File, kind: String, log: File): Boolean = { val testSettings = newSettings val logWriter = new FileWriter(log) - val global = newGlobal(testSettings, logWriter) + val args = List.fromArray(fileManager.SCALAC_OPTS.split("\\s")) + val command = new CompilerCommand(args, testSettings, x => {}, false) + val global = newGlobal(command.settings, logWriter) val testRep: ExtConsoleReporter = global.reporter.asInstanceOf[ExtConsoleReporter] val test: TestFile = kind match { @@ -83,7 +85,9 @@ class DirectCompiler(val fileManager: FileManager) extends SimpleCompiler { def compile(file: File, kind: String): Boolean = { val testSettings = newSettings val testRep = newReporter(testSettings) - val global = newGlobal(testSettings, testRep) + val args = List.fromArray(fileManager.SCALAC_OPTS.split("\\s")) + val command = new CompilerCommand(args, testSettings, x => {}, false) + val global = newGlobal(command.settings, testRep) val test: TestFile = kind match { case "pos" => PosTestFile(file, fileManager) diff --git a/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala b/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala index 5bcee60ff1..4ac3e365f5 100644 --- a/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala +++ b/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala @@ -12,6 +12,25 @@ import java.net.URI class ConsoleFileManager extends FileManager { + var testBuild = System.getProperty("scalatest.build") + + val debug: Boolean = + (System.getProperty("partest.debug", "false") equals "true") || + (System.getProperty("scalatest.debug", "false") equals "true") + + def this(build: String) = { + this() + testBuild = build + // re-run because initialization of default + // constructor must be updated + findLatest() + } + + def this(build: String, moreOpts: String) = { + this(build) + SCALAC_OPTS = SCALAC_OPTS+" "+moreOpts + } + var CLASSPATH = System.getProperty("java.class.path", ".") NestUI.verbose("CLASSPATH: "+CLASSPATH) @@ -25,10 +44,6 @@ class ConsoleFileManager extends FileManager { } val PREFIX = prefixFile.getAbsolutePath - val debug: Boolean = - (System.getProperty("partest.debug", "false") equals "true") || - (System.getProperty("scalatest.debug", "false") equals "true") - /* if [ -d "$PREFIX/test" ]; then TESTROOT="$PREFIX/test"; @@ -73,6 +88,7 @@ else def findLatest() { val testParent = testRootFile.getParentFile + NestUI.verbose("test parent: "+testParent) def prefixFileWith(parent: File, relPath: String): File = { (new File(parent, relPath)).getCanonicalFile @@ -82,47 +98,55 @@ else prefixFileWith(testParent, relPath) } - NestUI.verbose("test parent: "+testParent) - val dists = new File(testParent, "dists") - val build = new File(testParent, "build") - // in case of an installed dist, testRootFile is one level deeper - val bin = new File(testParent.getParentFile, "bin") - - if (dists.isDirectory) { - NestUI.verbose("Running on DISTRIBUTION") - latestFile = prefixFile("dists/latest/bin") - latestLibFile = prefixFile("dists/latest/lib/scala-library.jar") - latestActFile = prefixFile("dists/latest/lib/scala-library.jar") - latestCompFile = prefixFile("dists/latest/lib/scala-compiler.jar") - latestPartestFile = prefixFile("dists/latest/lib/scala-partest.jar") - } - else if (build.isDirectory && (new File(build, "pack/lib/scala-library.jar")).exists) { - NestUI.verbose("Running on SuperSABBUS PACK") - latestFile = prefixFile("build/pack/bin") - latestLibFile = prefixFile("build/pack/lib/scala-library.jar") - latestActFile = prefixFile("build/pack/lib/scala-library.jar") - latestCompFile = prefixFile("build/pack/lib/scala-compiler.jar") - latestPartestFile = prefixFile("build/pack/lib/scala-partest.jar") - } - else if (build.isDirectory) { - NestUI.verbose("Running on SABBUS QUICK") - latestFile = prefixFile("build/quick/bin") - latestLibFile = prefixFile("build/quick/lib/library") - latestActFile = prefixFile("build/quick/lib/actors") - latestCompFile = prefixFile("build/quick/lib/compiler") - latestPartestFile = prefixFile("build/quick/lib/partest") - } - else if (bin.isDirectory) { - NestUI.verbose("Running on INSTALLED DIST") - val p = testParent.getParentFile - latestFile = prefixFileWith(p, "bin") - latestLibFile = prefixFileWith(p, "lib/scala-library.jar") - latestActFile = prefixFileWith(p, "lib/scala-library.jar") - latestCompFile = prefixFileWith(p, "lib/scala-compiler.jar") - latestPartestFile = prefixFileWith(p, "lib/scala-partest.jar") + if (testBuild != null) { + NestUI.verbose("Running on "+testBuild) + latestFile = prefixFile(testBuild+"/bin") + latestLibFile = prefixFile(testBuild+"/lib/scala-library.jar") + latestActFile = prefixFile(testBuild+"/lib/scala-library.jar") + latestCompFile = prefixFile(testBuild+"/lib/scala-compiler.jar") + latestPartestFile = prefixFile(testBuild+"/lib/scala-partest.jar") + } else { + val dists = new File(testParent, "dists") + val build = new File(testParent, "build") + // in case of an installed dist, testRootFile is one level deeper + val bin = new File(testParent.getParentFile, "bin") + + if (dists.isDirectory) { + NestUI.verbose("Running on DISTRIBUTION") + latestFile = prefixFile("dists/latest/bin") + latestLibFile = prefixFile("dists/latest/lib/scala-library.jar") + latestActFile = prefixFile("dists/latest/lib/scala-library.jar") + latestCompFile = prefixFile("dists/latest/lib/scala-compiler.jar") + latestPartestFile = prefixFile("dists/latest/lib/scala-partest.jar") + } + else if (build.isDirectory && (new File(build, "pack/lib/scala-library.jar")).exists) { + NestUI.verbose("Running on SuperSABBUS PACK") + latestFile = prefixFile("build/pack/bin") + latestLibFile = prefixFile("build/pack/lib/scala-library.jar") + latestActFile = prefixFile("build/pack/lib/scala-library.jar") + latestCompFile = prefixFile("build/pack/lib/scala-compiler.jar") + latestPartestFile = prefixFile("build/pack/lib/scala-partest.jar") + } + else if (build.isDirectory) { + NestUI.verbose("Running on SABBUS QUICK") + latestFile = prefixFile("build/quick/bin") + latestLibFile = prefixFile("build/quick/lib/library") + latestActFile = prefixFile("build/quick/lib/actors") + latestCompFile = prefixFile("build/quick/lib/compiler") + latestPartestFile = prefixFile("build/quick/lib/partest") + } + else if (bin.isDirectory) { + NestUI.verbose("Running on INSTALLED DIST") + val p = testParent.getParentFile + latestFile = prefixFileWith(p, "bin") + latestLibFile = prefixFileWith(p, "lib/scala-library.jar") + latestActFile = prefixFileWith(p, "lib/scala-library.jar") + latestCompFile = prefixFileWith(p, "lib/scala-compiler.jar") + latestPartestFile = prefixFileWith(p, "lib/scala-partest.jar") + } + else + error("Scala binaries could not be found") } - else - error("Scala binaries could not be found") BIN_DIR = latestFile.getAbsolutePath LATEST_LIB = latestLibFile.getAbsolutePath @@ -149,8 +173,6 @@ else var SCALA: String = "" var SCALAC_CMD: String = "" - val SCALAC_OPTS = System.getProperty("scalatest.scalac_opts", "-deprecation") - var latestFile: File = _ var latestLibFile: File = _ var latestActFile: File = _ diff --git a/src/partest/scala/tools/partest/nest/ConsoleRunner.scala b/src/partest/scala/tools/partest/nest/ConsoleRunner.scala index bc03877310..67f698ab82 100644 --- a/src/partest/scala/tools/partest/nest/ConsoleRunner.scala +++ b/src/partest/scala/tools/partest/nest/ConsoleRunner.scala @@ -15,7 +15,7 @@ import scala.actors.Actor._ class ConsoleRunner extends DirectRunner { - val fileManager: ConsoleFileManager = new ConsoleFileManager + var fileManager: ConsoleFileManager = _ private val version = System.getProperty("java.version", "") private val isJava5 = version matches "1.[5|6|7].*" @@ -53,15 +53,20 @@ class ConsoleRunner extends DirectRunner { def main(argstr: String) { // tokenize args - var args: List[String] = List() - val st = new StringTokenizer(argstr) - while (st.hasMoreTokens) { - args = args ::: List(st.nextToken()) - } + var args = List.fromArray(argstr.split("\\s")) if (args.length == 0) NestUI.usage() else { + // create a file manager + fileManager = + if (args contains "--pack") + new ConsoleFileManager("build/pack") + else if (args contains "--four") + new ConsoleFileManager("build/four-pack", "-target:jvm-1.4") + else // auto detection + new ConsoleFileManager + if (!args.exists(denotesTestSet(_)) && !args.exists(_.endsWith(".scala"))) runAll = true for (arg <- args) { arg match { diff --git a/src/partest/scala/tools/partest/nest/FileManager.scala b/src/partest/scala/tools/partest/nest/FileManager.scala index f83882d078..5de1aeb538 100644 --- a/src/partest/scala/tools/partest/nest/FileManager.scala +++ b/src/partest/scala/tools/partest/nest/FileManager.scala @@ -53,4 +53,5 @@ trait FileManager { var showLog = false var failed = false + var SCALAC_OPTS = System.getProperty("scalatest.scalac_opts", "-deprecation") } diff --git a/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala b/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala index f7476d2772..2870d79418 100644 --- a/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala +++ b/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala @@ -19,29 +19,38 @@ class ReflectiveRunner { // to use the same classes as used by `scala` that // was used to start the runner. - val fileManager = new ConsoleFileManager + def main(args: String) { + val argList = List.fromArray(args.split("\\s")) - import fileManager.{latestCompFile, latestLibFile, latestActFile, - latestPartestFile} + // find out which build to test + val fileManager = + if (argList contains "--pack") + new ConsoleFileManager("build/pack") + else if (argList contains "--four") + new ConsoleFileManager("build/four-pack", "-target:jvm-1.4") + else // auto detection + new ConsoleFileManager - val sepUrls = Array(latestCompFile.toURL, latestLibFile.toURL, - latestActFile.toURL, latestPartestFile.toURL) - val sepLoader = new java.net.URLClassLoader(sepUrls, null) + import fileManager.{latestCompFile, latestLibFile, latestActFile, + latestPartestFile} - if (fileManager.debug) { - println("Loading classes from:") - sepUrls foreach { url => println(url) } - } + val sepUrls = Array(latestCompFile.toURL, latestLibFile.toURL, + latestActFile.toURL, latestPartestFile.toURL) + val sepLoader = new java.net.URLClassLoader(sepUrls, null) - val sepRunnerClass = - sepLoader.loadClass("scala.tools.partest.nest.ConsoleRunner") - val sepRunner = sepRunnerClass.newInstance() + if (fileManager.debug) { + println("Loading classes from:") + sepUrls foreach { url => println(url) } + } - val stringClass = Class.forName("java.lang.String") - val sepMainMethod = - sepRunnerClass.getMethod("main", Array(stringClass)) + val sepRunnerClass = + sepLoader.loadClass("scala.tools.partest.nest.ConsoleRunner") + val sepRunner = sepRunnerClass.newInstance() + + val stringClass = Class.forName("java.lang.String") + val sepMainMethod = + sepRunnerClass.getMethod("main", Array(stringClass)) - def main(args: String) { val cargs: Array[AnyRef] = Array(args) sepMainMethod.invoke(sepRunner, cargs) } -- cgit v1.2.3