summaryrefslogtreecommitdiff
path: root/src/partest
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-03-02 22:28:45 +0000
committerPaul Phillips <paulp@improving.org>2010-03-02 22:28:45 +0000
commit649c18aeae2136b416683d8437012cd40dac1b59 (patch)
tree9699ff34bd694f51ba223b704315730a3ba04d73 /src/partest
parent1b5c4b93ecf8f63e81c23c38b277b5aad41d5551 (diff)
downloadscala-649c18aeae2136b416683d8437012cd40dac1b59.tar.gz
scala-649c18aeae2136b416683d8437012cd40dac1b59.tar.bz2
scala-649c18aeae2136b416683d8437012cd40dac1b59.zip
Added --grep command line option to partest.
test with the string "Manifest" in the source file, you may now do: ./partest --grep Manifest No review.
Diffstat (limited to 'src/partest')
-rw-r--r--src/partest/scala/tools/partest/nest/ConsoleRunner.scala47
-rw-r--r--src/partest/scala/tools/partest/nest/NestUI.scala1
-rw-r--r--src/partest/scala/tools/partest/nest/PathSettings.scala10
3 files changed, 40 insertions, 18 deletions
diff --git a/src/partest/scala/tools/partest/nest/ConsoleRunner.scala b/src/partest/scala/tools/partest/nest/ConsoleRunner.scala
index 3701985e1a..f7eca614ac 100644
--- a/src/partest/scala/tools/partest/nest/ConsoleRunner.scala
+++ b/src/partest/scala/tools/partest/nest/ConsoleRunner.scala
@@ -16,10 +16,10 @@ 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 }
+import io.{ Path, Process }
class ConsoleRunner extends DirectRunner {
- import PathSettings.srcDir
+ import PathSettings.{ srcDir, testRoot }
case class TestSet(kind: String, filter: Path => Boolean, msg: String)
@@ -60,8 +60,12 @@ class ConsoleRunner extends DirectRunner {
"--failed", "--version", "--ansi", "--debug"
) ::: testSetArgs
+ private val binaryArgs = List(
+ "--grep", "--srcpath", "--buildpath", "--classpath"
+ )
+
def main(argstr: String) {
- val parsed = CommandLineParser(argstr) withUnaryArguments unaryArgs
+ val parsed = CommandLineParser(argstr) withUnaryArgs unaryArgs withBinaryArgs binaryArgs
val args = parsed.residualArgs
/** Early return on no args, version, or invalid args */
@@ -82,12 +86,6 @@ class ConsoleRunner extends DirectRunner {
else new ConsoleFileManager // auto detection, see ConsoleFileManager.findLatest
def argNarrowsTests(x: String) = denotesTestSet(x) || denotesTestFile(x) || denotesTestDir(x)
- val enabledTestSets: List[TestSet] = {
- val enabledArgs = testSetArgs filter parsed.isSet
-
- if (args.isEmpty && (enabledArgs.isEmpty || (parsed isSet "--all"))) testSets
- else enabledArgs map testSetArgMap
- }
NestUI._verbose = parsed isSet "--verbose"
fileManager.showDiff = parsed isSet "--show-diff"
@@ -98,14 +96,33 @@ class ConsoleRunner extends DirectRunner {
if (parsed isSet "--timeout") fileManager.timeout = parsed("--timeout")
if (parsed isSet "--debug") setProp("partest.debug", "true")
- testFiles :::= args map { arg =>
- val file = new File(arg)
- if (!file.exists) {
- NestUI.failure("File \"%s\" not found\n" format arg)
- System.exit(1)
+ def addTestFile(file: File) = {
+ if (!file.exists)
+ NestUI.failure("Test file '%s' not found, skipping.\n" format file)
+ else {
+ NestUI.verbose("adding test file " + file)
+ testFiles +:= file
}
+ }
+
+ // If --grep is given we suck in every file it matches.
+ parsed get "--grep" foreach { expr =>
+ val allFiles = srcDir.deepList() filter (_ hasExtension "scala") map (_.toFile) toList
+ val files = allFiles filter (_.slurp() contains expr)
- returning[File](file)(x => NestUI.verbose("adding test file " + x))
+ if (files.isEmpty) NestUI.failure("--grep string '%s' matched no files." format expr)
+ else NestUI.verbose("--grep string '%s' matched %d file(s)".format(expr, files.size))
+
+ files foreach (x => addTestFile(x.jfile))
+ }
+ args foreach (x => addTestFile(new File(x)))
+
+ // If no file arguments were given, we assume --all
+ val enabledTestSets: List[TestSet] = {
+ val enabledArgs = testSetArgs filter parsed.isSet
+
+ if (args.isEmpty && !(parsed isSet "--grep") && (enabledArgs.isEmpty || (parsed isSet "--all"))) testSets
+ else enabledArgs map testSetArgMap
}
val dir =
diff --git a/src/partest/scala/tools/partest/nest/NestUI.scala b/src/partest/scala/tools/partest/nest/NestUI.scala
index c05730c4ff..efff4e8375 100644
--- a/src/partest/scala/tools/partest/nest/NestUI.scala
+++ b/src/partest/scala/tools/partest/nest/NestUI.scala
@@ -80,6 +80,7 @@ object NestUI {
println(" --scalacheck run ScalaCheck tests")
println(" --script run script runner tests")
println(" --shootout run shootout tests")
+ println(" --grep <expr> run all tests whose source file contains <expr>")
println
println(" Other options:")
println(" --pack pick compiler/library in build/pack, and run all tests")
diff --git a/src/partest/scala/tools/partest/nest/PathSettings.scala b/src/partest/scala/tools/partest/nest/PathSettings.scala
index 4ecee721bc..41bba5782e 100644
--- a/src/partest/scala/tools/partest/nest/PathSettings.scala
+++ b/src/partest/scala/tools/partest/nest/PathSettings.scala
@@ -18,17 +18,21 @@ object PathSettings {
private def cwd = Directory.Current getOrElse error("user.dir property not set")
private def isPartestDir(d: Directory) = (d.name == "test") && (d / srcDirName isDirectory)
+ // Directory <root>/test
lazy val testRoot: Directory = testRootDir getOrElse {
val candidates: List[Directory] = (cwd :: cwd.parents) flatMap (d => List(d, Directory(d / "test")))
candidates find isPartestDir getOrElse error("Directory 'test' not found.")
}
+ // Directory <root>/test/files
lazy val srcDir = Directory(testRoot / srcDirName normalize)
- lazy val scalaCheck = {
- val libdir = Directory(testRoot / "files" / "lib")
- libdir.files find (_.name startsWith "scalacheck") getOrElse error("No scalacheck jar found in '%s'" format libdir)
+ // Directory <root>/test/files/lib
+ lazy val srcLibDir = Directory(srcDir / "lib")
+
+ lazy val scalaCheck = srcLibDir.files find (_.name startsWith "scalacheck") getOrElse {
+ error("No scalacheck jar found in '%s'" format srcLibDir)
}
}