From f61dba1b12fc764f774b57a639f2630de63a9076 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Wed, 25 Apr 2018 15:06:44 +0200 Subject: [PATCH] Remove ant support Now that https://github.com/scala/scala/pull/6255 is merged --- README.md | 6 +- build.sbt | 1 - .../resources/scala/tools/partest/antlib.xml | 4 - .../scala/tools/partest/PartestTask.scala | 160 ------------------ .../scala/tools/partest/nest/AntRunner.scala | 64 ------- .../scala/tools/partest/nest/Runner.scala | 44 +---- .../scala/tools/partest/nest/RunnerSpec.scala | 1 - 7 files changed, 3 insertions(+), 277 deletions(-) delete mode 100644 src/main/resources/scala/tools/partest/antlib.xml delete mode 100644 src/main/scala/scala/tools/partest/PartestTask.scala delete mode 100644 src/main/scala/scala/tools/partest/nest/AntRunner.scala diff --git a/README.md b/README.md index 82de207..540cf6d 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,7 @@ Test categories (subdirectories under `test/files`) As partest links directly against the compiler being tested, it's cross-versioned against the compiler version that it's intended for. -There are three ways of invoking partest: - - - ant (see https://github.com/scala/scala/blob/2.11.x/test/build-partest.xml and https://github.com/scala/scala-partest/blob/master/src/main/scala/scala/tools/partest/PartestTask.scala) - - sbt (details below) - - the [test/partest script](https://github.com/scala/scala/blob/2.11.x/test/partest), which uses ant to set up the classpath in the same way as the ant task, but then launches [ConsoleRunner](https://github.com/scala/scala-partest/blob/master/src/main/scala/scala/tools/partest/nest/ConsoleRunner.scala) directly. +Partest is invoked from sbt. The compiler to be tested must be on the classpath. The corresponding jar or class directory is detected by [FileManager::findArtifact](https://github.com/scala/scala-partest/blob/master/src/main/scala/scala/tools/partest/nest/FileManager.scala#L123). diff --git a/build.sbt b/build.sbt index 8a8112c..8ca9bb6 100644 --- a/build.sbt +++ b/build.sbt @@ -21,7 +21,6 @@ enableOptimizer // dependencies // versions involved in integration builds / that change frequently should be keys, set above! -libraryDependencies += "org.apache.ant" % "ant" % "1.8.4" % "provided" libraryDependencies += "com.googlecode.java-diff-utils" % "diffutils" % "1.3.0" libraryDependencies += "org.scala-sbt" % "test-interface" % "1.0" // mark all scala dependencies as provided which means one has to explicitly provide them when depending on partest diff --git a/src/main/resources/scala/tools/partest/antlib.xml b/src/main/resources/scala/tools/partest/antlib.xml deleted file mode 100644 index b3b98e8..0000000 --- a/src/main/resources/scala/tools/partest/antlib.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - diff --git a/src/main/scala/scala/tools/partest/PartestTask.scala b/src/main/scala/scala/tools/partest/PartestTask.scala deleted file mode 100644 index ab46494..0000000 --- a/src/main/scala/scala/tools/partest/PartestTask.scala +++ /dev/null @@ -1,160 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala Parallel Testing ** -** / __/ __// _ | / / / _ | (c) 2007-2013, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -package scala.tools -package partest - -import scala.tools.nsc.Properties.propOrFalse -import scala.tools.ant.sabbus.CompilationPathProperty -import org.apache.tools.ant.Task -import org.apache.tools.ant.types.Reference -import org.apache.tools.ant.types.Commandline.Argument -import scala.tools.ant.ScalaTask -import nest.NestUI -import java.net.URLClassLoader - -/** An Ant task to execute the Scala test suite (NSC). - * - * This task can take the following parameters as attributes: - * - `srcdir`, - * - `classpath`, - * - `classpathref`, - * - `erroronfailed`, - * - `javacmd`, - * - `javaccmd`, - * - `scalacopts`, - * - `debug`, - * - `junitreportdir`. - * - * It also takes the following parameters as nested elements: - * - `compilationpath`. -- TODO: this parameter is now redundant: it's the same as the classpath used to run the task - * - * @author Philipp Haller, Adriaan Moors - */ -class PartestTask extends Task with CompilationPathProperty with ScalaTask { - type Path = org.apache.tools.ant.types.Path - - private var kinds: Array[String] = Array.empty - private var classpath: Option[Path] = None - private var debug = false - private var errorOnFailed: Boolean = true - private var jUnitReportDir: Option[File] = None - private var javaccmd: Option[File] = None - private var javacmd: Option[File] = Option(sys.props("java.home")) map (x => new File(x, "bin/java")) - private var javaOpts: Option[Seq[String]] = None - private var scalacArgs: Option[Seq[Argument]] = None - private var srcDir: Option[String] = None - private var colors: Int = 0 - - def setSrcDir(input: String) { - srcDir = Some(input) - } - - def setColors(input: String) { - try colors = input.toInt catch { case _: NumberFormatException => () } - if (colors > 0) - sys.props("partest.colors") = colors.toString - } - - def setClasspath(input: Path) { - if (classpath.isEmpty) - classpath = Some(input) - else - classpath.get.append(input) - } - - def createClasspath(): Path = { - if (classpath.isEmpty) classpath = Some(new Path(getProject())) - classpath.get.createPath() - } - - def setClasspathref(input: Reference) { - createClasspath().setRefid(input) - } - def setErrorOnFailed(input: Boolean) { - errorOnFailed = input - } - - def setJavaCmd(input: File) { - javacmd = Some(input) - } - - def setJavaOpts(input: String) { - val s = input.split(' ') - javaOpts = Some(javaOpts.getOrElse(Seq()) ++ s) - } - - def setKinds(input: String) { - kinds = words(input).toArray - } - - def setJavacCmd(input: File) { - javaccmd = Some(input) - } - - def setScalacOpts(input: String) { - val s = input.split(' ').map { s => val a = new Argument; a.setValue(s); a } - scalacArgs = Some(scalacArgs.getOrElse(Seq()) ++ s) - } - - def createCompilerArg(): Argument = { - val a = new Argument - scalacArgs = Some(scalacArgs.getOrElse(Seq()) :+ a) - a - } - - def setDebug(input: Boolean) { - debug = input - } - - def setJUnitReportDir(input: File) { - jUnitReportDir = Some(input) - } - - override def execute() { - val nestUI: NestUI = new NestUI(debug = debug || propOrFalse("partest.debug")) - - if (compilationPath.isEmpty) sys.error("Mandatory attribute 'compilationPath' is not set.") - - def scalacArgsFlat: Array[String] = scalacArgs.toArray flatMap (_ flatMap { a => - val parts = a.getParts - if (parts eq null) Array.empty[String] else parts - }) - - var failureCount = 0 - val summary = new scala.tools.partest.nest.AntRunner(srcDir.getOrElse(null), new URLClassLoader(compilationPath.get.list.map(Path(_).toURL)), javacmd.getOrElse(null), javaccmd.getOrElse(null), scalacArgsFlat, javaOpts, nestUI) { - def echo(msg: String): Unit = PartestTask.this.log(msg) - def log(msg: String): Unit = PartestTask.this.log(msg) - - def onFinishKind(kind: String, passed: Array[TestState], failed: Array[TestState]) = { - failureCount += failed.size - - def oneResult(res: TestState) = - { - if (res.isOk) scala.xml.NodeSeq.Empty - else - } - - // create JUnit Report xml files if directory was specified - jUnitReportDir foreach { d => - d.mkdir - val report = - - { passed map oneResult }{ failed map oneResult } - - - scala.xml.XML.save(d.getAbsolutePath + "/" + kind + ".xml", report) - } - } - } execute (kinds) - - if (errorOnFailed && failureCount > 0) buildError(summary) - else log(summary) - - } -} diff --git a/src/main/scala/scala/tools/partest/nest/AntRunner.scala b/src/main/scala/scala/tools/partest/nest/AntRunner.scala deleted file mode 100644 index 4800172..0000000 --- a/src/main/scala/scala/tools/partest/nest/AntRunner.scala +++ /dev/null @@ -1,64 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala Parallel Testing ** -** / __/ __// _ | / / / _ | (c) 2007-2013, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -package scala.tools.partest -package nest - -import java.net.URLClassLoader - -// not using any Scala types to ease calling across different scala versions -abstract class AntRunner(srcDir: String, testClassLoader: URLClassLoader, javaCmd: File, javacCmd: File, scalacArgs: Array[String], javaOpts: Option[Seq[String]], nestUI: NestUI) extends SuiteRunner( - testSourcePath = Option(srcDir) getOrElse PartestDefaults.sourcePath, - new FileManager(testClassLoader = testClassLoader), - updateCheck = false, - failed = false, - nestUI = nestUI, - javaCmdPath = Option(javaCmd).map(_.getAbsolutePath) getOrElse PartestDefaults.javaCmd, - javacCmdPath = Option(javacCmd).map(_.getAbsolutePath) getOrElse PartestDefaults.javacCmd, - scalacExtraArgs = scalacArgs.toIndexedSeq, - javaOpts = javaOpts.map(_.mkString(" ")).getOrElse(PartestDefaults.javaOpts)) { - - def error(msg: String): Nothing = sys.error(msg) - def echo(msg: String): Unit - def log(msg: String): Unit - def onFinishKind(kind: String, passed: Array[TestState], failed: Array[TestState]): Unit - - final def runSet(kind: String, files: Array[File]): (Int, Int, Array[String]) = { - if (files.isEmpty) (0, 0, Array.empty[String]) - else { - log(s"Running ${files.length} tests in '$kind' at $now") - // log(s"Tests: ${files.toList}") - val results = runTestsForFiles(files, kind) - val (passed, failed) = results partition (_.isOk) - val numPassed = passed.size - val numFailed = failed.size - def failedMessages = failed map (_.longStatus) - - onFinishKind(kind, passed, failed) - - (numPassed, numFailed, failedMessages) - } - } - - // called reflectively from scala-partest-test-interface - final def execute(kinds: Array[String]): String = { - echo(banner) - - val _results = kinds map (k => runSet(k, TestKinds testsFor k map (_.jfile) toArray)) - - val allSuccesses = _results map (_._1) sum - val allFailures = _results map (_._2) sum - val allFailedPaths = _results flatMap (_._3) - - if (allFailures > 0) - s"Test suite finished with $allFailures case${if (allFailures > 1) "s" else ""} failing:\n" + - allFailedPaths.mkString("\n") - else if (allSuccesses == 0) "There were no tests to run." - else "Test suite finished with no failures." - } -} diff --git a/src/main/scala/scala/tools/partest/nest/Runner.scala b/src/main/scala/scala/tools/partest/nest/Runner.scala index 7df0242..e298ff0 100644 --- a/src/main/scala/scala/tools/partest/nest/Runner.scala +++ b/src/main/scala/scala/tools/partest/nest/Runner.scala @@ -18,7 +18,7 @@ import scala.concurrent.duration.Duration import scala.reflect.internal.FatalError import scala.reflect.internal.util.ScalaClassLoader import scala.sys.process.{Process, ProcessLogger} -import scala.tools.nsc.Properties.{envOrNone, isWin, javaHome, javaVmInfo, javaVmName, javaVmVersion, propOrEmpty, versionMsg} +import scala.tools.nsc.Properties.{isWin, javaHome, javaVmInfo, javaVmName, javaVmVersion, propOrEmpty, versionMsg} import scala.tools.nsc.{CompilerCommand, Global, Settings} import scala.tools.nsc.reporters.ConsoleReporter import scala.tools.nsc.util.stackTraceString @@ -89,9 +89,6 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner, val nestUI: NestU lazy val outDir = { outFile.mkdirs() ; outFile } - // oh boy... - private lazy val antLauncher = SFile(Path(envOrNone("ANT_HOME") getOrElse "/opt/ant/") / "lib/ant-launcher.jar") - type RanOneTest = (Boolean, LogContext) def showCrashInfo(t: Throwable) { @@ -594,42 +591,6 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner, val nestUI: NestU compilationRounds(testFile).forall(x => nextTestActionExpectTrue("compilation failed", x.isOk)) && andAlso } - // Apache Ant 1.6 or newer - def ant(args: Seq[String], output: File): Boolean = { - val antOptions = - if (nestUI.verbose) List("-verbose", "-noinput") - else List("-noinput") - val cmd = javaCmdPath +: ( - suiteRunner.javaOpts.split(' ').map(_.trim).filter(_ != "") ++ Seq( - "-classpath", - antLauncher.path, - "org.apache.tools.ant.launch.Launcher" - ) ++ antOptions ++ args - ) - - runCommand(cmd.toIndexedSeq, output) - } - - def runAntTest(): (Boolean, LogContext) = { - val (swr, wr) = newTestWriters() - - val succeeded = try { - val binary = "-Dbinary="+ fileManager.distKind - val args = Array(binary, "-logfile", logFile.getPath, "-file", testFile.getPath) - nestUI.verbose("ant "+args.mkString(" ")) - - pushTranscript(s"ant ${args.mkString(" ")}") - nextTestActionExpectTrue("ant failed", ant(args.toIndexedSeq, logFile)) && diffIsOk - } - catch { // *catch-all* - case e: Exception => - nestUI.warning("caught "+e) - false - } - - (succeeded, LogContext(logFile, swr, wr)) - } - def extraClasspath = kind match { case "specialized" => List(PathSettings.srcSpecLib.fold(sys.error, identity)) case _ => Nil @@ -714,7 +675,6 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner, val nestUI: NestU if (kind == "neg" || (kind endsWith "-neg")) runNegTest() else kind match { case "pos" => runTestCommon(true) - case "ant" => runAntTest() case "res" => runResidentTest() case "scalap" => runScalapTest() case "script" => runScriptTest() @@ -792,7 +752,7 @@ object Properties extends scala.util.PropertiesTrait { protected def pickJarBasedOn = classOf[SuiteRunner] } -/** Extended by Ant- and ConsoleRunner for running a set of tests. */ +/** Used by SBT- and ConsoleRunner for running a set of tests. */ class SuiteRunner( val testSourcePath: String, // relative path, like "files", or "pending" val fileManager: FileManager, diff --git a/src/main/scala/scala/tools/partest/nest/RunnerSpec.scala b/src/main/scala/scala/tools/partest/nest/RunnerSpec.scala index 850d141..88c259d 100644 --- a/src/main/scala/scala/tools/partest/nest/RunnerSpec.scala +++ b/src/main/scala/scala/tools/partest/nest/RunnerSpec.scala @@ -17,7 +17,6 @@ trait RunnerSpec extends Spec with Meta.StdOpts with Interpolation { val optRun = "run" / "run interpreter and backend tests" --? val optJvm = "jvm" / "run JVM backend tests" --? val optRes = "res" / "run resident compiler tests" --? - val optAnt = "ant" / "run Ant tests" --? val optScalap = "scalap" / "run scalap tests" --? val optSpecialized = "specialized" / "run specialization tests" --? val optInstrumented = "instrumented" / "run instrumented tests" --?