Skip to content
This repository was archived by the owner on Sep 8, 2022. It is now read-only.

Commit dcf4883

Browse files
committed
Consolidate RunnerManager & DirectRunner as SuiteRunner
Test suite arguments now `SuiteRunner` constructor arguments. `FileManager` instance focusses on managing classpath.
1 parent 0cd1d8a commit dcf4883

File tree

7 files changed

+98
-110
lines changed

7 files changed

+98
-110
lines changed

src/main/scala/scala/tools/partest/PartestTask.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ class PartestTask extends Task with CompilationPathProperty with ScalaTask {
124124
if (parts eq null) Array.empty[String] else parts
125125
})
126126

127-
128127
var failureCount = 0
129128
val summary = new scala.tools.partest.nest.AntRunner(compilationPath.get.list, javacmd.getOrElse(null), javaccmd.getOrElse(null), scalacArgsFlat) {
130129
def echo(msg: String): Unit = PartestTask.this.log(msg)

src/main/scala/scala/tools/partest/nest/AntRunner.scala

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,18 @@ import sbt.testing.SuiteSelector
2020
import sbt.testing.TestSelector
2121

2222
// not using any Scala types to ease calling across different scala versions
23-
abstract class AntRunner(compilationPaths: Array[String], javaCmd: File, javacCmd: File, scalacArgs: Array[String]) extends DirectRunner {
23+
abstract class AntRunner(compilationPaths: Array[String], javaCmd: File, javacCmd: File, scalacArgs: Array[String]) extends SuiteRunner(
24+
new FileManager(testClassPath = compilationPaths map { fs => Path(fs) } toList),
25+
updateCheck = false,
26+
failed = false,
27+
javaCmdPath = Option(javaCmd).map(_.getAbsolutePath) getOrElse PartestDefaults.javaCmd,
28+
javacCmdPath = Option(javacCmd).map(_.getAbsolutePath) getOrElse PartestDefaults.javacCmd,
29+
scalacExtraArgs = scalacArgs) {
30+
2431
def error(msg: String): Nothing = sys.error(msg)
2532
def echo(msg: String): Unit
2633
def log(msg: String): Unit
2734
def onFinishKind(kind: String, passed: Array[TestState], failed: Array[TestState]): Unit
28-
def onFinishTest(testFile: File, result: TestState): TestState = result
29-
30-
def updateCheck: Boolean = false
31-
def failed: Boolean = false
32-
33-
final lazy val fileManager =
34-
new FileManager(
35-
testClassPath = compilationPaths map { fs => Path(fs) } toList,
36-
javaCmd = Option(javaCmd) map (_.getAbsolutePath),
37-
javacCmd = Option(javacCmd) map (_.getAbsolutePath),
38-
scalacOpts = scalacArgs.toSeq)
39-
40-
final override def runTest(manager: RunnerManager, testFile: File): TestState =
41-
onFinishTest(testFile, manager runTest testFile)
4235

4336
final def runSet(kind: String, files: Array[File]): (Int, Int, Array[String]) = {
4437
if (files.isEmpty) (0, 0, Array.empty[String])

src/main/scala/scala/tools/partest/nest/ConsoleRunner.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ import scala.tools.cmd.{ CommandLine, CommandLineParser, Instance }
1616

1717
class ConsoleRunner(argstr: String) extends {
1818
val parsed = ConsoleRunnerSpec.creator(CommandLineParser tokenize argstr)
19-
} with DirectRunner with ConsoleRunnerSpec with Instance {
19+
} with ConsoleRunnerSpec with Instance {
20+
21+
val suiteRunner = new SuiteRunner (
22+
new ConsoleFileManager(if (optPack) Some("build/pack") else optBuildPath, optClassPath),
23+
optUpdateCheck,
24+
optFailed)
25+
import suiteRunner._
2026
import NestUI._
2127
import NestUI.color._
2228

2329
// So we can ctrl-C a test run and still hear all
2430
// the buffered failure info.
2531
scala.sys addShutdownHook issueSummaryReport()
2632

27-
lazy val fileManager: ConsoleFileManager =
28-
new ConsoleFileManager(if (optPack) Some("build/pack") else optBuildPath, optClassPath)
29-
30-
def updateCheck = optUpdateCheck
31-
def failed = optFailed
32-
3333
private var totalTests = 0
3434
private val passedTests = mutable.ListBuffer[TestState]()
3535
private val failedTests = mutable.ListBuffer[TestState]()

src/main/scala/scala/tools/partest/nest/DirectCompiler.scala

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,45 @@ class PartestGlobal(settings: Settings, reporter: Reporter) extends Global(setti
3232
// override def globalError(msg: String): Unit
3333
// override def supplementErrorMessage(msg: String): String
3434
}
35-
class DirectCompiler(val fileManager: FileManager) {
35+
class DirectCompiler(val runner: Runner) {
3636
def newGlobal(settings: Settings, reporter: Reporter): PartestGlobal =
3737
new PartestGlobal(settings, reporter)
3838

3939
def newGlobal(settings: Settings, logWriter: FileWriter): Global =
4040
newGlobal(settings, new ExtConsoleReporter(settings, new PrintWriter(logWriter)))
4141

42-
def compile(runner: Runner, opts0: List[String], sources: List[File]): TestState = {
42+
43+
/** Massage args to merge plugins and fix paths.
44+
* Plugin path can be relative to test root, or cwd is out.
45+
* While we're at it, mix in the baseline options, too.
46+
* That's how ant passes in the plugins dir.
47+
*/
48+
private def updatePluginPath(args: List[String], out: AbstractFile, srcdir: AbstractFile): Seq[String] = {
49+
val dir = PathSettings.testRoot
50+
// The given path, or the output dir if ".", or a temp dir if output is virtual (since plugin loading doesn't like virtual)
51+
def pathOrCwd(p: String) =
52+
if (p == ".") {
53+
val plugxml = "scalac-plugin.xml"
54+
val pout = if (out.isVirtual) Directory.makeTemp() else Path(out.path)
55+
val srcpath = Path(srcdir.path)
56+
val pd = (srcpath / plugxml).toFile
57+
if (pd.exists) pd copyTo (pout / plugxml)
58+
pout
59+
} else Path(p)
60+
def absolutize(path: String) = pathOrCwd(path) match {
61+
case x if x.isAbsolute => x.path
62+
case x => (dir / x).toAbsolute.path
63+
}
64+
65+
val xprefix = "-Xplugin:"
66+
val (xplugs, others) = args partition (_ startsWith xprefix)
67+
val Xplugin = if (xplugs.isEmpty) Nil else List(xprefix +
68+
(xplugs map (_ stripPrefix xprefix) flatMap (_ split pathSeparator) map absolutize mkString pathSeparator)
69+
)
70+
runner.suiteRunner.scalacExtraArgs ++ PartestDefaults.scalacOpts.split(' ') ++ others ++ Xplugin
71+
}
72+
73+
def compile(opts0: List[String], sources: List[File]): TestState = {
4374
import runner.{ sources => _, _ }
4475
import ClassPath.{join, split}
4576

@@ -55,8 +86,8 @@ class DirectCompiler(val fileManager: FileManager) {
5586
val testSettings = new TestSettings(FileManager.joinPaths(classPath))
5687
val logWriter = new FileWriter(logFile)
5788
val srcDir = if (testFile.isDirectory) testFile else Path(testFile).parent.jfile
58-
val opts = fileManager.updatePluginPath(opts0, AbstractFile getDirectory outDir, AbstractFile getDirectory srcDir)
59-
val command = new CompilerCommand(opts, testSettings)
89+
val opts = updatePluginPath(opts0, AbstractFile getDirectory outDir, AbstractFile getDirectory srcDir)
90+
val command = new CompilerCommand(opts.toList, testSettings)
6091
val global = newGlobal(testSettings, logWriter)
6192
val reporter = global.reporter.asInstanceOf[ExtConsoleReporter]
6293
def errorCount = reporter.ERROR.count

src/main/scala/scala/tools/partest/nest/FileManager.scala

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,12 @@ object FileManager {
138138
class FileManager(val testClassPath: List[Path],
139139
val libraryUnderTest: Path,
140140
val reflectUnderTest: Path,
141-
val compilerUnderTest: Path,
142-
javaCmd: Option[String] = None,
143-
javacCmd: Option[String] = None,
144-
scalacOpts: Seq[String] = Seq.empty) {
145-
def this(testClassPath: List[Path], javaCmd: Option[String] = None, javacCmd: Option[String] = None, scalacOpts: Seq[String] = Seq.empty) {
141+
val compilerUnderTest: Path) {
142+
def this(testClassPath: List[Path]) {
146143
this(testClassPath,
147144
FileManager.fromClassPath("library", testClassPath),
148145
FileManager.fromClassPath("reflect", testClassPath),
149-
FileManager.fromClassPath("compiler", testClassPath),
150-
javaCmd,
151-
javacCmd,
152-
scalacOpts)
146+
FileManager.fromClassPath("compiler", testClassPath))
153147
}
154148

155149
def this(libraryUnderTest: Path, reflectUnderTest: Path, compilerUnderTest: Path) {
@@ -165,45 +159,11 @@ class FileManager(val testClassPath: List[Path],
165159
// basedir for jars or classfiles on core classpath
166160
lazy val baseDir = libraryUnderTest.parent
167161

168-
lazy val JAVACMD: String = javaCmd getOrElse PartestDefaults.javaCmd
169-
lazy val JAVAC_CMD: String = javacCmd getOrElse PartestDefaults.javacCmd
170-
lazy val SCALAC_OPTS: Seq[String] = scalacOpts ++ PartestDefaults.scalacOpts.split(' ').toSeq
171-
172162
def distKind = {
173163
val p = libraryUnderTest.getAbsolutePath
174164
if (p endsWith "build/quick/classes/library") "quick"
175165
else if (p endsWith "build/pack/lib/scala-library.jar") "pack"
176166
else if (p endsWith "dists/latest/lib/scala-library.jar/") "latest"
177167
else "installed"
178168
}
179-
180-
/** Massage args to merge plugins and fix paths.
181-
* Plugin path can be relative to test root, or cwd is out.
182-
* While we're at it, mix in the baseline options, too.
183-
* That's how ant passes in the plugins dir.
184-
*/
185-
def updatePluginPath(args: List[String], out: AbstractFile, srcdir: AbstractFile): List[String] = {
186-
val dir = PathSettings.testRoot
187-
// The given path, or the output dir if ".", or a temp dir if output is virtual (since plugin loading doesn't like virtual)
188-
def pathOrCwd(p: String) =
189-
if (p == ".") {
190-
val plugxml = "scalac-plugin.xml"
191-
val pout = if (out.isVirtual) Directory.makeTemp() else Path(out.path)
192-
val srcpath = Path(srcdir.path)
193-
val pd = (srcpath / plugxml).toFile
194-
if (pd.exists) pd copyTo (pout / plugxml)
195-
pout
196-
} else Path(p)
197-
def absolutize(path: String) = pathOrCwd(path) match {
198-
case x if x.isAbsolute => x.path
199-
case x => (dir / x).toAbsolute.path
200-
}
201-
202-
val xprefix = "-Xplugin:"
203-
val (xplugs, others) = args partition (_ startsWith xprefix)
204-
val Xplugin = if (xplugs.isEmpty) Nil else List(xprefix +
205-
(xplugs map (_ stripPrefix xprefix) flatMap (_ split pathSeparator) map absolutize mkString pathSeparator)
206-
)
207-
SCALAC_OPTS.toList ::: others ::: Xplugin
208-
}
209169
}

src/main/scala/scala/tools/partest/nest/Runner.scala

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import scala.tools.scalap.Main.decompileScala
2424
import scala.tools.scalap.scalax.rules.scalasig.ByteCode
2525
import scala.util.{ Try, Success, Failure }
2626
import ClassPath.{ join, split }
27-
import PartestDefaults.{ javaCmd, javacCmd }
2827
import TestState.{ Pass, Fail, Crash, Uninitialized, Updated }
2928

3029
import FileManager.{compareFiles, compareContents, joinPaths}
@@ -58,7 +57,11 @@ class TestTranscript {
5857
}
5958

6059
/** Run a single test. Rubber meets road. */
61-
class Runner(val testFile: File, fileManager: FileManager, updateCheck: Boolean) {
60+
class Runner(val testFile: File, val suiteRunner: SuiteRunner) {
61+
62+
import suiteRunner.{fileManager => fm, _}
63+
val fileManager = fm
64+
6265
import fileManager._
6366

6467
// Override to true to have the outcome of this test displayed
@@ -112,7 +115,7 @@ class Runner(val testFile: File, fileManager: FileManager, updateCheck: Boolean)
112115
def javac(files: List[File]): TestState = {
113116
// compile using command-line javac compiler
114117
val args = Seq(
115-
javacCmd,
118+
javacCmdPath,
116119
"-d",
117120
outDir.getAbsolutePath,
118121
"-classpath",
@@ -172,15 +175,15 @@ class Runner(val testFile: File, fileManager: FileManager, updateCheck: Boolean)
172175
"-Dpartest.cwd="+outDir.getParent,
173176
"-Dpartest.test-path="+testFullPath,
174177
"-Dpartest.testname="+fileBase,
175-
"-Djavacmd="+javaCmd,
176-
"-Djavaccmd="+javacCmd,
178+
"-Djavacmd="+javaCmdPath,
179+
"-Djavaccmd="+javacCmdPath,
177180
"-Duser.language=en",
178181
"-Duser.country=US"
179182
) ++ extras
180183

181184
val classpath = joinPaths(extraClasspath ++ testClassPath)
182185

183-
javaCmd +: (
186+
javaCmdPath +: (
184187
(PartestDefaults.javaOpts.split(' ') ++ extraJavaOptions ++ argString.split(' ')).map(_.trim).filter(_ != "").toList ++ Seq(
185188
"-classpath",
186189
join(outDir.toString, classpath)
@@ -426,10 +429,10 @@ class Runner(val testFile: File, fileManager: FileManager, updateCheck: Boolean)
426429
List(file)
427430
)
428431

429-
def newCompiler = new DirectCompiler(fileManager)
432+
def newCompiler = new DirectCompiler(this)
430433

431434
def attemptCompile(sources: List[File]): TestState = {
432-
val state = newCompiler.compile(this, flagsForCompilation(sources), sources)
435+
val state = newCompiler.compile(flagsForCompilation(sources), sources)
433436
if (!state.isOk)
434437
_transcript append ("\n" + file2String(logFile))
435438

@@ -533,7 +536,7 @@ class Runner(val testFile: File, fileManager: FileManager, updateCheck: Boolean)
533536
val antOptions =
534537
if (NestUI._verbose) List("-verbose", "-noinput")
535538
else List("-noinput")
536-
val cmd = javaCmd +: (
539+
val cmd = javaCmdPath +: (
537540
PartestDefaults.javaOpts.split(' ').map(_.trim).filter(_ != "") ++ Seq(
538541
"-classpath",
539542
antLauncherPath,
@@ -727,13 +730,17 @@ class Runner(val testFile: File, fileManager: FileManager, updateCheck: Boolean)
727730
if (!isPartestDebug)
728731
Directory(outDir).deleteRecursively()
729732
}
733+
730734
}
731735

732736
/** Extended by Ant- and ConsoleRunner for running a set of tests. */
733-
abstract class DirectRunner {
734-
def fileManager: FileManager
735-
def updateCheck: Boolean
736-
def failed: Boolean
737+
class SuiteRunner(
738+
val fileManager: FileManager,
739+
val updateCheck: Boolean,
740+
val failed: Boolean,
741+
val javaCmdPath: String = PartestDefaults.javaCmd,
742+
val javacCmdPath: String = PartestDefaults.javacCmd,
743+
val scalacExtraArgs: Seq[String] = Seq.empty) {
737744

738745
import PartestDefaults.{ numThreads, waitTime }
739746

@@ -746,7 +753,7 @@ abstract class DirectRunner {
746753

747754
s"""|Compiler under test: ${relativize(fileManager.compilerUnderTest.getAbsolutePath)}
748755
|Scala version is: $versionMsg
749-
|Scalac options are: ${fileManager.SCALAC_OPTS mkString " "}
756+
|Scalac options are: ${scalacExtraArgs.mkString(" ")}
750757
|Compilation Path: ${relativize(joinPaths(fileManager.testClassPath))}
751758
|Java binaries in: $vmBin
752759
|Java runtime is: $vmName
@@ -758,14 +765,34 @@ abstract class DirectRunner {
758765
// |Java Classpath: ${sys.props("java.class.path")}
759766
}
760767

761-
def runTest(manager: RunnerManager, testFile: File): TestState = manager runTest testFile
768+
def onFinishTest(testFile: File, result: TestState): TestState = result
769+
770+
def runTest(testFile: File): TestState = {
771+
val runner = new Runner(testFile, this)
772+
773+
// when option "--failed" is provided execute test only if log
774+
// is present (which means it failed before)
775+
val state =
776+
if (failed && !runner.logFile.canRead)
777+
runner.genPass()
778+
else {
779+
val (state, elapsed) =
780+
try timed(runner.run())
781+
catch {
782+
case t: Throwable => throw new RuntimeException(s"Error running $testFile", t)
783+
}
784+
NestUI.reportTest(state)
785+
runner.cleanup()
786+
state
787+
}
788+
onFinishTest(testFile, state)
789+
}
762790

763791
def runTestsForFiles(kindFiles: Array[File], kind: String): Array[TestState] = {
764792
NestUI.resetTestNumber(kindFiles.size)
765793

766794
val pool = Executors newFixedThreadPool numThreads
767-
val manager = new RunnerManager(kind, fileManager, failed, updateCheck)
768-
val futures = kindFiles map (f => pool submit callable(runTest(manager, f)))
795+
val futures = kindFiles map (f => pool submit callable(runTest(f)))
769796

770797
pool.shutdown()
771798
Try (pool.awaitTermination(waitTime) {
@@ -845,25 +872,3 @@ object Output {
845872
}
846873
}
847874
}
848-
849-
/** Use a Runner to run a test. */
850-
class RunnerManager(kind: String, fileManager: FileManager, failed: Boolean, updateCheck: Boolean) {
851-
def runTest(testFile: File): TestState = {
852-
val runner = new Runner(testFile, fileManager, updateCheck)
853-
854-
// when option "--failed" is provided execute test only if log
855-
// is present (which means it failed before)
856-
if (failed && !runner.logFile.canRead)
857-
runner.genPass()
858-
else {
859-
val (state, elapsed) =
860-
try timed(runner.run())
861-
catch {
862-
case t: Throwable => throw new RuntimeException(s"Error running $testFile", t)
863-
}
864-
NestUI.reportTest(state)
865-
runner.cleanup()
866-
state
867-
}
868-
}
869-
}

src/main/scala/scala/tools/partest/utils/Properties.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ package utils
1313
/** Loads partest.properties from the jar. */
1414
object Properties extends scala.util.PropertiesTrait {
1515
protected def propCategory = "partest"
16-
protected def pickJarBasedOn = classOf[nest.RunnerManager]
16+
protected def pickJarBasedOn = classOf[nest.Runner]
1717
override def isAvian = super.isAvian
1818
}

0 commit comments

Comments
 (0)