summaryrefslogtreecommitdiff
path: root/src/partest
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-02-14 08:47:18 +0000
committerPaul Phillips <paulp@improving.org>2010-02-14 08:47:18 +0000
commit1ec5bf5c82ab29a565eeeec2ce8df2bddab7da0b (patch)
tree0b5b3935db11cf7d9bacecbe267e3d29dbf180a8 /src/partest
parentd7ad3f348753884e154ab40aa848b6f9d85d7b52 (diff)
downloadscala-1ec5bf5c82ab29a565eeeec2ce8df2bddab7da0b.tar.gz
scala-1ec5bf5c82ab29a565eeeec2ce8df2bddab7da0b.tar.bz2
scala-1ec5bf5c82ab29a565eeeec2ce8df2bddab7da0b.zip
More classpath work, and cleanups in the vicini...
More classpath work, and cleanups in the vicinities of everything manipulating classpaths. Review by anyone willing to slog through the approximately dozen different ways the classpath can be influenced.
Diffstat (limited to 'src/partest')
-rw-r--r--src/partest/scala/tools/partest/nest/CompileManager.scala81
-rw-r--r--src/partest/scala/tools/partest/nest/ConsoleFileManager.scala82
-rw-r--r--src/partest/scala/tools/partest/nest/ReflectiveRunner.scala4
-rw-r--r--src/partest/scala/tools/partest/nest/TestFile.scala6
-rw-r--r--src/partest/scala/tools/partest/nest/Worker.scala57
5 files changed, 99 insertions, 131 deletions
diff --git a/src/partest/scala/tools/partest/nest/CompileManager.scala b/src/partest/scala/tools/partest/nest/CompileManager.scala
index ecf8b07b8e..9535b35c95 100644
--- a/src/partest/scala/tools/partest/nest/CompileManager.scala
+++ b/src/partest/scala/tools/partest/nest/CompileManager.scala
@@ -8,18 +8,19 @@
package scala.tools.partest
package nest
-import scala.tools.nsc.{Global, Settings, CompilerCommand, FatalError}
+import scala.tools.nsc.{ Global, Settings, CompilerCommand, FatalError }
import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
import scala.tools.nsc.util.ClassPath
import scala.tools.util.PathResolver
-import java.io.{File, BufferedReader, PrintWriter, FileReader, FileWriter, StringWriter}
+import java.io.{ File, BufferedReader, PrintWriter, FileReader, Writer, FileWriter, StringWriter }
import File.pathSeparator
-class ExtConsoleReporter(override val settings: Settings, reader: BufferedReader, var writer: PrintWriter) extends ConsoleReporter(settings, reader, writer) {
- def this(settings: Settings) = {
- this(settings, Console.in, new PrintWriter(new FileWriter("/dev/null")))
- }
+class ExtConsoleReporter(override val settings: Settings, reader: BufferedReader, var writer: PrintWriter)
+extends ConsoleReporter(settings, reader, writer) {
+
+ def this(settings: Settings) = this(settings, Console.in, new PrintWriter(new FileWriter("/dev/null")))
+
def hasWarnings: Boolean = WARNING.count != 0
}
@@ -27,20 +28,14 @@ abstract class SimpleCompiler {
def compile(out: Option[File], files: List[File], kind: String, log: File): Boolean
}
-class TestSettings(fileMan: FileManager) extends Settings(x => ()) {
- javabootclasspath.value = ClassPath.join(
- List(PathResolver.Environment.javaBootClassPath, fileMan.LATEST_LIB)
- )
-}
+class TestSettings(fileMan: FileManager) extends Settings(_ => ()) { }
class DirectCompiler(val fileManager: FileManager) extends SimpleCompiler {
def newGlobal(settings: Settings, reporter: Reporter): Global =
new Global(settings, reporter)
def newGlobal(settings: Settings, logWriter: FileWriter): Global = {
- val rep = new ExtConsoleReporter(settings,
- Console.in,
- new PrintWriter(logWriter))
+ val rep = newReporter(settings, logWriter)
rep.shortname = true
newGlobal(settings, rep)
}
@@ -50,12 +45,15 @@ class DirectCompiler(val fileManager: FileManager) extends SimpleCompiler {
settings.deprecation.value = true
settings.nowarnings.value = false
settings.encoding.value = "iso-8859-1"
+ // XXX
+ settings.javabootclasspath.value =
+ ClassPath.join(Seq(PathResolver.Environment.javaBootClassPath, fileManager.LATEST_LIB))
+
settings
}
- def newReporter(sett: Settings) = new ExtConsoleReporter(sett,
- Console.in,
- new PrintWriter(new StringWriter))
+ def newReporter(sett: Settings, writer: Writer = new StringWriter) =
+ new ExtConsoleReporter(sett, Console.in, new PrintWriter(writer))
private def updatePluginPath(options: String): String = {
val (opt1, opt2) =
@@ -95,49 +93,50 @@ class DirectCompiler(val fileManager: FileManager) extends SimpleCompiler {
} else ""
val allOpts = fileManager.SCALAC_OPTS+" "+argString
NestUI.verbose("scalac options: "+allOpts)
+
val args = (allOpts split "\\s").toList
- val command = new CompilerCommand(args, testSettings, x => {}, false)
+ val command = new CompilerCommand(args, testSettings, _ => (), false)
val global = newGlobal(command.settings, logWriter)
val testRep: ExtConsoleReporter = global.reporter.asInstanceOf[ExtConsoleReporter]
- val test: TestFile = kind match {
- case "pos" => PosTestFile(files(0), fileManager, out.isEmpty)
- case "neg" => NegTestFile(files(0), fileManager, out.isEmpty)
- case "run" => RunTestFile(files(0), fileManager, out.isEmpty)
- case "jvm" => JvmTestFile(files(0), fileManager, out.isEmpty)
- case "shootout" => ShootoutTestFile(files(0), fileManager, out.isEmpty)
- case "scalap" => ScalapTestFile(files(0), fileManager, out.isEmpty)
- case "scalacheck" =>
- ScalaCheckTestFile(files(0), fileManager, out.isEmpty)
+ val testFileFn: (File, FileManager, Boolean) => TestFile = kind match {
+ case "pos" => PosTestFile.apply
+ case "neg" => NegTestFile.apply
+ case "run" => RunTestFile.apply
+ case "jvm" => JvmTestFile.apply
+ case "shootout" => ShootoutTestFile.apply
+ case "scalap" => ScalapTestFile.apply
+ case "scalacheck" => ScalaCheckTestFile.apply
}
- test.defineSettings(command.settings)
- out match {
- case Some(outDir) =>
- command.settings.outdir.value = outDir.getAbsolutePath
- command.settings appendToClasspath outDir.getAbsolutePath
- case None =>
- // do nothing
+ val test: TestFile = testFileFn(files.head, fileManager, out.isEmpty)
+ test defineSettings command.settings
+
+ out map { outDir =>
+ command.settings.outdir.value = outDir.getAbsolutePath
+ command.settings appendToClasspath outDir.getAbsolutePath
}
- val toCompile = files.map(_.getPath)
+ val toCompile = files map (_.getPath)
+
try {
NestUI.verbose("compiling "+toCompile)
- try {
- (new global.Run) compile toCompile
- } catch {
+ try new global.Run compile toCompile
+ catch {
case FatalError(msg) =>
testRep.error(null, "fatal error: " + msg)
}
+
testRep.printSummary
testRep.writer.flush
testRep.writer.close
- } catch {
+ }
+ catch {
case e =>
e.printStackTrace()
return false
- } finally {
- logWriter.close()
}
+ finally logWriter.close()
+
!testRep.hasErrors
}
}
diff --git a/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala b/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala
index 27cd36e3e7..c8ec9a9f6f 100644
--- a/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala
+++ b/src/partest/scala/tools/partest/nest/ConsoleFileManager.scala
@@ -10,6 +10,7 @@ package nest
import java.io.{File, FilenameFilter, IOException, StringWriter}
import java.net.URI
+import scala.tools.util.PathResolver
class ConsoleFileManager extends FileManager {
@@ -40,7 +41,8 @@ class ConsoleFileManager extends FileManager {
SCALAC_OPTS = SCALAC_OPTS+" "+moreOpts
}
- var CLASSPATH = System.getProperty("java.class.path", ".")
+ var CLASSPATH = PathResolver.Environment.javaUserClassPath match { case "" => "." ; case x => x }
+
NestUI.verbose("CLASSPATH: "+CLASSPATH)
var JAVACMD = System.getProperty("scalatest.javacmd", "java")
@@ -135,7 +137,6 @@ else
NestUI.verbose("Running with classes in "+testClassesFile)
latestFile = prefixFileWith(testClassesFile.getParentFile, "bin")
latestLibFile = prefixFileWith(testClassesFile, "library")
- latestActFile = prefixFileWith(testClassesFile, "library")
latestCompFile = prefixFileWith(testClassesFile, "compiler")
latestPartestFile = prefixFileWith(testClassesFile, "partest")
latestFjbgFile = prefixFile("lib/fjbg.jar")
@@ -145,15 +146,14 @@ else
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 {
+ }
+ else {
def setupQuick() {
NestUI.verbose("Running build/quick")
latestFile = prefixFile("build/quick/bin")
latestLibFile = prefixFile("build/quick/classes/library")
- latestActFile = prefixFile("build/quick/classes/library")
latestCompFile = prefixFile("build/quick/classes/compiler")
latestPartestFile = prefixFile("build/quick/classes/partest")
}
@@ -163,7 +163,6 @@ else
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")
}
@@ -172,7 +171,6 @@ else
NestUI.verbose("Running dists/latest")
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")
}
@@ -181,59 +179,34 @@ else
NestUI.verbose("Running build/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")
}
- def max(a: Long, b: Long) = if (a > b) a else b
-
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")
+ def mostRecentOf(base: String, names: String*) =
+ names map (x => prefixFile(base + "/" + x).lastModified) reduceLeft (_ max _)
+
// detect most recent build
- val quickTime =
- max(prefixFile("build/quick/classes/compiler/compiler.properties").lastModified,
- prefixFile("build/quick/classes/library/library.properties").lastModified)
- val packTime =
- max(prefixFile("build/pack/lib/scala-compiler.jar").lastModified,
- prefixFile("build/pack/lib/scala-library.jar").lastModified)
- val distTime =
- max(prefixFile("dists/latest/lib/scala-compiler.jar").lastModified,
- prefixFile("dists/latest/lib/scala-library.jar").lastModified)
- val instTime = {
- val p = testParent.getParentFile
- max(prefixFileWith(p, "lib/scala-compiler.jar").lastModified,
- prefixFileWith(p, "lib/scala-library.jar").lastModified)
- }
+ val quickTime = mostRecentOf("build/quick/classes", "compiler/compiler.properties", "library/library.properties")
+ val packTime = mostRecentOf("build/pack/lib", "scala-compiler.jar", "scala-library.jar")
+ val distTime = mostRecentOf("dists/latest/lib", "scala-compiler.jar", "scala-library.jar")
+ val instTime = mostRecentOf("lib", "scala-compiler.jar", "scala-library.jar")
+
+ val pairs = Map(
+ (quickTime, () => setupQuick()),
+ (packTime, () => setupPack()),
+ (distTime, () => setupDist()),
+ (instTime, () => setupInst())
+ )
+
+ // run setup based on most recent time
+ pairs(pairs.keysIterator.toList max)()
- if (quickTime > packTime) { // pack ruled out
- if (quickTime > distTime) { // dist ruled out
- if (quickTime > instTime) // inst ruled out
- setupQuick()
- else
- setupInst()
- } else { // quick ruled out
- if (distTime > instTime) // inst ruled out
- setupDist()
- else
- setupInst()
- }
- } else { // quick ruled out
- if (packTime > distTime) { // dist ruled out
- if (packTime > instTime) // inst ruled out
- setupPack()
- else
- setupInst()
- } else { // pack ruled out
- if (distTime > instTime) // inst ruled out
- setupDist()
- else
- setupInst()
- }
- }
latestFjbgFile = prefixFile("lib/fjbg.jar")
}
@@ -242,14 +215,10 @@ else
LATEST_COMP = latestCompFile.getAbsolutePath
LATEST_PARTEST = latestPartestFile.getAbsolutePath
- // detect whether we are running on Windows
- val osName = System.getProperty("os.name")
- NestUI.verbose("OS: "+osName)
+ import util.Properties.isWin
- val scalaCommand = if (osName startsWith "Windows")
- "scala.bat" else "scala"
- val scalacCommand = if (osName startsWith "Windows")
- "scalac.bat" else "scalac"
+ 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
@@ -264,7 +233,6 @@ else
var latestFile: File = _
var latestLibFile: File = _
- var latestActFile: File = _
var latestCompFile: File = _
var latestPartestFile: File = _
var latestFjbgFile: File = _
diff --git a/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala b/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala
index 2ae67db566..af8a368489 100644
--- a/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala
+++ b/src/partest/scala/tools/partest/nest/ReflectiveRunner.scala
@@ -44,9 +44,9 @@ class ReflectiveRunner extends RunnerUtils {
new ConsoleFileManager
import fileManager.
- { latestCompFile, latestLibFile, latestActFile, latestPartestFile, latestFjbgFile }
+ { latestCompFile, latestLibFile, latestPartestFile, latestFjbgFile }
val files =
- Array(latestCompFile, latestLibFile, latestActFile, latestPartestFile, latestFjbgFile)
+ Array(latestCompFile, latestLibFile, latestPartestFile, latestFjbgFile)
val sepUrls = files map { _.toURI.toURL }
val sepLoader = new URLClassLoader(sepUrls, null)
diff --git a/src/partest/scala/tools/partest/nest/TestFile.scala b/src/partest/scala/tools/partest/nest/TestFile.scala
index 3ae46399ec..90d8db936f 100644
--- a/src/partest/scala/tools/partest/nest/TestFile.scala
+++ b/src/partest/scala/tools/partest/nest/TestFile.scala
@@ -26,8 +26,10 @@ abstract class TestFile(kind: String) {
protected def baseSettings(settings: Settings) {
settings appendToClasspath dirpath
- if (createOutDir)
- settings.outdir.value = (Path(dir) / objDir).createDirectory(true).path
+ if (createOutDir) {
+ val d = (Path(dirpath) / objDir) createDirectory true
+ settings.outdir.value = d.toAbsolute.path
+ }
// add additional flags found in 'testname.flags'
def flagsPath = Path(dir) / (fileBase + ".flags")
diff --git a/src/partest/scala/tools/partest/nest/Worker.scala b/src/partest/scala/tools/partest/nest/Worker.scala
index bd742a5b13..19fa35cdeb 100644
--- a/src/partest/scala/tools/partest/nest/Worker.scala
+++ b/src/partest/scala/tools/partest/nest/Worker.scala
@@ -15,7 +15,9 @@ import java.util.{Timer, TimerTask}
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
-import scala.tools.nsc.util.FakePos
+import scala.tools.nsc.util.{ ClassPath, FakePos }
+import scala.tools.util.PathResolver
+import ClassPath.{ join, split }
import scala.actors.{Actor, Exit, TIMEOUT}
import scala.actors.Actor._
@@ -55,7 +57,7 @@ class Worker(val fileManager: FileManager) extends Actor {
def act() {
react {
case RunTests(kind, files) =>
- NestUI.verbose("received "+files.length+" to test")
+ // NestUI.verbose("received "+files.length+" to test")
val master = sender
runTests(kind, files) { results =>
master ! Results(results, createdLogFiles, createdOutputDirs)
@@ -123,9 +125,9 @@ class Worker(val fileManager: FileManager) extends Actor {
val consFM = new ConsoleFileManager
val classpath: List[URL] = {
- import consFM.{ latestCompFile, latestLibFile, latestActFile, latestPartestFile }
+ import consFM.{ latestCompFile, latestLibFile, latestPartestFile }
val units = (
- List(outDir, latestCompFile, latestLibFile, latestActFile, latestPartestFile) :::
+ List(outDir, latestCompFile, latestLibFile, latestPartestFile) :::
((CLASSPATH split File.pathSeparatorChar).toList map (x => new File(x)))
)
units map (_.toURI.toURL)
@@ -173,7 +175,7 @@ class Worker(val fileManager: FileManager) extends Actor {
val cmd = javacCmd+
" -d "+outDir.getAbsolutePath+
- " -classpath "+outDir+File.pathSeparator+CLASSPATH+
+ " -classpath "+ join(Seq(outDir.toString, CLASSPATH)) +
" "+files.mkString(" ")
val (success, msg) = try {
@@ -235,9 +237,6 @@ class Worker(val fileManager: FileManager) extends Actor {
options
} else ""
- val cp = System.getProperty("java.class.path", ".")
- NestUI.verbose("java.class.path: "+cp)
-
def quote(path: String) = "\""+path+"\""
// Note! As this currently functions, JAVA_OPTS must precede argString
@@ -248,21 +247,23 @@ class Worker(val fileManager: FileManager) extends Actor {
//
// debug: Found javaopts file 'files/shootout/message.scala-2.javaopts', using options: '-Xss32k'
// debug: java -Xss32k -Xss2m -Xms256M -Xmx1024M -classpath [...]
- val cmd =
- JAVACMD+
- " "+JAVA_OPTS+
- " "+argString+
- " -classpath "+outDir+File.pathSeparator+CLASSPATH+
- " -Djava.library.path="+logFile.getParentFile.getAbsolutePath+
- " -Dscalatest.output="+outDir.getAbsolutePath+
- " -Dscalatest.lib="+LATEST_LIB+
- " -Dscalatest.cwd="+outDir.getParent+
- " -Djavacmd="+JAVACMD+
- " -Duser.language=en -Duser.country=US"+
- " scala.tools.nsc.MainGenericRunner"+
- " Test jvm"
- NestUI.verbose(cmd)
+ val cmd = List(
+ JAVACMD,
+ JAVA_OPTS,
+ argString,
+ "-classpath " + join(Seq(outDir.toString, CLASSPATH)),
+ "-Djava.library.path="+logFile.getParentFile.getAbsolutePath,
+ "-Dscalatest.output="+outDir.getAbsolutePath,
+ "-Dscalatest.lib="+LATEST_LIB,
+ "-Dscalatest.cwd="+outDir.getParent,
+ "-Djavacmd="+JAVACMD,
+ "-Duser.language=en -Duser.country=US",
+ "scala.tools.nsc.MainGenericRunner",
+ "Test",
+ "jvm"
+ ) mkString " "
+ NestUI.verbose(cmd)
runCommand(cmd, logFile)
if (fileManager.showLog) {
@@ -410,7 +411,7 @@ class Worker(val fileManager: FileManager) extends Actor {
execTest(outDir, logFile, fileBase)
else
execTestObjectRunner(file, outDir, logFile)
- NestUI.verbose(this+" finished running "+fileBase)
+ // NestUI.verbose(this+" finished running "+fileBase)
diff = compareOutput(dir, fileBase, kind, logFile)
if (!diff.equals("")) {
@@ -430,8 +431,7 @@ class Worker(val fileManager: FileManager) extends Actor {
}
if (succeeded) {
val consFM = new ConsoleFileManager
- import consFM.{latestCompFile, latestLibFile, latestActFile,
- latestPartestFile}
+ import consFM.{ latestCompFile, latestLibFile, latestPartestFile }
NestUI.verbose("compilation of "+file+" succeeded\n")
@@ -439,8 +439,7 @@ class Worker(val fileManager: FileManager) extends Actor {
val scalacheckURL = (new File(libs, "ScalaCheck.jar")).toURI.toURL
val outURL = outDir.getCanonicalFile.toURI.toURL
val classpath: List[URL] =
- List(outURL, scalacheckURL, latestCompFile.toURI.toURL, latestLibFile.toURI.toURL,
- latestActFile.toURI.toURL, latestPartestFile.toURI.toURL).distinct
+ List(outURL, scalacheckURL, latestCompFile.toURI.toURL, latestLibFile.toURI.toURL, latestPartestFile.toURI.toURL).distinct
val logWriter = new PrintStream(new FileOutputStream(logFile))
@@ -952,8 +951,8 @@ class Worker(val fileManager: FileManager) extends Actor {
}
def reportAll(results: ImmMap[String, Int], cont: ImmMap[String, Int] => Unit) {
- NestUI.verbose("finished testing "+kind+" with "+errors+" errors")
- NestUI.verbose("created "+compileMgr.numSeparateCompilers+" separate compilers")
+ // NestUI.verbose("finished testing "+kind+" with "+errors+" errors")
+ // NestUI.verbose("created "+compileMgr.numSeparateCompilers+" separate compilers")
timer.cancel()
cont(results)
}