aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/scala/org/perl8/test/package.scala
blob: 98cba60a728977d17ebf74a43e83989fed1ae7e6 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.iinteractive

package object test {
  import language.implicitConversions

  /** Converts an
    * [[http://www.scala-lang.org/api/current/index.html#scala.Int Int]] to a
    * [[NumericPlan]].
    */
  implicit def intToPlan (p: Int): Plan =
    NumericPlan(p)

  /** A test plan. This represents the TAP statement telling how many tests
    * will be run.
    */
  sealed trait Plan {
    /** How many tests will be run. */
    val plan:    Int
    /** Whether this test was skipped. It should contain `Some(message)` if
      * the test is skipped, and `None` otherwise.
      */
    val skipAll: Option[String]
  }

  /** An explicit plan number. Corresponds to `1..5` in TAP. */
  case class NumericPlan (plan: Int) extends Plan {
    /** @inheritdoc
      *
      * Always `None` for this class.
      */
    val skipAll = None
  }

  /** A test which did not declare a plan yet. */
  case object NoPlan extends Plan {
    /** @inheritdoc
      *
      * Always 0 for this class.
      */
    val plan    = 0
    /** @inheritdoc
      *
      * Always `None` for this class.
      */
    val skipAll = None
  }

  /** A test which has declared that the entire test has been skipped.
    * Corresponds to `1..0 # SKIP [message]` in TAP.
    */
  case class SkipAll (message: String) extends Plan {
    /** @inheritdoc
      *
      * Always 0 for this class.
      */
    val plan    = 0
    /** @inheritdoc
      *
      * Never `None` for this class.
      */
    val skipAll = Some(message)
  }

  /** Exception thrown when a test bails out. Corresponds to
    * `Bail out!  [message]` in TAP.
    */
  case class BailOutException (
    message: String
  ) extends RuntimeException(message)
}