Skip to content

Commit

Permalink
Teach partest the magic of abstraction.
Browse files Browse the repository at this point in the history
Some new partest abilities which were necessary to deal with
additional standard jars. These new abilities aren't yet put
to the test because scaladoc and interactive are still going
into the compiler jar.

No longer need each jar or classes directory be named
directly for partest to find them.
  • Loading branch information
paulp authored and adriaanm committed Mar 9, 2013
1 parent e83defa commit 1dd88d9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 34 deletions.
26 changes: 7 additions & 19 deletions src/partest/scala/tools/partest/nest/DirectRunner.scala
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,27 +38,15 @@ trait DirectRunner {
def runTestsForFiles(_kindFiles: List[File], kind: String): immutable.Map[String, TestState] = { def runTestsForFiles(_kindFiles: List[File], kind: String): immutable.Map[String, TestState] = {
System.setProperty("line.separator", "\n") System.setProperty("line.separator", "\n")


// @partest maintainer: we cannot create a fresh file manager here val allUrls = PathSettings.scalaCheck.toURL :: fileManager.latestUrls
// since the FM must respect --buildpath and --classpath from the command line val scalaCheckParentClassLoader = ScalaClassLoader.fromURLs(allUrls)
// for example, see how it's done in ReflectiveRunner val kindFiles = onlyValidTestPaths(_kindFiles)
//val consFM = new ConsoleFileManager val pool = Executors.newFixedThreadPool(numThreads)
//import consFM.{ latestCompFile, latestLibFile, latestPartestFile } val manager = new RunnerManager(kind, fileManager, TestRunParams(scalaCheckParentClassLoader))
val latestCompFile = new File(fileManager.LATEST_COMP) val futures = kindFiles map (f => (f, pool submit callable(manager runTest f))) toMap
val latestReflectFile = new File(fileManager.LATEST_REFLECT)
val latestLibFile = new File(fileManager.LATEST_LIB)
val latestPartestFile = new File(fileManager.LATEST_PARTEST)
val latestActorsFile = new File(fileManager.LATEST_ACTORS)
val scalacheckURL = PathSettings.scalaCheck.toURL
val scalaCheckParentClassLoader = ScalaClassLoader.fromURLs(
scalacheckURL :: (List(latestCompFile, latestReflectFile, latestLibFile, latestActorsFile, latestPartestFile).map(_.toURI.toURL))
)

val kindFiles = onlyValidTestPaths(_kindFiles)
val pool = Executors.newFixedThreadPool(numThreads)
val manager = new RunnerManager(kind, fileManager, TestRunParams(scalaCheckParentClassLoader))
val futures = kindFiles map (f => (f, pool submit callable(manager runTest f))) toMap


pool.shutdown() pool.shutdown()

try if (!pool.awaitTermination(4, TimeUnit.HOURS)) try if (!pool.awaitTermination(4, TimeUnit.HOURS))
NestUI.warning("Thread pool timeout elapsed before all tests were complete!") NestUI.warning("Thread pool timeout elapsed before all tests were complete!")
catch { case t: InterruptedException => catch { case t: InterruptedException =>
Expand Down
14 changes: 14 additions & 0 deletions src/partest/scala/tools/partest/nest/FileManager.scala
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ trait FileManager extends FileUtil {
var LATEST_PARTEST: String var LATEST_PARTEST: String
var LATEST_ACTORS: String var LATEST_ACTORS: String


protected def relativeToLibrary(what: String): String = {
if (LATEST_LIB endsWith ".jar") {
(SFile(LATEST_LIB).parent / s"scala-$what.jar").toAbsolute.path
}
else {
(SFile(LATEST_LIB).parent.parent / "classes" / what).toAbsolute.path
}
}
def latestScaladoc = relativeToLibrary("scaladoc")
def latestInteractive = relativeToLibrary("interactive")
def latestPaths = List(LATEST_LIB, LATEST_REFLECT, LATEST_COMP, LATEST_PARTEST, LATEST_ACTORS, latestScaladoc, latestInteractive)
def latestFiles = latestPaths map (p => new java.io.File(p))
def latestUrls = latestFiles map (_.toURI.toURL)

var showDiff = false var showDiff = false
var updateCheck = false var updateCheck = false
var showLog = false var showLog = false
Expand Down
20 changes: 5 additions & 15 deletions src/partest/scala/tools/partest/nest/ReflectiveRunner.scala
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -50,22 +50,15 @@ class ReflectiveRunner {
else // auto detection else // auto detection
new ConsoleFileManager new ConsoleFileManager


import fileManager.
{ latestCompFile, latestReflectFile, latestLibFile, latestPartestFile, latestScalapFile, latestActorsFile }
val files =
Array(latestCompFile, latestReflectFile, latestLibFile, latestPartestFile, latestScalapFile, latestActorsFile) map (x => io.File(x))

val sepUrls = files map (_.toURL)
var sepLoader = new URLClassLoader(sepUrls, null)

// this is a workaround for https://issues.scala-lang.org/browse/SI-5433 // this is a workaround for https://issues.scala-lang.org/browse/SI-5433
// when that bug is fixed, this paragraph of code can be safely removed // when that bug is fixed, the addition of PathSettings.srcCodeLib can be removed
// we hack into the classloader that will become parent classloader for scalac // we hack into the classloader that will become parent classloader for scalac
// this way we ensure that reflective macro lookup will pick correct Code.lift // this way we ensure that reflective macro lookup will pick correct Code.lift
sepLoader = new URLClassLoader((PathSettings.srcCodeLib +: files) map (_.toURL), null) val sepUrls = PathSettings.srcCodeLib.toURI.toURL :: fileManager.latestUrls
val sepLoader = new URLClassLoader(sepUrls.toArray, null)


if (isPartestDebug) if (isPartestDebug)
println("Loading classes from:\n" + sepUrls.mkString("\n")) println("Loading classes from:\n " + fileManager.latestUrls.mkString("\n "))


// @partest maintainer: it seems to me that commented lines are incorrect // @partest maintainer: it seems to me that commented lines are incorrect
// if classPath is not empty, then it has been provided by the --classpath option // if classPath is not empty, then it has been provided by the --classpath option
Expand All @@ -76,11 +69,8 @@ class ReflectiveRunner {
// case Some(cp) => Nil // case Some(cp) => Nil
// case _ => files.toList map (_.path) // case _ => files.toList map (_.path)
//} //}
val paths = files.toList map (_.path)

val newClasspath = ClassPath.join(paths: _*)


setProp("java.class.path", newClasspath) setProp("java.class.path", ClassPath.join(fileManager.latestPaths: _*))


// don't let partest find pluginsdir; in ant build, standard plugin has dedicated test suite // don't let partest find pluginsdir; in ant build, standard plugin has dedicated test suite
//setProp("scala.home", latestLibFile.parent.parent.path) //setProp("scala.home", latestLibFile.parent.parent.path)
Expand Down

0 comments on commit 1dd88d9

Please sign in to comment.