aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-02-28 17:34:53 -0600
committerJesse Luehrs <doy@tozt.net>2013-02-28 17:41:04 -0600
commitaa7bafe18b07e91af4afb96d1e3fc08479d897fb (patch)
tree802e3a1bacffa93f903a16770d9b2960ce9dacb2
parent7bf64f5b97e344de3a35aa2e4fb9dc1d2a8c4b0c (diff)
downloadscala-test-more-aa7bafe18b07e91af4afb96d1e3fc08479d897fb.tar.gz
scala-test-more-aa7bafe18b07e91af4afb96d1e3fc08479d897fb.zip
factor some stuff out of SummaryReporter
-rw-r--r--src/main/scala/org/perl8/test/harness/SummarizedTests.scala32
-rw-r--r--src/main/scala/org/perl8/test/harness/SummaryReporter.scala62
2 files changed, 51 insertions, 43 deletions
diff --git a/src/main/scala/org/perl8/test/harness/SummarizedTests.scala b/src/main/scala/org/perl8/test/harness/SummarizedTests.scala
new file mode 100644
index 0000000..afa5f41
--- /dev/null
+++ b/src/main/scala/org/perl8/test/harness/SummarizedTests.scala
@@ -0,0 +1,32 @@
+package org.perl8.test.harness
+
+import java.io.{PipedInputStream,PipedOutputStream}
+import scala.concurrent.Await
+import scala.concurrent.duration.Duration
+import scala.concurrent.ExecutionContext.Implicits.global
+import scala.concurrent.Future
+
+import org.perl8.test.tap.Consumer.{TAPResult,TodoDirective}
+import org.perl8.test.tap._
+import org.perl8.test.Test
+
+trait SummarizedTests {
+ def runOneTest (test: Test, cb: TAPEvent => Unit): TAPResult = {
+ val out = new PipedOutputStream
+ val in = new PipedInputStream(out)
+
+ val testFuture = Future {
+ Console.withOut(out) {
+ test.runInHarness
+ }
+ out.close
+ }
+
+ val parser = new Parser(cb)
+ val result = parser.parse(in)
+ in.close
+ Await.ready(testFuture, Duration.Inf)
+
+ result
+ }
+}
diff --git a/src/main/scala/org/perl8/test/harness/SummaryReporter.scala b/src/main/scala/org/perl8/test/harness/SummaryReporter.scala
index 273a7dc..b0c7f98 100644
--- a/src/main/scala/org/perl8/test/harness/SummaryReporter.scala
+++ b/src/main/scala/org/perl8/test/harness/SummaryReporter.scala
@@ -1,16 +1,10 @@
package org.perl8.test.harness
-import java.io.{PipedInputStream,PipedOutputStream}
-import scala.concurrent.Await
-import scala.concurrent.duration.Duration
-import scala.concurrent.ExecutionContext.Implicits.global
-import scala.concurrent.Future
-
import org.perl8.test.tap.Consumer.{TAPResult,TodoDirective}
import org.perl8.test.tap._
import org.perl8.test.Test
-class SummaryReporter extends MultiTestReporter {
+class SummaryReporter extends MultiTestReporter with SummarizedTests {
def run (testNames: Seq[String]): Int = {
val results = runTests(testNames)
val success = results.values.forall(_.success)
@@ -22,53 +16,39 @@ class SummaryReporter extends MultiTestReporter {
val maxLength = testNames.map(_.length).max
testNames.map { name =>
- val out = new PipedOutputStream
- val in = new PipedInputStream(out)
-
- val test = newInstance[Test](name)
-
- val testFuture = Future {
- Console.withOut(out) {
- test.runInHarness
- }
- out.close
- }
-
val callbackGenerator: () => TAPEvent => Unit = () => {
- var prevWidth = 0
+ var width = 0
var tests = 0
var plan: Option[Int] = None
- var failed = false
-
- def printStatus {
- print("\r")
- // print(("\b" * prevWidth) + (" " * prevWidth) + ("\b" * prevWidth))
- print(name + " " + ("." * (maxLength - name.length)) + ".. ")
- val display = tests + "/" + plan.getOrElse("?")
- prevWidth = display.length
- print(display)
+
+ def status = {
+ tests + "/" + plan.getOrElse("?")
+ }
+
+ def printStatus (st: String) {
+ print("\r" + (" " * width) + "\r")
+ val line =
+ name + " " + ("." * (maxLength - name.length)) + ".. " + st
+ width = line.length
+ print(line)
Console.out.flush
}
(e: TAPEvent) => e match {
case StartEvent => {
- print(name + " " + ("." * (maxLength - name.length)) + ".. ")
- Console.out.flush
+ printStatus("")
}
case PlanEvent(p) => {
plan = Some(p.plan)
- printStatus
+ printStatus(status)
}
case ResultEvent(r) => {
tests += 1
- if (!r.passed) {
- failed = true
- }
- printStatus
+ printStatus(status)
}
case EndEvent(result) => {
- print(("\b" * prevWidth) + (" " * prevWidth) + ("\b" * prevWidth))
if (result.success) {
+ printStatus("")
println("ok")
}
else {
@@ -77,6 +57,7 @@ class SummaryReporter extends MultiTestReporter {
!t.passed && !t.directive.isDefined
}
+ printStatus("")
println("Dubious, test returned " + result.exitCode)
println("Failed " + failed + "/" + results + " subtests")
}
@@ -85,12 +66,7 @@ class SummaryReporter extends MultiTestReporter {
}
}
- val parser = new Parser(callbackGenerator())
- val result = parser.parse(in)
- in.close
- Await.ready(testFuture, Duration.Inf)
-
- name -> result
+ name -> runOneTest(newInstance[Test](name), callbackGenerator())
}.toMap
}