aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-02-23 12:45:45 -0600
committerJesse Luehrs <doy@tozt.net>2013-02-23 12:45:45 -0600
commitad3dd7956f48da3e07caf4f649f427109ca8704a (patch)
treea24ebd6c79faa9a5a51a2210b5d5a8d3f751d74b /src
parent0cf9e98c2a04b8e5c4698278bbb2ba22fef7c1a2 (diff)
downloadscala-test-more-ad3dd7956f48da3e07caf4f649f427109ca8704a.tar.gz
scala-test-more-ad3dd7956f48da3e07caf4f649f427109ca8704a.zip
diag should print to stderr, so it's visible (note is for stdout)
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/org/perl8/test/tap/TestBuilder.scala29
-rw-r--r--src/test/scala/org/perl8/test/TestMoreTest.scala4
-rw-r--r--src/test/scala/org/perl8/test/tap/TestBuilderTest.scala148
3 files changed, 120 insertions, 61 deletions
diff --git a/src/main/scala/org/perl8/test/tap/TestBuilder.scala b/src/main/scala/org/perl8/test/tap/TestBuilder.scala
index ac576d8..203080c 100644
--- a/src/main/scala/org/perl8/test/tap/TestBuilder.scala
+++ b/src/main/scala/org/perl8/test/tap/TestBuilder.scala
@@ -7,7 +7,7 @@ class TestBuilder (
val indent: String,
private val name: Message
) {
- plan.foreach(p => println(Producer.plan(p)))
+ plan.foreach(p => outLine(Producer.plan(p)))
def this (
plan: Plan,
@@ -29,27 +29,31 @@ class TestBuilder (
) {
val line = Producer.result(test, state.currentTest, description, todo)
state.ok(test || todo.isDefined)
- println(line)
+ outLine(line)
}
def skip (reason: Message = NoMessage) {
val line = Producer.skip(state.currentTest, reason)
state.ok(true)
- println(line)
+ outLine(line)
}
def diag (message: Message) {
- message.foreach(m => println(Producer.comment(m)))
+ message.foreach(m => errLine(Producer.comment(m)))
+ }
+
+ def note (message: Message) {
+ message.foreach(m => outLine(Producer.comment(m)))
}
def bailOut (message: Message = NoMessage) {
- println(Producer.bailOut(message))
+ outLine(Producer.bailOut(message))
throw new BailOutException(message.getOrElse(""))
}
def doneTesting () {
plan match {
- case None => println(Producer.plan(state.currentTest - 1))
+ case None => outLine(Producer.plan(state.currentTest - 1))
case _ => ()
}
@@ -86,12 +90,17 @@ class TestBuilder (
private val state = new TestState
- private def println (str: String) {
- val indented =
- str.split("\n").map(s => indent + s).mkString("\n")
- Console.println(indented)
+ private def outLine (str: String) {
+ Console.out.println(withIndent(str))
}
+ private def errLine (str: String) {
+ Console.err.println(withIndent(str))
+ }
+
+ private def withIndent (str: String): String =
+ str.split("\n").map(s => indent + s).mkString("\n")
+
private class TestState {
var passCount = 0
var failCount = 0
diff --git a/src/test/scala/org/perl8/test/TestMoreTest.scala b/src/test/scala/org/perl8/test/TestMoreTest.scala
index 4272fdd..61bacad 100644
--- a/src/test/scala/org/perl8/test/TestMoreTest.scala
+++ b/src/test/scala/org/perl8/test/TestMoreTest.scala
@@ -57,7 +57,9 @@ class TestMoreTest extends TestMore {
}
val exitCode = Console.withOut(OutputContainer.output) {
- (new MyBasicTest).run
+ Console.withErr(OutputContainer.output) {
+ (new MyBasicTest).run
+ }
}
is(exitCode, 9, "got the right plan")
diff --git a/src/test/scala/org/perl8/test/tap/TestBuilderTest.scala b/src/test/scala/org/perl8/test/tap/TestBuilderTest.scala
index cf4a40d..8eab0d2 100644
--- a/src/test/scala/org/perl8/test/tap/TestBuilderTest.scala
+++ b/src/test/scala/org/perl8/test/tap/TestBuilderTest.scala
@@ -10,12 +10,14 @@ class TestBuilderTest extends TestMore {
subtest ("ok") {
val output = new ByteArrayOutputStream
Console.withOut(output) {
- val builder = new TestBuilder(4)
- builder.ok(true, "test succeeded")
- builder.ok(false, "test failed")
- builder.ok(true)
- builder.ok(false)
- builder.doneTesting
+ Console.withErr(output) {
+ val builder = new TestBuilder(4)
+ builder.ok(true, "test succeeded")
+ builder.ok(false, "test failed")
+ builder.ok(true)
+ builder.ok(false)
+ builder.doneTesting
+ }
}
val expected =
@@ -32,12 +34,14 @@ class TestBuilderTest extends TestMore {
subtest ("no plan") {
val output = new ByteArrayOutputStream
Console.withOut(output) {
- val builder = new TestBuilder
- builder.ok(true, "test succeeded")
- builder.ok(false, "test failed")
- builder.ok(true)
- builder.ok(false)
- builder.doneTesting
+ Console.withErr(output) {
+ val builder = new TestBuilder
+ builder.ok(true, "test succeeded")
+ builder.ok(false, "test failed")
+ builder.ok(true)
+ builder.ok(false)
+ builder.doneTesting
+ }
}
val expected =
@@ -54,8 +58,10 @@ class TestBuilderTest extends TestMore {
subtest ("empty") {
val output = new ByteArrayOutputStream
Console.withOut(output) {
- val builder = new TestBuilder
- builder.doneTesting
+ Console.withErr(output) {
+ val builder = new TestBuilder
+ builder.doneTesting
+ }
}
val expected =
@@ -68,13 +74,15 @@ class TestBuilderTest extends TestMore {
subtest ("diag") {
val output = new ByteArrayOutputStream
Console.withOut(output) {
- val builder = new TestBuilder
- builder.ok(true, "the test passes")
- builder.ok(false, "the test passes")
- builder.diag("got false, expected true")
- builder.ok(true)
- builder.diag("ending\nnow")
- builder.doneTesting
+ Console.withErr(output) {
+ val builder = new TestBuilder
+ builder.ok(true, "the test passes")
+ builder.ok(false, "the test passes")
+ builder.diag("got false, expected true")
+ builder.ok(true)
+ builder.diag("ending\nnow")
+ builder.doneTesting
+ }
}
val expected =
@@ -93,33 +101,65 @@ class TestBuilderTest extends TestMore {
subtest ("is passing") {
val output = new ByteArrayOutputStream
val oldOut = Console.out
+ val oldErr = Console.err
Console.withOut(output) {
- val builder = new TestBuilder
- Console.withOut(oldOut) { ok(!builder.isPassing) }
- builder.ok(true)
- Console.withOut(oldOut) { ok(builder.isPassing) }
- builder.ok(false)
- Console.withOut(oldOut) { ok(!builder.isPassing) }
- builder.ok(true)
- Console.withOut(oldOut) { ok(!builder.isPassing) }
+ Console.withErr(output) {
+ val builder = new TestBuilder
+ Console.withOut(oldOut) {
+ Console.withErr(oldErr) {
+ ok(!builder.isPassing)
+ }
+ }
+ builder.ok(true)
+ Console.withOut(oldOut) {
+ Console.withErr(oldErr) {
+ ok(builder.isPassing)
+ }
+ }
+ builder.ok(false)
+ Console.withOut(oldOut) {
+ Console.withErr(oldErr) {
+ ok(!builder.isPassing)
+ }
+ }
+ builder.ok(true)
+ Console.withOut(oldOut) {
+ Console.withErr(oldErr) {
+ ok(!builder.isPassing)
+ }
+ }
+ }
}
}
subtest ("bail out") {
val output = new ByteArrayOutputStream
val oldOut = Console.out
+ val oldErr = Console.err
Console.withOut(output) {
- val builder = new TestBuilder
- builder.ok(true)
- try {
- builder.bailOut("oh no!")
- Console.withOut(oldOut) { fail() }
- }
- catch {
- case e: BailOutException => Console.withOut(oldOut) {
- is(e.message, "oh no!")
+ Console.withErr(output) {
+ val builder = new TestBuilder
+ builder.ok(true)
+ try {
+ builder.bailOut("oh no!")
+ Console.withOut(oldOut) {
+ Console.withErr(oldErr) {
+ fail()
+ }
+ }
+ }
+ catch {
+ case e: BailOutException => Console.withOut(oldOut) {
+ Console.withErr(oldErr) {
+ is(e.message, "oh no!")
+ }
+ }
+ case _: Throwable => Console.withOut(oldOut) {
+ Console.withErr(oldErr) {
+ fail()
+ }
+ }
}
- case _: Throwable => Console.withOut(oldOut) { fail() }
}
}
@@ -133,7 +173,9 @@ class TestBuilderTest extends TestMore {
subtest ("skip all") {
val output = new ByteArrayOutputStream
Console.withOut(output) {
- val builder = new TestBuilder(SkipAll())
+ Console.withErr(output) {
+ val builder = new TestBuilder(SkipAll())
+ }
}
val expected =
@@ -145,7 +187,9 @@ class TestBuilderTest extends TestMore {
subtest ("skip all with reason") {
val output = new ByteArrayOutputStream
Console.withOut(output) {
- val builder = new TestBuilder(SkipAll("foo bar"))
+ Console.withErr(output) {
+ val builder = new TestBuilder(SkipAll("foo bar"))
+ }
}
val expected =
@@ -157,11 +201,13 @@ class TestBuilderTest extends TestMore {
subtest ("skip") {
val output = new ByteArrayOutputStream
Console.withOut(output) {
- val builder = new TestBuilder
- builder.ok(false)
- builder.skip("not now")
- builder.skip()
- builder.doneTesting
+ Console.withErr(output) {
+ val builder = new TestBuilder
+ builder.ok(false)
+ builder.skip("not now")
+ builder.skip()
+ builder.doneTesting
+ }
}
val expected =
@@ -177,10 +223,12 @@ class TestBuilderTest extends TestMore {
subtest ("todo") {
val output = new ByteArrayOutputStream
Console.withOut(output) {
- val builder = new TestBuilder
- builder.ok(false, "do a thing", todo = "not working yet")
- builder.ok(true, todo = "is it?")
- builder.doneTesting
+ Console.withErr(output) {
+ val builder = new TestBuilder
+ builder.ok(false, "do a thing", todo = "not working yet")
+ builder.ok(true, todo = "is it?")
+ builder.doneTesting
+ }
}
val expected =