diff options
Diffstat (limited to 'src/partest')
10 files changed, 179 insertions, 174 deletions
diff --git a/src/partest/scala/tools/partest/PartestTask.scala b/src/partest/scala/tools/partest/PartestTask.scala index 45f1ebc2f1..65858d16ea 100644 --- a/src/partest/scala/tools/partest/PartestTask.scala +++ b/src/partest/scala/tools/partest/PartestTask.scala @@ -11,6 +11,7 @@ package scala.tools.partest import scala.actors.Actor._ +import util.Properties.setProp import java.io.File import java.net.URLClassLoader @@ -166,7 +167,7 @@ class PartestTask extends Task { override def execute() { if (isPartestDebug) - System.setProperty("partest.debug", "true") + setProp("partest.debug", "true") if (classpath.isEmpty) error("Mandatory attribute 'classpath' is not set.") diff --git a/src/partest/scala/tools/partest/nest/CompileManager.scala b/src/partest/scala/tools/partest/nest/CompileManager.scala index 63acf654e2..517620e958 100644 --- a/src/partest/scala/tools/partest/nest/CompileManager.scala +++ b/src/partest/scala/tools/partest/nest/CompileManager.scala @@ -141,36 +141,36 @@ class DirectCompiler(val fileManager: FileManager) extends SimpleCompiler { } } -class ReflectiveCompiler(val fileManager: ConsoleFileManager) extends SimpleCompiler { - import fileManager.{latestCompFile, latestPartestFile} - - val sepUrls = Array(latestCompFile.toURI.toURL, latestPartestFile.toURI.toURL) - //NestUI.verbose("constructing URLClassLoader from URLs "+latestCompFile+" and "+latestPartestFile) - - val sepLoader = new java.net.URLClassLoader(sepUrls, null) - - val sepCompilerClass = - sepLoader.loadClass("scala.tools.partest.nest.DirectCompiler") - val sepCompiler = sepCompilerClass.newInstance() - - // needed for reflective invocation - val fileClass = Class.forName("java.io.File") - val stringClass = Class.forName("java.lang.String") - val sepCompileMethod = - sepCompilerClass.getMethod("compile", fileClass, stringClass) - val sepCompileMethod2 = - sepCompilerClass.getMethod("compile", fileClass, stringClass, fileClass) - - /* This method throws java.lang.reflect.InvocationTargetException - * if the compiler crashes. - * This exception is handled in the shouldCompile and shouldFailCompile - * methods of class CompileManager. - */ - def compile(out: Option[File], files: List[File], kind: String, log: File): Boolean = { - val res = sepCompileMethod2.invoke(sepCompiler, out, files, kind, log).asInstanceOf[java.lang.Boolean] - res.booleanValue() - } -} +// class ReflectiveCompiler(val fileManager: ConsoleFileManager) extends SimpleCompiler { +// import fileManager.{latestCompFile, latestPartestFile} +// +// val sepUrls = Array(latestCompFile.toURI.toURL, latestPartestFile.toURI.toURL) +// //NestUI.verbose("constructing URLClassLoader from URLs "+latestCompFile+" and "+latestPartestFile) +// +// val sepLoader = new java.net.URLClassLoader(sepUrls, null) +// +// val sepCompilerClass = +// sepLoader.loadClass("scala.tools.partest.nest.DirectCompiler") +// val sepCompiler = sepCompilerClass.newInstance() +// +// // needed for reflective invocation +// val fileClass = Class.forName("java.io.File") +// val stringClass = Class.forName("java.lang.String") +// val sepCompileMethod = +// sepCompilerClass.getMethod("compile", fileClass, stringClass) +// val sepCompileMethod2 = +// sepCompilerClass.getMethod("compile", fileClass, stringClass, fileClass) +// +// /* This method throws java.lang.reflect.InvocationTargetException +// * if the compiler crashes. +// * This exception is handled in the shouldCompile and shouldFailCompile +// * methods of class CompileManager. +// */ +// def compile(out: Option[File], files: List[File], kind: String, log: File): Boolean = { +// val res = sepCompileMethod2.invoke(sepCompiler, out, files, kind, log).asInstanceOf[java.lang.Boolean] +// res.booleanValue() +// } +// } class CompileManager(val fileManager: FileManager) { var compiler: SimpleCompiler = new /*ReflectiveCompiler*/ DirectCompiler(fileManager) diff --git a/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala b/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala index 258651e0ce..c5d67fb4e2 100644 --- a/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala +++ b/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala @@ -10,16 +10,27 @@ package nest import java.io.{ File, FilenameFilter, IOException, StringWriter } import java.net.URI +import scala.util.Properties.{ propOrElse, scalaCmd, scalacCmd } import scala.tools.util.PathResolver -import scala.tools.nsc.io +import scala.tools.nsc.{ Settings } +import scala.tools.nsc.{ io, util } +import util.{ ClassPath } import io.{ Path, Directory } import File.pathSeparator -import PathResolver.{ propOrElse } +import ClassPath.{ join } +import PathResolver.{ Environment, Defaults } +import RunnerUtils._ + +object ConsoleFileManager { + def testRootPropDir = Option(propOrElse("scalatest.root", null)) map (x => Directory(x)) +} +import ConsoleFileManager._ class ConsoleFileManager extends FileManager { - implicit private def tempPathConversion(x: Path): File = x.jfile + implicit private def temporaryPath2File(x: Path): File = x.jfile + implicit private def temporaryFile2Path(x: File): Path = Path(x) - var testBuild: Option[String] = Option(System.getProperty("scalatest.build")) + var testBuild: Option[String] = PartestDefaults.testBuild def testBuildFile = testBuild map (testParent / _) var testClasses: Option[String] = None @@ -44,15 +55,15 @@ class ConsoleFileManager extends FileManager { SCALAC_OPTS = SCALAC_OPTS+" "+moreOpts } - var CLASSPATH = PathResolver.Environment.javaUserClassPath + var CLASSPATH = PartestDefaults.classPath + var JAVACMD = PartestDefaults.javaCmd + var JAVAC_CMD = PartestDefaults.javacCmd NestUI.verbose("CLASSPATH: "+CLASSPATH) - var JAVACMD = propOrElse("scalatest.javacmd", "java") - var JAVAC_CMD = propOrElse("scalatest.javac_cmd", "javac") - - val prefixDir = Directory.Current map (_.normalize.toDirectory) getOrElse error("user.dir property not set") - val PREFIX = prefixDir.toAbsolute.path + val prefixDir = PartestDefaults.prefixDir getOrElse error("user.dir property not set") + val srcDirName = PartestDefaults.srcDirName + val PREFIX = prefixDir.toAbsolute.path /* if [ -d "$PREFIX/test" ]; then @@ -64,11 +75,10 @@ else */ val testRootDir = { - val testRootProp = Option(propOrElse("scalatest.root", null)) map (x => Directory(x)) def isTestDir(d: Directory) = d.name == "test" && (d / "files" isDirectory) ( - testRootProp orElse ( + testRootPropDir orElse ( if (isTestDir(prefixDir)) Some(prefixDir) else None // cwd is `test` ) orElse ( (prefixDir / "test") ifDirectory (x => x) // cwd is `test/..` @@ -83,19 +93,14 @@ else def testParent = testRootDir.parent - var srcDirName: String = "" + val srcDir = (testRootDir / srcDirName).toDirectory - val srcDir: io.Directory = { - srcDirName = Option(System.getProperty("partest.srcdir")) getOrElse "files" - val src = testRootDir / srcDirName - - if (src.isDirectory) src.toDirectory - else { - NestUI.failure("Source directory \"" + src.path + "\" not found") - exit(1) - } + if (!srcDir.isDirectory) { + NestUI.failure("Source directory \"" + srcDir.path + "\" not found") + exit(1) } + LIB_DIR = (testParent / "lib").normalize.toAbsolute.path CLASSPATH = { @@ -195,13 +200,8 @@ else LATEST_COMP = latestCompFile.getAbsolutePath LATEST_PARTEST = latestPartestFile.getAbsolutePath - import util.Properties.isWin - - val scalaCommand = if (isWin) "scala.bat" else "scala" - val scalacCommand = if (isWin) "scalac.bat" else "scalac" - - SCALA = (new File(latestFile, scalaCommand)).getAbsolutePath - SCALAC_CMD = (new File(latestFile, scalacCommand)).getAbsolutePath + SCALA = (latestFile / scalaCmd).toAbsolute.path + SCALAC_CMD = (latestFile / scalacCmd).toAbsolute.path } var BIN_DIR: String = "" diff --git a/src/partest/scala/tools/partest/nest/ConsoleRunner.scala b/src/partest/scala/tools/partest/nest/ConsoleRunner.scala index 9e582bb1cd..8542e08071 100644 --- a/src/partest/scala/tools/partest/nest/ConsoleRunner.scala +++ b/src/partest/scala/tools/partest/nest/ConsoleRunner.scala @@ -11,13 +11,14 @@ package nest import java.io.{File, PrintStream, FileOutputStream, BufferedReader, InputStreamReader, StringWriter, PrintWriter} import utils.Properties._ -import scala.tools.nsc.Properties.versionMsg +import RunnerUtils._ +import scala.tools.nsc.Properties.{ versionMsg, setProp } import scala.tools.nsc.util.CommandLineParser import scala.tools.nsc.io import scala.tools.nsc.interpreter.returning import io.{ Path } -class ConsoleRunner extends DirectRunner with RunnerUtils { +class ConsoleRunner extends DirectRunner { case class TestSet(loc: String, filter: Option[(String, Boolean)], @@ -45,8 +46,7 @@ class ConsoleRunner extends DirectRunner with RunnerUtils { var fileManager: ConsoleFileManager = _ private var testFiles: List[File] = List() - private val errors = - Integer.parseInt(System.getProperty("scalatest.errors", "0")) + private val errors = PartestDefaults.errorCount private val testSetArgMap = testSets map (x => ("--" + x.loc) -> x) toMap private val testSetArgs = testSets map ("--" + _.loc) @@ -75,7 +75,7 @@ class ConsoleRunner extends DirectRunner with RunnerUtils { return NestUI.usage() } - parsed get "--srcpath" foreach (x => System.setProperty("partest.srcdir", x)) + parsed get "--srcpath" foreach (x => setProp("partest.srcdir", x)) fileManager = if (parsed isSet "--buildpath") new ConsoleFileManager(parsed("--buildpath")) diff --git a/src/partest/scala/tools/partest/nest/DirectRunner.scala b/src/partest/scala/tools/partest/nest/DirectRunner.scala index 3778a927df..1dd0d5a9aa 100644 --- a/src/partest/scala/tools/partest/nest/DirectRunner.scala +++ b/src/partest/scala/tools/partest/nest/DirectRunner.scala @@ -11,6 +11,7 @@ package nest import java.io.{File, PrintStream, FileOutputStream, BufferedReader, InputStreamReader, StringWriter, PrintWriter} import java.util.StringTokenizer +import scala.util.Properties.{ setProp } import scala.tools.nsc.io.Directory import scala.actors.Actor._ @@ -20,20 +21,14 @@ trait DirectRunner { def fileManager: FileManager - private val numActors = Integer.parseInt(System.getProperty("scalatest.actors", "8")) + import PartestDefaults.numActors if (isPartestDebug) scala.actors.Debug.level = 3 - private val coreProp = try { - System.getProperty("actors.corePoolSize") - } catch { - case ace: java.security.AccessControlException => - null - } - if (coreProp == null) { + if (PartestDefaults.poolSize.isEmpty) { scala.actors.Debug.info("actors.corePoolSize not defined") - System.setProperty("actors.corePoolSize", "16") + setProp("actors.corePoolSize", "16") } def runTestsForFiles(kindFiles: List[File], kind: String): scala.collection.immutable.Map[String, Int] = { diff --git a/src/partest/scala/tools/partest/nest/FileManager.scala b/src/partest/scala/tools/partest/nest/FileManager.scala index ffeba6bbe3..b8f0770f3a 100644 --- a/src/partest/scala/tools/partest/nest/FileManager.scala +++ b/src/partest/scala/tools/partest/nest/FileManager.scala @@ -55,10 +55,9 @@ trait FileManager { var showLog = false var failed = false - var SCALAC_OPTS = System.getProperty("scalatest.scalac_opts", "-deprecation") - var JAVA_OPTS = System.getProperty("scalatest.java_opts", "") - - var timeout = "1200000" + var SCALAC_OPTS = PartestDefaults.scalacOpts + var JAVA_OPTS = PartestDefaults.javaOpts + var timeout = PartestDefaults.timeout def getLogFile(dir: File, fileBase: String, kind: String): LogFile = new LogFile(dir, fileBase + "-" + kind + ".log") diff --git a/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala b/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala index 2063d51b71..b3f199a3d6 100644 --- a/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala +++ b/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala @@ -8,9 +8,12 @@ package scala.tools.partest package nest +import scala.tools.nsc.Properties.{ setProp, propOrEmpty } import scala.tools.nsc.util.ClassPath import scala.tools.nsc.io import io.Path +import RunnerUtils._ +import java.net.URLClassLoader /* This class is used to load an instance of DirectRunner using * a custom class loader. @@ -19,14 +22,10 @@ import io.Path * the main NestRunner can be started merely by putting its * class on the classpath (ideally). */ -class ReflectiveRunner extends RunnerUtils { +class ReflectiveRunner { // TODO: we might also use fileManager.CLASSPATH // to use the same classes as used by `scala` that // was used to start the runner. - - import java.net.URLClassLoader - import utils.Properties.{ sysprop, syspropset } - val sepRunnerClassName = "scala.tools.partest.nest.ConsoleRunner" def main(args: String) { @@ -65,12 +64,12 @@ class ReflectiveRunner extends RunnerUtils { } val newClasspath = ClassPath.join(paths: _*) - syspropset("java.class.path", newClasspath) - syspropset("scala.home", "") + setProp("java.class.path", newClasspath) + setProp("scala.home", "") if (isPartestDebug) for (prop <- List("java.class.path", "sun.boot.class.path", "java.ext.dirs")) - println(prop + ": " + sysprop(prop)) + println(prop + ": " + propOrEmpty(prop)) try { val sepRunnerClass = sepLoader loadClass sepRunnerClassName diff --git a/src/partest/scala/tools/partest/nest/RunnerUtils.scala b/src/partest/scala/tools/partest/nest/RunnerUtils.scala index 4e41d00bf1..24445bb545 100644 --- a/src/partest/scala/tools/partest/nest/RunnerUtils.scala +++ b/src/partest/scala/tools/partest/nest/RunnerUtils.scala @@ -8,35 +8,22 @@ package scala.tools.partest package nest -trait RunnerUtils { +object RunnerUtils { + def splitArgs(str: String) = str split "\\s" filterNot (_ == "") toList - def searchPath(option: String, as: List[String]): Option[String] = { - val Option = option - as match { - case Option :: r :: rs => Some(r) - case other :: rest => searchPath(option, rest) - case List() => None - } + def searchPath(option: String, as: List[String]): Option[String] = as match { + case `option` :: r :: _ => Some(r) + case _ :: rest => searchPath(option, rest) + case Nil => None } - def searchAndRemovePath(option: String, as: List[String]): (Option[String], List[String]) = { - val Option = option - def search(before: List[String], after: List[String]): (Option[String], List[String]) = after match { - case Option :: r :: rs => (Some(r), before ::: rs) - case other :: rest => search(before ::: List(other), rest) - case List() => (None, before) - } - search(List(), as) + def searchAndRemovePath(option: String, as: List[String]) = (as indexOf option) match { + case -1 => (None, as) + case idx => (Some(as(idx + 1)), (as take idx) ::: (as drop (idx + 2))) } - def searchAndRemoveOption(option: String, as: List[String]): (Boolean, List[String]) = { - val Option = option - def search(before: List[String], after: List[String]): (Boolean, List[String]) = after match { - case Option :: rest => (true, before ::: rest) - case other :: rest => search(before ::: List(other), rest) - case List() => (false, before) - } - search(List(), as) + def searchAndRemoveOption(option: String, as: List[String]) = (as indexOf option) match { + case -1 => (false, as) + case idx => (true, (as take idx) ::: (as drop (idx + 1))) } - } diff --git a/src/partest/scala/tools/partest/nest/Worker.scala b/src/partest/scala/tools/partest/nest/Worker.scala index 7a947b3298..4bbd34766c 100644 --- a/src/partest/scala/tools/partest/nest/Worker.scala +++ b/src/partest/scala/tools/partest/nest/Worker.scala @@ -12,6 +12,7 @@ import java.io._ import java.net.{URLClassLoader, URL} import java.util.{Timer, TimerTask} +import scala.util.Properties.osName import scala.tools.nsc.{ ObjectRunner, Settings, CompilerCommand, Global } import scala.tools.nsc.io.{ AbstractFile, PlainFile, Path, Directory, File => SFile } import scala.tools.nsc.reporters.ConsoleReporter @@ -121,48 +122,48 @@ class Worker(val fileManager: FileManager) extends Actor { } /* Note: not yet used/tested. */ - def execTestObjectRunner(file: File, outDir: File, logFile: File) { - val consFM = new ConsoleFileManager - - val classpath: List[URL] = { - import consFM.{ latestCompFile, latestLibFile, latestPartestFile } - val units = ( - List(outDir, latestCompFile, latestLibFile, latestPartestFile) ::: - ((CLASSPATH split File.pathSeparatorChar).toList map (x => new File(x))) - ) - units map (_.toURI.toURL) - } - - NestUI.verbose("ObjectRunner classpath: "+classpath) - - try { - // configure input/output files - val logOut = new FileOutputStream(logFile) - val logWriter = new PrintStream(logOut) - - // grab global lock - fileManager.synchronized { - withOutputRedirected(logWriter) { - System.setProperty("java.library.path", logFile.getParentFile.getCanonicalFile.getAbsolutePath) - System.setProperty("scalatest.output", outDir.getCanonicalFile.getAbsolutePath) - System.setProperty("scalatest.lib", LATEST_LIB) - System.setProperty("scalatest.cwd", outDir.getParent) - ObjectRunner.run(classpath, "Test", List("jvm")) - } - } - - /*val out = new FileOutputStream(logFile, true) - Console.withOut(new PrintStream(out)) { - ObjectRunner.run(classpath, "Test", List("jvm")) - } - out.flush - out.close*/ - } catch { - case e: Exception => - NestUI.verbose(e+" ("+file.getPath+")") - e.printStackTrace() - } - } + // def execTestObjectRunner(file: File, outDir: File, logFile: File) { + // val consFM = new ConsoleFileManager + // + // val classpath: List[URL] = { + // import consFM.{ latestCompFile, latestLibFile, latestPartestFile } + // val units = ( + // List(outDir, latestCompFile, latestLibFile, latestPartestFile) ::: + // ((CLASSPATH split File.pathSeparatorChar).toList map (x => new File(x))) + // ) + // units map (_.toURI.toURL) + // } + // + // NestUI.verbose("ObjectRunner classpath: "+classpath) + // + // try { + // // configure input/output files + // val logOut = new FileOutputStream(logFile) + // val logWriter = new PrintStream(logOut) + // + // // grab global lock + // fileManager.synchronized { + // withOutputRedirected(logWriter) { + // System.setProperty("java.library.path", logFile.getParentFile.getCanonicalFile.getAbsolutePath) + // System.setProperty("scalatest.output", outDir.getCanonicalFile.getAbsolutePath) + // System.setProperty("scalatest.lib", LATEST_LIB) + // System.setProperty("scalatest.cwd", outDir.getParent) + // ObjectRunner.run(classpath, "Test", List("jvm")) + // } + // } + // + // /*val out = new FileOutputStream(logFile, true) + // Console.withOut(new PrintStream(out)) { + // ObjectRunner.run(classpath, "Test", List("jvm")) + // } + // out.flush + // out.close*/ + // } catch { + // case e: Exception => + // NestUI.verbose(e+" ("+file.getPath+")") + // e.printStackTrace() + // } + // } def javac(outDir: File, files: List[File], output: File): Boolean = { // compile using command-line javac compiler @@ -412,13 +413,14 @@ class Worker(val fileManager: FileManager) extends Actor { val dir = file.getParentFile //TODO: detect whether we have to use Runtime.exec - val useRuntime = true - - if (useRuntime) - execTest(outDir, logFile, fileBase) - else - execTestObjectRunner(file, outDir, logFile) - // NestUI.verbose(this+" finished running "+fileBase) + // val useRuntime = true + // + // if (useRuntime) + // execTest(outDir, logFile, fileBase) + // else + // execTestObjectRunner(file, outDir, logFile) + // // NestUI.verbose(this+" finished running "+fileBase) + execTest(outDir, logFile, fileBase) diff = compareOutput(dir, fileBase, kind, logFile) if (!diff.equals("")) { @@ -492,10 +494,7 @@ class Worker(val fileManager: FileManager) extends Actor { } }) - case "run" => - runJvmTest(file, kind) - - case "jvm" => + case "run" | "jvm" => runJvmTest(file, kind) case "buildmanager" => @@ -809,12 +808,15 @@ class Worker(val fileManager: FileManager) extends Actor { // -------- run test -------- //TODO: detect whether we have to use Runtime.exec - val useRuntime = true + // val useRuntime = true + // + // if (useRuntime) + // execTest(outDir, logFile, fileBase) + // else + // execTestObjectRunner(file, outDir, logFile) + + execTest(outDir, logFile, fileBase) - if (useRuntime) - execTest(outDir, logFile, fileBase) - else - execTestObjectRunner(file, outDir, logFile) NestUI.verbose(this+" finished running "+fileBase) } // successful compile } catch { // *catch-all* @@ -892,7 +894,6 @@ class Worker(val fileManager: FileManager) extends Actor { } case "script" => { - val osName = System.getProperty("os.name", "") // when option "--failed" is provided // execute test only if log file is present // (which means it failed before) diff --git a/src/partest/scala/tools/partest/package.scala b/src/partest/scala/tools/partest/package.scala index d814fc4fc7..9337d78ef4 100644 --- a/src/partest/scala/tools/partest/package.scala +++ b/src/partest/scala/tools/partest/package.scala @@ -4,9 +4,35 @@ package scala.tools +import nsc.io.{ Directory } +import util.{ PathResolver } +import nsc.Properties.{ propOrElse, propOrNone, propOrEmpty } + package object partest { import nest.NestUI + object PartestDefaults { + import nsc.Properties._ + private def wrapAccessControl[T](body: => Option[T]): Option[T] = + try body catch { case _: java.security.AccessControlException => None } + + def prefixDir = Directory.Current map (_.normalize.toDirectory) + def srcDirName = propOrElse("partest.srcdir", "files") + def classPath = PathResolver.Environment.javaUserClassPath // XXX + + def javaCmd = propOrElse("scalatest.javacmd", "java") + def javacCmd = propOrElse("scalatest.javac_cmd", "javac") + def javaOpts = propOrElse("scalatest.java_opts", "") + def scalacOpts = propOrElse("scalatest.scalac_opts", "-deprecation") + + def testBuild = propOrNone("scalatest.build") + def errorCount = propOrElse("scalatest.errors", "0").toInt + def numActors = propOrElse("scalatest.actors", "8").toInt + def poolSize = wrapAccessControl(propOrNone("actors.corePoolSize")) + + def timeout = "1200000" + } + def vmArgString = { import scala.tools.nsc.io.Process @@ -24,8 +50,5 @@ package object partest { NestUI.verbose(allPropertiesString) } - def isPartestDebug = { - (System.getProperty("partest.debug") == "true") || - (System.getProperty("scalatest.debug") == "true") - } + def isPartestDebug = List("partest.debug", "scalatest.debug") map propOrEmpty contains "true" }
\ No newline at end of file |