aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/scala/org/perl8/test/Test.scala
blob: 2161de3f4a208c777b38fcfc42f9cada9fb136b2 (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
32
33
34
package com.iinteractive.test

/** Base trait for test classes in this framework. Any tests that should be
  * autodiscovered by `sbt test` should extend this trait, and implement
  * [[runTests]].
  */
trait Test {
  /** Runs the test. The TAP stream will be written to Console.out and
    * Console.err, so you can swap these out as required in order to parse it.
    *
    * @return The exit code that the test produced. Success is indicated by 0,
    *         failure to run the correct number of tests by 255, and any other
    *         failure by the number of tests that failed. This should be used
    *         by reporters which run a single test, which can call
    *         `sys.exit(exitCode)`
    */
  def run: Int =
    runTests(false)

  /** Runs the test just like [[run]], but in a way that makes sense when test
   *  results are being summarized rather than directly displayed.
   *
   *  Summarizing test reporters tend to repeatedly update the same line on
   *  the terminal, so this method makes calls to
   *  [[com.iinteractive.test.tap.TestBuilder#diag diag]] (which sends
   *  messages to stderr, where they are typically displayed as-is) prefix the
   *  message with a newline, to ensure that the output starts on its own
   *  line.
   */
  def runInHarness: Int =
    runTests(true)

  protected def runTests (terminalInUse: Boolean): Int
}