summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-01-26 00:21:17 +0000
committerPaul Phillips <paulp@improving.org>2011-01-26 00:21:17 +0000
commit85fbd6f10043ae4ef811dfbf92356dd6a09f205c (patch)
tree86be4caf4a94125522233e7a6059fdca2f2b903d
parent3cf67d788a747191f78fce8150194b3c1c48e7be (diff)
downloadscala-85fbd6f10043ae4ef811dfbf92356dd6a09f205c.tar.gz
scala-85fbd6f10043ae4ef811dfbf92356dd6a09f205c.tar.bz2
scala-85fbd6f10043ae4ef811dfbf92356dd6a09f205c.zip
partest --grep has never worked quite right (at...
partest --grep has never worked quite right (at least not in the "sideported" version.) Now it looks harder for matching tests: the check file or any java or scala source file can match. And directory based tests will be properly included. Try it out: test/partest --grep java No review.
-rw-r--r--src/partest/scala/tools/partest/nest/ConsoleRunner.scala35
-rw-r--r--src/partest/scala/tools/partest/nest/NestRunner.scala3
-rw-r--r--src/partest/scala/tools/partest/nest/Worker.scala4
-rw-r--r--src/partest/scala/tools/partest/package.scala9
4 files changed, 36 insertions, 15 deletions
diff --git a/src/partest/scala/tools/partest/nest/ConsoleRunner.scala b/src/partest/scala/tools/partest/nest/ConsoleRunner.scala
index b665974ec8..b79c2bbbdb 100644
--- a/src/partest/scala/tools/partest/nest/ConsoleRunner.scala
+++ b/src/partest/scala/tools/partest/nest/ConsoleRunner.scala
@@ -65,6 +65,16 @@ class ConsoleRunner extends DirectRunner {
"--grep", "--srcpath", "--buildpath", "--classpath"
)
+ // true if a test path matches the --grep expression.
+ private def pathMatchesExpr(path: Path, expr: String) = {
+ def pred(p: Path) = file2String(p.toFile) contains expr
+ def srcs = path.toDirectory.deepList() filter (_.hasExtension("scala", "java"))
+
+ (path.isFile && pred(path)) ||
+ (path.isDirectory && srcs.exists(pred)) ||
+ (pred(Path(path.toAbsolute.stripExtension + ".check")))
+ }
+
def main(argstr: String) {
val parsed = CommandLineParser(argstr) withUnaryArgs unaryArgs withBinaryArgs binaryArgs
val args = parsed.residualArgs
@@ -112,15 +122,21 @@ class ConsoleRunner extends DirectRunner {
}
// 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)
- 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))
+ val grepOption = parsed get "--grep"
+ val grepPaths = grepOption.toList flatMap { expr =>
+ val subjectDirs = testSetKinds map (srcDir / _ toDirectory)
+ val testPaths = subjectDirs flatMap (_.files filter (x => x.hasExtension("scala") || x.isDirectory))
+ val paths = testPaths filter (p => pathMatchesExpr(p, expr))
+
+ if (paths.isEmpty)
+ NestUI.failure("--grep string '%s' matched no tests." format expr)
- files foreach (x => addTestFile(x.jfile))
+ paths map (_.jfile)
}
+ val grepMessage = grepOption map (x => "Argument '%s' matched %d test(s)".format(x, grepPaths.size)) getOrElse ""
+
+ grepPaths foreach addTestFile
args foreach (x => addTestFile(new File(x)))
// If no file arguments were given, we assume --all
@@ -156,6 +172,10 @@ class ConsoleRunner extends DirectRunner {
NestUI.verbose("available processors: " + Runtime.getRuntime().availableProcessors())
+ // Dragged down here so it isn't buried under the banner.
+ if (grepMessage != "")
+ NestUI.normal(grepMessage + "\n")
+
val start = System.currentTimeMillis
val (successes, failures) = testCheckAll(enabledTestSets)
val end = System.currentTimeMillis
@@ -203,8 +223,9 @@ class ConsoleRunner extends DirectRunner {
val (valid, invalid) = testFiles partition (x => testSetKinds contains kindOf(x))
invalid foreach (x => NestUI.failure("Invalid test file '%s', skipping.\n" format x))
+ val grouped = (valid groupBy kindOf).toList sortBy (x => testSetKinds indexOf x._1)
val runTestsFileLists =
- for ((kind, files) <- valid groupBy kindOf toList) yield {
+ for ((kind, files) <- grouped) yield {
NestUI.outline("\nTesting individual files\n")
resultsToStatistics(runTestsForFiles(files, kind))
}
diff --git a/src/partest/scala/tools/partest/nest/NestRunner.scala b/src/partest/scala/tools/partest/nest/NestRunner.scala
index 897975f330..27c1ef64f0 100644
--- a/src/partest/scala/tools/partest/nest/NestRunner.scala
+++ b/src/partest/scala/tools/partest/nest/NestRunner.scala
@@ -10,7 +10,6 @@ package nest
object NestRunner {
def main(args: Array[String]) {
- val argstr = args.mkString(" ")
- (new ReflectiveRunner).main(argstr)
+ new ReflectiveRunner main (args mkString " ")
}
}
diff --git a/src/partest/scala/tools/partest/nest/Worker.scala b/src/partest/scala/tools/partest/nest/Worker.scala
index 2278cb4def..5c6f8832f3 100644
--- a/src/partest/scala/tools/partest/nest/Worker.scala
+++ b/src/partest/scala/tools/partest/nest/Worker.scala
@@ -374,10 +374,6 @@ class Worker(val fileManager: FileManager, params: TestRunParams) extends Actor
else diff
}
- def file2String(f: File) =
- try SFile(f).slurp()
- catch { case _: FileNotFoundException => "" }
-
def isJava(f: File) = SFile(f) hasExtension "java"
def isScala(f: File) = SFile(f) hasExtension "scala"
def isJavaOrScala(f: File) = isJava(f) || isScala(f)
diff --git a/src/partest/scala/tools/partest/package.scala b/src/partest/scala/tools/partest/package.scala
index 02e4e4e445..5bcc66ddbd 100644
--- a/src/partest/scala/tools/partest/package.scala
+++ b/src/partest/scala/tools/partest/package.scala
@@ -4,8 +4,8 @@
package scala.tools
-import java.io.{ File => JFile }
-import nsc.io.{ Path, Directory }
+import java.io.{ FileNotFoundException, File => JFile }
+import nsc.io.{ Path, Directory, File => SFile }
import util.{ PathResolver }
import nsc.Properties.{ propOrElse, propOrNone, propOrEmpty }
import scala.sys.process.javaVmArguments
@@ -16,6 +16,11 @@ package object partest {
implicit private[partest] def temporaryPath2File(x: Path): JFile = x.jfile
implicit private[partest] def temporaryFile2Path(x: JFile): Path = Path(x)
+ def path2String(path: String) = file2String(new JFile(path))
+ def file2String(f: JFile) =
+ try SFile(f).slurp()
+ catch { case _: FileNotFoundException => "" }
+
def basename(name: String): String = Path(name).stripExtension
def resultsToStatistics(results: Iterable[(_, Int)]): (Int, Int) = {