aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/scala/org/perl8/test/harness/SummarizedTests.scala
blob: 36880116aa704f685e43634b436f04e64c0460b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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.{Parser,TAPEvent,TAPResult,TodoDirective}
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
  }
}