diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-03-01 14:41:12 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-03-01 14:41:20 -0600 |
commit | 1d278221a709d2a26c73e76c4aeed1ba003fa6f3 (patch) | |
tree | 41c2423f52fc82fcd93ac8305dfc03ffb70f9fc8 /src/main/scala/org/perl8/test/harness | |
parent | b040805e6afae337b2602f794af9d3ddb1f003a5 (diff) | |
download | scala-test-more-1d278221a709d2a26c73e76c4aeed1ba003fa6f3.tar.gz scala-test-more-1d278221a709d2a26c73e76c4aeed1ba003fa6f3.zip |
more documentation
Diffstat (limited to 'src/main/scala/org/perl8/test/harness')
6 files changed, 54 insertions, 3 deletions
diff --git a/src/main/scala/org/perl8/test/harness/MultiTestReporter.scala b/src/main/scala/org/perl8/test/harness/MultiTestReporter.scala index b0548e4..8d50528 100644 --- a/src/main/scala/org/perl8/test/harness/MultiTestReporter.scala +++ b/src/main/scala/org/perl8/test/harness/MultiTestReporter.scala @@ -1,5 +1,16 @@ package org.perl8.test.harness +/** Classes that implement `MultiTestReporter` are capable of running a group + * of test classes, given their names. This typically involves some sort of + * summarization. + * + * See also: [[org.perl8.test.harness.MultiTestReporter]]. + */ trait MultiTestReporter { + /** Runs the test classes identifed by the list of fully qualified class + * names `testNames`. + * + * @return The exit code for the harness to use. Will be 0 on success. + */ def run (testNames: Seq[String]): Int } diff --git a/src/main/scala/org/perl8/test/harness/Reporter.scala b/src/main/scala/org/perl8/test/harness/Reporter.scala index 536636f..749cb30 100644 --- a/src/main/scala/org/perl8/test/harness/Reporter.scala +++ b/src/main/scala/org/perl8/test/harness/Reporter.scala @@ -1,5 +1,15 @@ package org.perl8.test.harness +/** Classes that implement `Reporter` are capable of running a test class, + * given its name. + * + * See also: [[org.perl8.test.harness.MultiTestReporter]]. + */ trait Reporter { + /** Runs the test class identifed by the fully qualified class name + * `testName`. + * + * @return The exit code for the harness to use. Will be 0 on success. + */ def run (testName: String): Int } diff --git a/src/main/scala/org/perl8/test/harness/SummarizedTests.scala b/src/main/scala/org/perl8/test/harness/SummarizedTests.scala index 3688011..207cc18 100644 --- a/src/main/scala/org/perl8/test/harness/SummarizedTests.scala +++ b/src/main/scala/org/perl8/test/harness/SummarizedTests.scala @@ -9,8 +9,18 @@ import scala.concurrent.Future import org.perl8.test.tap.{Parser,TAPEvent,TAPResult,TodoDirective} import org.perl8.test.Test +/** This is a trait for classes that run tests and summarize the results. It + * provides a single `runOneTest` method, which runs a test class and + * produces a stream of [[org.perl8.test.tap.TAPEvent TAP events]] which can + * be used to produce whatever summarized output you need. + */ trait SummarizedTests { - def runOneTest (test: Test, cb: TAPEvent => Unit): TAPResult = { + /** Runs a single [[org.perl8.test.Test test]] instance, calling `cb` with + * each [[org.perl8.test.tap.TAPEvent TAP event]] as it is produced. + * + * @return The overall result of the test instance. + */ + protected def runOneTest (test: Test, cb: TAPEvent => Unit): TAPResult = { val out = new PipedOutputStream val in = new PipedInputStream(out) diff --git a/src/main/scala/org/perl8/test/harness/SummaryReporter.scala b/src/main/scala/org/perl8/test/harness/SummaryReporter.scala index 083290b..1901bcf 100644 --- a/src/main/scala/org/perl8/test/harness/SummaryReporter.scala +++ b/src/main/scala/org/perl8/test/harness/SummaryReporter.scala @@ -4,6 +4,10 @@ import org.perl8.test.tap.{TAPEvent,StartEvent,ResultEvent,PlanEvent,EndEvent} import org.perl8.test.tap.{TAPResult,TodoDirective} import org.perl8.test.Test +/** Runs a series of tests. The TAP output from these tests is parsed, and + * output is produced which is similar in style to Perl's + * [[https://metacpan.org/module/Test::Harness Test::Harness]]. + */ class SummaryReporter extends MultiTestReporter with SummarizedTests { def run (testNames: Seq[String]): Int = { val results = runTests(testNames) @@ -12,7 +16,7 @@ class SummaryReporter extends MultiTestReporter with SummarizedTests { if (success) 0 else 1 } - def runTests (testNames: Seq[String]): Map[String, TAPResult] = { + protected def runTests (testNames: Seq[String]): Map[String, TAPResult] = { val maxLength = testNames.map(_.length).max testNames.map { name => @@ -70,7 +74,7 @@ class SummaryReporter extends MultiTestReporter with SummarizedTests { }.toMap } - def printTestSummary ( + protected def printTestSummary ( success: Boolean, results: Map[String, TAPResult] ) { diff --git a/src/main/scala/org/perl8/test/harness/TAPReporter.scala b/src/main/scala/org/perl8/test/harness/TAPReporter.scala index 47a88c5..58dd175 100644 --- a/src/main/scala/org/perl8/test/harness/TAPReporter.scala +++ b/src/main/scala/org/perl8/test/harness/TAPReporter.scala @@ -3,6 +3,9 @@ package org.perl8.test.harness import org.perl8.test.tap import org.perl8.test.Test +/** Runs a single test. The TAP stream from that test is written directly to + * stdout/stderr. + */ class TAPReporter extends Reporter { def run (testName: String): Int = newInstance[Test](testName).run diff --git a/src/main/scala/org/perl8/test/harness/package.scala b/src/main/scala/org/perl8/test/harness/package.scala index a5641e8..fbebf07 100644 --- a/src/main/scala/org/perl8/test/harness/package.scala +++ b/src/main/scala/org/perl8/test/harness/package.scala @@ -1,14 +1,27 @@ package org.perl8.test +/** Classes to handle running test instances and providing output. + */ package object harness { import scala.reflect.{ClassTag,classTag} + /** Loads `className`, returning the + * [[http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html java.lang.Class]] + * instance. + */ def loadClass[T: ClassTag] (className: String): Class[_] = classTag[T].runtimeClass.getClassLoader.loadClass(className) + /** Loads `className` and creates a new instance of it, using the + * no-argument constructor. + */ def newInstance[T: ClassTag] (className: String): T = loadClass[T](className).newInstance.asInstanceOf[T] + /** Loads `className` and creates a new instance of it, using a + * one-argument constructor. Passes `arg` as the argument to the + * constructor. + */ def newInstance[T: ClassTag, U <: AnyRef: ClassTag] ( className: String, arg: U |