diff options
Diffstat (limited to 'src/main/scala/org/perl8/test/tap/TAPResult.scala')
-rw-r--r-- | src/main/scala/org/perl8/test/tap/TAPResult.scala | 74 |
1 files changed, 60 insertions, 14 deletions
diff --git a/src/main/scala/org/perl8/test/tap/TAPResult.scala b/src/main/scala/org/perl8/test/tap/TAPResult.scala index 21c7986..2a23122 100644 --- a/src/main/scala/org/perl8/test/tap/TAPResult.scala +++ b/src/main/scala/org/perl8/test/tap/TAPResult.scala @@ -2,37 +2,47 @@ package org.perl8.test.tap import org.perl8.test.{Plan,NumericPlan,SkipAll} -sealed trait Directive { - val message: Option[String] -} -case class SkipDirective (message: Option[String]) extends Directive -case class TodoDirective (message: Option[String]) extends Directive - -class TestResult ( - val passed: Boolean, - val number: Int, - val description: String, - val directive: Option[Directive], - val subtest: Option[TAPResult] -) - +/** The summarized results of a TAP stream. Contains the + * [[org.perl8.test.Plan Plan]] that was given, as well as a list of + * [[org.perl8.test.tap.TestResult TestResults]] corresponding to each of the + * tests in the stream. + * + * @param plan The [[org.perl8.test.Plan Plan]] from the TAP stream + * @param results The list of [[org.perl8.test.tap.TestResult TestResults]] + * from the TAP stream + */ class TAPResult (val plan: Plan, val results: Seq[TestResult]) { + /** Returns true if the number of tests executed was compatible with the + * provided test plan. + */ val matchesPlan = plan match { case NumericPlan(n) => results.length == n case _ => results.length == 0 } + /** Returns the number of test failures in the TAP stream. */ val fails = results.count { r => !r.passed && !r.directive.isDefined } + /** Returns true if all of the tests passed. */ val testsPassed = fails == 0 + /** Returns true if the TAP stream overall passed. + * + * Differs from `testsPassed` in that it also takes into account things + * like invalid plans. + */ val success = plan match { case SkipAll(_) => true case _ => results.length > 0 && fails == 0 && matchesPlan } + /** Returns the exit code to use if running this test on its own. + * + * Success is indicated by 0, invalid TAP streams (such as incorrect plans) + * by 255, and other kinds of failures by the failure count. + */ val exitCode = if (success) { 0 @@ -44,3 +54,39 @@ class TAPResult (val plan: Plan, val results: Seq[TestResult]) { fails } } + +/** The result of a single test. + * + * @param passed True if the test passed + * @param number The test number in the TAP stream + * @param description The test description + * @param directive The [[org.perl8.test.tap.Directive Directive]] (either + * skip or todo) that was provided for this test, if any + * @param subtest The [[org.perl8.test.tap.TAPResult]] for the subtest + * that this test corresponds to, if any + */ +class TestResult ( + val passed: Boolean, + val number: Int, + val description: String, + val directive: Option[Directive], + val subtest: Option[TAPResult] +) + +/** A modifier associated with a test result. This is indicated by a `#` at + * the end of the result line, followed by the type of directive, and an + * optional message. + */ +sealed trait Directive { + val message: Option[String] +} + +/** A directive indicating that this test was skipped. */ +case class SkipDirective private[tap] ( + message: Option[String] +) extends Directive + +/** A directive indicating that this test is known to fail. */ +case class TodoDirective private[tap] ( + message: Option[String] +) extends Directive |