aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-02-28 11:37:48 -0600
committerJesse Luehrs <doy@tozt.net>2013-02-28 11:37:48 -0600
commita908ee5ea0933a1841acf7a96ed37ff73568b26e (patch)
tree17a7eba560e599ee430c71955bf0f65c38088f10 /src
parentd103327785c10b5c538e4eb8b81007d22c39f4ed (diff)
downloadscala-test-more-a908ee5ea0933a1841acf7a96ed37ff73568b26e.tar.gz
scala-test-more-a908ee5ea0933a1841acf7a96ed37ff73568b26e.zip
refactor the harness application a bit
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/org/perl8/test/harness/TestHarness.scala68
1 files changed, 50 insertions, 18 deletions
diff --git a/src/main/scala/org/perl8/test/harness/TestHarness.scala b/src/main/scala/org/perl8/test/harness/TestHarness.scala
index 4865c2c..09f780b 100644
--- a/src/main/scala/org/perl8/test/harness/TestHarness.scala
+++ b/src/main/scala/org/perl8/test/harness/TestHarness.scala
@@ -4,34 +4,66 @@ object TestHarness {
import org.perl8.test.Test
def main (args: Array[String]) {
- val (reporterName, idx, multi) = if (args.length >= 2 && args(0) == "-r") {
- (args(1), 2, false)
- }
- else if (args.length >= 2 && args(0) == "-R") {
- (args(1), 2, true)
- }
- else if (args.length > 1) {
- ("org.perl8.test.harness.SummaryReporter", 0, true)
- }
- else if (args.length == 1) {
- ("org.perl8.test.harness.TAPReporter", 0, false)
- }
- else {
- println("No tests specified!")
- sys.exit(1)
- }
+ val opts = parseOpts(args.toList)
+ val multi = !opts("prefer-single").asInstanceOf[Boolean]
val exitCode = if (multi) {
- val testNames = args.drop(idx)
+ val reporterName = opts("multi-reporter").asInstanceOf[String]
+ val testNames = opts("test-classes").asInstanceOf[List[String]]
val reporter = newInstance[MultiTestReporter](reporterName)
reporter.run(testNames)
}
else {
- val testName = args(idx)
+ val reporterName = opts("single-reporter").asInstanceOf[String]
+ val testName = opts("test-classes").asInstanceOf[List[String]].apply(0)
val reporter = newInstance[Reporter](reporterName)
reporter.run(testName)
}
sys.exit(exitCode)
}
+
+ def parseOpts (args: List[String]): Map[String, Any] = args match {
+ case "-r" :: singleReporter :: rest =>
+ parseOpts(rest) + ("single-reporter" -> singleReporter)
+
+ case "-R" :: multiReporter :: rest =>
+ parseOpts(rest) ++ Map(
+ "multi-reporter" -> multiReporter,
+ "prefer-single" -> false
+ )
+
+ case "--help" :: rest =>
+ usage(0)
+
+ case Nil => Map(
+ "single-reporter" -> "org.perl8.test.harness.TAPReporter",
+ "multi-reporter" -> "org.perl8.test.harness.SummaryReporter",
+ "prefer-single" -> true,
+ "test-classes" -> Nil
+ )
+
+ case `unknownOption` =>
+ usage(1)
+
+ case testClass :: rest => {
+ val opts = parseOpts(rest)
+ val tests = opts("test-classes").asInstanceOf[List[String]]
+ opts ++ Map(
+ "test-classes" -> (testClass :: tests),
+ "prefer-single" -> tests.isEmpty
+ )
+ }
+ }
+
+ def usage (exitCode: Int) = {
+ val out = if (exitCode == 0) Console.out else Console.err
+ out.println("harness [-r <single-reporter-class>]\n" +
+ " [-R <multi-reporter-class>]\n" +
+ " [--help]\n" +
+ " <test-class> [<test-class>...]\n")
+ sys.exit(exitCode)
+ }
+
+ private val unknownOption = """^-.*""".r
}