aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-02-27 19:18:20 -0600
committerJesse Luehrs <doy@tozt.net>2013-02-27 19:18:20 -0600
commite669339dc394cfa42ae7d7ccae291328dc64e5d8 (patch)
treee1516fc0d07d4f819be7b1ac1387ec8255625cfe
parent3f6db5f9a57191ce5b8a0812af3f7b1f26e84af1 (diff)
downloadscala-test-more-e669339dc394cfa42ae7d7ccae291328dc64e5d8.tar.gz
scala-test-more-e669339dc394cfa42ae7d7ccae291328dc64e5d8.zip
use the new stream parsing stuff in the summary reporter
-rw-r--r--src/main/scala/org/perl8/test/harness/SummaryReporter.scala82
1 files changed, 66 insertions, 16 deletions
diff --git a/src/main/scala/org/perl8/test/harness/SummaryReporter.scala b/src/main/scala/org/perl8/test/harness/SummaryReporter.scala
index d70b007..fdf7967 100644
--- a/src/main/scala/org/perl8/test/harness/SummaryReporter.scala
+++ b/src/main/scala/org/perl8/test/harness/SummaryReporter.scala
@@ -1,9 +1,13 @@
package org.perl8.test.harness
-import java.io.ByteArrayOutputStream
+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
import org.perl8.test.tap.Consumer.{TAPResult,TodoDirective}
+import org.perl8.test.tap._
import org.perl8.test.Test
class SummaryReporter extends MultiTestReporter {
@@ -18,28 +22,74 @@ class SummaryReporter extends MultiTestReporter {
val maxLength = testNames.map(_.length).max
testNames.map { name =>
- print(name + ("." * (maxLength - name.length)) + "... ")
+ val out = new PipedOutputStream
+ val in = new PipedInputStream(out)
- val out = new ByteArrayOutputStream
val test = newInstance[Test](name)
- Console.withOut(out) {
- test.run
- }
- val result = (new tap.Parser).parse(out)
- if (result.success) {
- println("ok")
+ val testFuture = Future {
+ Console.withOut(out) {
+ test.run
+ }
+ out.close
}
- else {
- val results = result.results.length
- val failed = result.results.count { t =>
- !t.passed && !t.directive.isDefined
+
+ val callbackGenerator: () => TAPEvent => Unit = () => {
+ var prevWidth = 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)
+ Console.out.flush
}
- println("Dubious, test returned " + result.exitCode)
- println("Failed " + failed + "/" + results + " subtests")
+ (e: TAPEvent) => e match {
+ case StartEvent => {
+ print(name + " " + ("." * (maxLength - name.length)) + ".. ")
+ Console.out.flush
+ }
+ case PlanEvent(p) => {
+ plan = Some(p.plan)
+ printStatus
+ }
+ case ResultEvent(r) => {
+ tests += 1
+ if (!r.passed) {
+ failed = true
+ }
+ printStatus
+ }
+ case EndEvent(result) => {
+ print(("\b" * prevWidth) + (" " * prevWidth) + ("\b" * prevWidth))
+ if (result.success) {
+ println("ok")
+ }
+ else {
+ val results = result.results.length
+ val failed = result.results.count { t =>
+ !t.passed && !t.directive.isDefined
+ }
+
+ println("Dubious, test returned " + result.exitCode)
+ println("Failed " + failed + "/" + results + " subtests")
+ }
+ }
+ case _ => ()
+ }
}
+ val parser = new Parser(callbackGenerator())
+ val result = parser.parse(in)
+ in.close
+ Await.ready(testFuture, Duration.Inf)
+
name -> result
}.toMap
}