aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-02-20 16:09:41 -0600
committerJesse Luehrs <doy@tozt.net>2013-02-20 16:09:41 -0600
commit2dbd8afabd25635059bcd16475b9b4f3bae25d2f (patch)
tree1c328e4472be121d79f1c7bf77072229a048f243
parent4651c5e92859c89a0344e1413e141858f64e6de0 (diff)
downloadscala-test-more-2dbd8afabd25635059bcd16475b9b4f3bae25d2f.tar.gz
scala-test-more-2dbd8afabd25635059bcd16475b9b4f3bae25d2f.zip
subtests
-rw-r--r--src/main/scala/org/perl8/test/TestBuilder.scala4
-rw-r--r--src/main/scala/org/perl8/test/TestMore.scala25
-rw-r--r--src/test/scala/builder/basic.scala31
3 files changed, 25 insertions, 35 deletions
diff --git a/src/main/scala/org/perl8/test/TestBuilder.scala b/src/main/scala/org/perl8/test/TestBuilder.scala
index a291504..567d9d3 100644
--- a/src/main/scala/org/perl8/test/TestBuilder.scala
+++ b/src/main/scala/org/perl8/test/TestBuilder.scala
@@ -47,10 +47,6 @@ class TestBuilder (
message.foreach(m => println(TAP.comment(m)))
}
- def subtest (test: TestBuilder, todo: Message = NoMessage) {
- ok(test.isPassing, test.name, todo)
- }
-
def bailOut (message: Message = NoMessage) {
println(TAP.bailOut(message))
throw new BailOutException(message.getOrElse(""))
diff --git a/src/main/scala/org/perl8/test/TestMore.scala b/src/main/scala/org/perl8/test/TestMore.scala
index 9838a5b..d2c2997 100644
--- a/src/main/scala/org/perl8/test/TestMore.scala
+++ b/src/main/scala/org/perl8/test/TestMore.scala
@@ -102,6 +102,31 @@ class TestMore (
}
}
+ def subtest (name: Message, plan: Plan)(body: => Unit): Boolean =
+ subtest(name, Some(plan))(body)
+
+ def subtest (
+ name: Message,
+ plan: Option[Plan] = None
+ )(body: => Unit): Boolean = {
+ val oldBuilder = builder
+ val success = try {
+ builder = new TestBuilder(
+ plan,
+ out,
+ oldBuilder.indent + 1,
+ name.map(n => "- " + n)
+ )
+ body
+ builder.doneTesting
+ builder.isPassing
+ }
+ finally {
+ builder = oldBuilder
+ }
+ ok(success, name)
+ }
+
private def failed (desc: Message) {
val caller = Thread.currentThread.getStackTrace.drop(1).find(frame => {
frame.getFileName != "TestMore.scala"
diff --git a/src/test/scala/builder/basic.scala b/src/test/scala/builder/basic.scala
index 862d80f..0c28b06 100644
--- a/src/test/scala/builder/basic.scala
+++ b/src/test/scala/builder/basic.scala
@@ -162,35 +162,4 @@ class Basic extends FunSuite with BeforeAndAfter {
assert(output.toString === expected)
}
-
- test ("subtests") {
- val builder = new TestBuilder(output)
-
- builder.ok(true)
-
- val subtest = new TestBuilder(output, indent = 1, name = "foo")
- subtest.ok(true)
- subtest.ok(false, "do a test")
- subtest.diag("did a test")
- subtest.doneTesting
-
- builder.subtest(subtest)
-
- builder.ok(false, "something else")
- builder.doneTesting
-
- val expected =
- "ok 1\n" +
- " ok 1\n" +
- " not ok 2 do a test\n" +
- " # did a test\n" +
- " 1..2\n" +
- " # Looks like you failed 1 test of 2.\n" +
- "not ok 2 foo\n" +
- "not ok 3 something else\n" +
- "1..3\n" +
- "# Looks like you failed 2 tests of 3.\n"
-
- assert(output.toString === expected)
- }
}