aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-02-23 00:55:37 -0600
committerJesse Luehrs <doy@tozt.net>2013-02-23 00:55:48 -0600
commiteb12ad14a07cecca59c7990d09055ea6ae59f414 (patch)
tree5530ecaea14217446c8f782f8dfd3fa35ded4e1d /src
parente5ba3c840b3f4654bc354f916d26fcf7ce80a638 (diff)
downloadscala-test-more-eb12ad14a07cecca59c7990d09055ea6ae59f414.tar.gz
scala-test-more-eb12ad14a07cecca59c7990d09055ea6ae59f414.zip
convert the test suite to use TestMore
still has issues (the tests run in parallel, which messes up the test output, and the outputstream parameter is required), but it's a start
Diffstat (limited to 'src')
-rw-r--r--src/test/scala/org/perl8/test/TestMoreTest.scala162
-rw-r--r--src/test/scala/org/perl8/test/TestMoreTestMore.scala138
-rw-r--r--src/test/scala/org/perl8/test/tap/ConsumerTest.scala92
-rw-r--r--src/test/scala/org/perl8/test/tap/TestBuilderTest.scala83
4 files changed, 175 insertions, 300 deletions
diff --git a/src/test/scala/org/perl8/test/TestMoreTest.scala b/src/test/scala/org/perl8/test/TestMoreTest.scala
index 005691e..5b3f8a3 100644
--- a/src/test/scala/org/perl8/test/TestMoreTest.scala
+++ b/src/test/scala/org/perl8/test/TestMoreTest.scala
@@ -1,10 +1,8 @@
package org.perl8.test
-import org.scalatest.FunSuite
+import java.io.{OutputStream,ByteArrayOutputStream}
-import java.io.ByteArrayOutputStream
-
-class TestMoreTest extends FunSuite {
+class TestMoreTest (out: OutputStream) extends TestMore(out) {
private object OutputContainer {
val output = new ByteArrayOutputStream
}
@@ -58,85 +56,83 @@ class TestMoreTest extends FunSuite {
}
}
- test ("basic") {
- assert((new MyBasicTest).run == 9)
+ is((new MyBasicTest).run, 9, "got the right plan")
- val expected =
- "# ok\n" +
- "ok 1 - it works!\n" +
- "not ok 2 - it doesn't work!\n" +
- "# Failed test 'it doesn't work!'\n" +
- "# at TestMoreTest.scala line 15.\n" +
- "ok 3\n" +
- "not ok 4\n" +
- "# Failed test at TestMoreTest.scala line 17.\n" +
- "# is\n" +
- "ok 5 - it works!\n" +
- "not ok 6 - it doesn't work!\n" +
- "# Failed test 'it doesn't work!'\n" +
- "# at TestMoreTest.scala line 21.\n" +
- "# got: '1'\n" +
- "# expected: '0'\n" +
- "ok 7\n" +
- "not ok 8\n" +
- "# Failed test at TestMoreTest.scala line 23.\n" +
- "# got: '1'\n" +
- "# expected: '0'\n" +
- "# isnt\n" +
- "ok 9 - it works!\n" +
- "not ok 10 - it doesn't work!\n" +
- "# Failed test 'it doesn't work!'\n" +
- "# at TestMoreTest.scala line 27.\n" +
- "# got: '1'\n" +
- "# expected: anything else\n" +
- "ok 11\n" +
- "not ok 12\n" +
- "# Failed test at TestMoreTest.scala line 29.\n" +
- "# got: '1'\n" +
- "# expected: anything else\n" +
- "# like\n" +
- "ok 13 - it works!\n" +
- "not ok 14 - it doesn't work!\n" +
- "# Failed test 'it doesn't work!'\n" +
- "# at TestMoreTest.scala line 33.\n" +
- "# 'foo'\n" +
- "# doesn't match 'bar'\n" +
- "ok 15\n" +
- "not ok 16\n" +
- "# Failed test at TestMoreTest.scala line 35.\n" +
- "# 'foo'\n" +
- "# doesn't match 'bar'\n" +
- " # unlike\n" +
- " ok 1 - it works!\n" +
- " not ok 2 - it doesn't work!\n" +
- " # Failed test 'it doesn't work!'\n" +
- " # at TestMoreTest.scala line 40.\n" +
- " # 'foo'\n" +
- " # matches 'foo'\n" +
- " ok 3\n" +
- " not ok 4\n" +
- " # Failed test at TestMoreTest.scala line 42.\n" +
- " # 'foo'\n" +
- " # matches 'foo'\n" +
- " 1..4\n" +
- " # Looks like you failed 2 tests of 4.\n" +
- "not ok 17 - unlikes\n" +
- "# Failed test 'unlikes'\n" +
- "# at TestMoreTest.scala line 37.\n" +
- "# pass\n" +
- "ok 18 - it works!\n" +
- "ok 19\n" +
- "ok 20 # skip don't do this yet\n" +
- "ok 21 # skip don't do this yet\n" +
- "# fail\n" +
- "not ok 22 - it doesn't work # TODO not working yet\n" +
- "# Failed (TODO) test 'it doesn't work'\n" +
- "# at TestMoreTest.scala line 56.\n" +
- "not ok 23 # TODO not working yet\n" +
- "# Failed (TODO) test at TestMoreTest.scala line 57.\n" +
- "1..23\n" +
- "# Looks like you failed 9 tests of 23.\n"
+ val expected =
+ "# ok\n" +
+ "ok 1 - it works!\n" +
+ "not ok 2 - it doesn't work!\n" +
+ "# Failed test 'it doesn't work!'\n" +
+ "# at TestMoreTest.scala line 13.\n" +
+ "ok 3\n" +
+ "not ok 4\n" +
+ "# Failed test at TestMoreTest.scala line 15.\n" +
+ "# is\n" +
+ "ok 5 - it works!\n" +
+ "not ok 6 - it doesn't work!\n" +
+ "# Failed test 'it doesn't work!'\n" +
+ "# at TestMoreTest.scala line 19.\n" +
+ "# got: '1'\n" +
+ "# expected: '0'\n" +
+ "ok 7\n" +
+ "not ok 8\n" +
+ "# Failed test at TestMoreTest.scala line 21.\n" +
+ "# got: '1'\n" +
+ "# expected: '0'\n" +
+ "# isnt\n" +
+ "ok 9 - it works!\n" +
+ "not ok 10 - it doesn't work!\n" +
+ "# Failed test 'it doesn't work!'\n" +
+ "# at TestMoreTest.scala line 25.\n" +
+ "# got: '1'\n" +
+ "# expected: anything else\n" +
+ "ok 11\n" +
+ "not ok 12\n" +
+ "# Failed test at TestMoreTest.scala line 27.\n" +
+ "# got: '1'\n" +
+ "# expected: anything else\n" +
+ "# like\n" +
+ "ok 13 - it works!\n" +
+ "not ok 14 - it doesn't work!\n" +
+ "# Failed test 'it doesn't work!'\n" +
+ "# at TestMoreTest.scala line 31.\n" +
+ "# 'foo'\n" +
+ "# doesn't match 'bar'\n" +
+ "ok 15\n" +
+ "not ok 16\n" +
+ "# Failed test at TestMoreTest.scala line 33.\n" +
+ "# 'foo'\n" +
+ "# doesn't match 'bar'\n" +
+ " # unlike\n" +
+ " ok 1 - it works!\n" +
+ " not ok 2 - it doesn't work!\n" +
+ " # Failed test 'it doesn't work!'\n" +
+ " # at TestMoreTest.scala line 38.\n" +
+ " # 'foo'\n" +
+ " # matches 'foo'\n" +
+ " ok 3\n" +
+ " not ok 4\n" +
+ " # Failed test at TestMoreTest.scala line 40.\n" +
+ " # 'foo'\n" +
+ " # matches 'foo'\n" +
+ " 1..4\n" +
+ " # Looks like you failed 2 tests of 4.\n" +
+ "not ok 17 - unlikes\n" +
+ "# Failed test 'unlikes'\n" +
+ "# at TestMoreTest.scala line 35.\n" +
+ "# pass\n" +
+ "ok 18 - it works!\n" +
+ "ok 19\n" +
+ "ok 20 # skip don't do this yet\n" +
+ "ok 21 # skip don't do this yet\n" +
+ "# fail\n" +
+ "not ok 22 - it doesn't work # TODO not working yet\n" +
+ "# Failed (TODO) test 'it doesn't work'\n" +
+ "# at TestMoreTest.scala line 54.\n" +
+ "not ok 23 # TODO not working yet\n" +
+ "# Failed (TODO) test at TestMoreTest.scala line 55.\n" +
+ "1..23\n" +
+ "# Looks like you failed 9 tests of 23.\n"
- assert(OutputContainer.output.toString === expected)
- }
+ is(OutputContainer.output.toString, expected, "correct tap")
}
diff --git a/src/test/scala/org/perl8/test/TestMoreTestMore.scala b/src/test/scala/org/perl8/test/TestMoreTestMore.scala
deleted file mode 100644
index 36d4037..0000000
--- a/src/test/scala/org/perl8/test/TestMoreTestMore.scala
+++ /dev/null
@@ -1,138 +0,0 @@
-package org.perl8.test
-
-import java.io.{OutputStream,ByteArrayOutputStream}
-
-class TestMoreTestMore (out: OutputStream) extends TestMore(out) {
- private object OutputContainer {
- val output = new ByteArrayOutputStream
- }
-
- private class MyBasicTest extends TestMore(OutputContainer.output) {
- diag("ok")
- ok(1 == 1, "it works!")
- ok(0 == 1, "it doesn't work!")
- ok(1 == 1)
- ok(0 == 1)
-
- diag("is")
- is(1, 1, "it works!")
- is(1, 0, "it doesn't work!")
- is(1, 1)
- is(1, 0)
-
- diag("isnt")
- isnt(1, 0, "it works!")
- isnt(1, 1, "it doesn't work!")
- isnt(1, 0)
- isnt(1, 1)
-
- diag("like")
- like("foo", """foo""".r, "it works!")
- like("foo", """bar""".r, "it doesn't work!")
- like("foo", """foo""".r)
- like("foo", """bar""".r)
-
- subtest("unlikes") {
- diag("unlike")
- unlike("foo", """bar""".r, "it works!")
- unlike("foo", """foo""".r, "it doesn't work!")
- unlike("foo", """bar""".r)
- unlike("foo", """foo""".r)
- }
-
- diag("pass")
- pass("it works!")
- pass()
-
- skip(2, "don't do this yet") {
- pass("skipped")
- pass()
- }
-
- todo("not working yet") {
- diag("fail")
- fail("it doesn't work")
- fail()
- }
- }
-
- is((new MyBasicTest).run, 9, "got the right plan")
-
- val expected =
- "# ok\n" +
- "ok 1 - it works!\n" +
- "not ok 2 - it doesn't work!\n" +
- "# Failed test 'it doesn't work!'\n" +
- "# at TestMoreTestMore.scala line 13.\n" +
- "ok 3\n" +
- "not ok 4\n" +
- "# Failed test at TestMoreTestMore.scala line 15.\n" +
- "# is\n" +
- "ok 5 - it works!\n" +
- "not ok 6 - it doesn't work!\n" +
- "# Failed test 'it doesn't work!'\n" +
- "# at TestMoreTestMore.scala line 19.\n" +
- "# got: '1'\n" +
- "# expected: '0'\n" +
- "ok 7\n" +
- "not ok 8\n" +
- "# Failed test at TestMoreTestMore.scala line 21.\n" +
- "# got: '1'\n" +
- "# expected: '0'\n" +
- "# isnt\n" +
- "ok 9 - it works!\n" +
- "not ok 10 - it doesn't work!\n" +
- "# Failed test 'it doesn't work!'\n" +
- "# at TestMoreTestMore.scala line 25.\n" +
- "# got: '1'\n" +
- "# expected: anything else\n" +
- "ok 11\n" +
- "not ok 12\n" +
- "# Failed test at TestMoreTestMore.scala line 27.\n" +
- "# got: '1'\n" +
- "# expected: anything else\n" +
- "# like\n" +
- "ok 13 - it works!\n" +
- "not ok 14 - it doesn't work!\n" +
- "# Failed test 'it doesn't work!'\n" +
- "# at TestMoreTestMore.scala line 31.\n" +
- "# 'foo'\n" +
- "# doesn't match 'bar'\n" +
- "ok 15\n" +
- "not ok 16\n" +
- "# Failed test at TestMoreTestMore.scala line 33.\n" +
- "# 'foo'\n" +
- "# doesn't match 'bar'\n" +
- " # unlike\n" +
- " ok 1 - it works!\n" +
- " not ok 2 - it doesn't work!\n" +
- " # Failed test 'it doesn't work!'\n" +
- " # at TestMoreTestMore.scala line 38.\n" +
- " # 'foo'\n" +
- " # matches 'foo'\n" +
- " ok 3\n" +
- " not ok 4\n" +
- " # Failed test at TestMoreTestMore.scala line 40.\n" +
- " # 'foo'\n" +
- " # matches 'foo'\n" +
- " 1..4\n" +
- " # Looks like you failed 2 tests of 4.\n" +
- "not ok 17 - unlikes\n" +
- "# Failed test 'unlikes'\n" +
- "# at TestMoreTestMore.scala line 35.\n" +
- "# pass\n" +
- "ok 18 - it works!\n" +
- "ok 19\n" +
- "ok 20 # skip don't do this yet\n" +
- "ok 21 # skip don't do this yet\n" +
- "# fail\n" +
- "not ok 22 - it doesn't work # TODO not working yet\n" +
- "# Failed (TODO) test 'it doesn't work'\n" +
- "# at TestMoreTestMore.scala line 54.\n" +
- "not ok 23 # TODO not working yet\n" +
- "# Failed (TODO) test at TestMoreTestMore.scala line 55.\n" +
- "1..23\n" +
- "# Looks like you failed 9 tests of 23.\n"
-
- is(OutputContainer.output.toString, expected, "correct tap")
-}
diff --git a/src/test/scala/org/perl8/test/tap/ConsumerTest.scala b/src/test/scala/org/perl8/test/tap/ConsumerTest.scala
index 7471a8c..8cee3df 100644
--- a/src/test/scala/org/perl8/test/tap/ConsumerTest.scala
+++ b/src/test/scala/org/perl8/test/tap/ConsumerTest.scala
@@ -1,30 +1,32 @@
package org.perl8.test.tap
-import org.scalatest.FunSuite
+import org.perl8.test.TestMore
+
+import java.io.OutputStream
import org.perl8.test.Utils._
-class ConsumerTest extends FunSuite {
- test ("basic") {
+class ConsumerTest (out: OutputStream) extends TestMore(out) {
+ subtest ("basic") {
val tap =
"1..1\n" +
"ok 1\n"
val result = Consumer.parse(tap)
- assert(result.plan === NumericPlan(1))
- assert(result.results.map(_.passed) === Seq(true))
+ is(result.plan, NumericPlan(1), "got the right plan")
+ is(result.results.map(_.passed), Seq(true), "got the right results")
}
- test ("skip all") {
+ subtest ("skip all") {
val tap =
"1..0 # SKIP nope\n"
val result = Consumer.parse(tap)
- assert(result.plan === SkipAll("nope"))
- assert(result.results === Seq())
+ is(result.plan, SkipAll("nope"), "got the right plan")
+ is(result.results, Nil, "got the right results")
}
- test ("more complicated") {
+ subtest ("more complicated") {
val tap =
"# starting...\n" +
"ok 1 - stuff\n" +
@@ -37,19 +39,22 @@ class ConsumerTest extends FunSuite {
"# Looks like you failed 1 test of 4.\n"
val result = Consumer.parse(tap)
- assert(result.plan === NumericPlan(4))
- assert(result.results.map(_.passed) === Seq(true, false, false, true))
- assert(result.results.map(_.number) === Seq(1, 2, 3, 4))
- assert(
- result.results.map(_.description) === Seq(
+ is(result.plan, NumericPlan(4))
+ is(result.results.map(_.passed), Seq(true, false, false, true))
+ is(result.results.map(_.number), Seq(1, 2, 3, 4))
+ is(
+ result.results.map(_.description),
+ Seq(
"- stuff",
"- does this work?",
"- eventually",
""
)
)
- assert(
- result.results.map(_.directive) === Seq(
+
+ is(
+ result.results.map(_.directive),
+ Seq(
None,
None,
Some(TodoDirective(Some("doesn't work yet"))),
@@ -58,7 +63,7 @@ class ConsumerTest extends FunSuite {
)
}
- test ("subtests") {
+ subtest ("subtests") {
val tap =
"ok 1 - not subtest\n" +
" ok 1 - passed\n" +
@@ -74,50 +79,53 @@ class ConsumerTest extends FunSuite {
"# Looks like you failed 1 test of 2.\n"
val result = Consumer.parse(tap)
- assert(result.plan === NumericPlan(2))
- assert(result.results.map(_.passed) === Seq(true, false))
- assert(result.results.map(_.number) === Seq(1, 2))
- assert(
- result.results.map(_.description) === Seq(
+ is(result.plan, NumericPlan(2))
+ is(result.results.map(_.passed), Seq(true, false))
+ is(result.results.map(_.number), Seq(1, 2))
+ is(
+ result.results.map(_.description),
+ Seq(
"- not subtest",
"- subtest"
)
)
- assert(result.results.map(_.directive) === Seq(None, None))
+ is(result.results.map(_.directive), Seq(None, None))
- assert(result.results(0).subtest === None)
- assert(result.results(1).subtest.isDefined)
+ is(result.results(0).subtest, None)
+ ok(result.results(1).subtest.isDefined)
val subtest = result.results(1).subtest.get
- assert(subtest.plan === NumericPlan(4))
- assert(subtest.results.map(_.passed) === Seq(true, false, true, true))
- assert(subtest.results.map(_.number) === Seq(1, 2, 3, 4))
- assert(
- subtest.results.map(_.description) === Seq(
+ is(subtest.plan, NumericPlan(4))
+ is(subtest.results.map(_.passed), Seq(true, false, true, true))
+ is(subtest.results.map(_.number), Seq(1, 2, 3, 4))
+ is(
+ subtest.results.map(_.description),
+ Seq(
"- passed",
"- failed",
"- passed again",
"- nested subtests"
)
)
- assert(subtest.results.map(_.directive) === Seq(None, None, None, None))
+ is(subtest.results.map(_.directive), Seq(None, None, None, None))
- assert(subtest.results(0).subtest === None)
- assert(subtest.results(1).subtest === None)
- assert(subtest.results(2).subtest === None)
- assert(subtest.results(3).subtest.isDefined)
+ is(subtest.results(0).subtest, None)
+ is(subtest.results(1).subtest, None)
+ is(subtest.results(2).subtest, None)
+ ok(subtest.results(3).subtest.isDefined)
val subsubtest = subtest.results(3).subtest.get
- assert(subsubtest.plan === NumericPlan(1))
- assert(subsubtest.results.map(_.passed) === Seq(true))
- assert(subsubtest.results.map(_.number) === Seq(1))
- assert(
- subsubtest.results.map(_.description) === Seq(
+ is(subsubtest.plan, NumericPlan(1))
+ is(subsubtest.results.map(_.passed), Seq(true))
+ is(subsubtest.results.map(_.number), Seq(1))
+ is(
+ subsubtest.results.map(_.description),
+ Seq(
"- sub-sub-test"
)
)
- assert(subsubtest.results.map(_.directive) === Seq(None))
+ is(subsubtest.results.map(_.directive), Seq(None))
- assert(subsubtest.results(0).subtest === None)
+ is(subsubtest.results(0).subtest, None)
}
}
diff --git a/src/test/scala/org/perl8/test/tap/TestBuilderTest.scala b/src/test/scala/org/perl8/test/tap/TestBuilderTest.scala
index 08341e4..c527cd2 100644
--- a/src/test/scala/org/perl8/test/tap/TestBuilderTest.scala
+++ b/src/test/scala/org/perl8/test/tap/TestBuilderTest.scala
@@ -1,20 +1,14 @@
-package org.perl8.test
+package org.perl8.test.tap
-import org.scalatest.FunSuite
-import org.scalatest.BeforeAndAfter
+import org.perl8.test.TestMore
-import org.perl8.test.tap.TestBuilder
+import java.io.{OutputStream,ByteArrayOutputStream}
-import java.io.ByteArrayOutputStream
+import org.perl8.test.Utils._
-class TestBuilderTest extends FunSuite with BeforeAndAfter {
- private val output = new ByteArrayOutputStream
-
- before {
- output.reset
- }
-
- test ("ok") {
+class TestBuilderTest (out: OutputStream) extends TestMore(out) {
+ subtest ("ok") {
+ val output = new ByteArrayOutputStream
val builder = new TestBuilder(4, output)
builder.ok(true, "test succeeded")
builder.ok(false, "test failed")
@@ -30,10 +24,11 @@ class TestBuilderTest extends FunSuite with BeforeAndAfter {
"not ok 4\n" +
"# Looks like you failed 2 tests of 4.\n"
- assert(output.toString === expected)
+ is(output.toString, expected)
}
- test ("no plan") {
+ subtest ("no plan") {
+ val output = new ByteArrayOutputStream
val builder = new TestBuilder(output)
builder.ok(true, "test succeeded")
builder.ok(false, "test failed")
@@ -49,10 +44,11 @@ class TestBuilderTest extends FunSuite with BeforeAndAfter {
"1..4\n" +
"# Looks like you failed 2 tests of 4.\n"
- assert(output.toString === expected)
+ is(output.toString, expected)
}
- test ("empty") {
+ subtest ("empty") {
+ val output = new ByteArrayOutputStream
val builder = new TestBuilder(output)
builder.doneTesting
@@ -60,10 +56,11 @@ class TestBuilderTest extends FunSuite with BeforeAndAfter {
"1..0\n" +
"# No tests run!\n"
- assert(output.toString === expected)
+ is(output.toString, expected)
}
- test ("diag") {
+ subtest ("diag") {
+ val output = new ByteArrayOutputStream
val builder = new TestBuilder(output)
builder.ok(true, "the test passes")
@@ -83,56 +80,67 @@ class TestBuilderTest extends FunSuite with BeforeAndAfter {
"1..3\n" +
"# Looks like you failed 1 test of 3.\n"
- assert(output.toString === expected)
+ is(output.toString, expected)
}
- test ("is passing") {
+ subtest ("is passing") {
+ val output = new ByteArrayOutputStream
val builder = new TestBuilder(output)
- assert(!builder.isPassing)
+ ok(!builder.isPassing)
builder.ok(true)
- assert(builder.isPassing)
+ ok(builder.isPassing)
builder.ok(false)
- assert(!builder.isPassing)
+ ok(!builder.isPassing)
builder.ok(true)
- assert(!builder.isPassing)
+ ok(!builder.isPassing)
}
- test ("bail out") {
+ subtest ("bail out") {
+ val output = new ByteArrayOutputStream
val builder = new TestBuilder(output)
builder.ok(true)
- val e = intercept[BailOutException] {
+ try {
builder.bailOut("oh no!")
+ fail()
+ }
+ catch {
+ case e: BailOutException => {
+ is(e.message, "oh no!")
+ }
+ case _: Throwable => fail()
}
- assert(e.message === "oh no!")
val expected =
"ok 1\n" +
"Bail out! oh no!\n"
- assert(output.toString === expected)
+ is(output.toString, expected)
}
- test ("skip all") {
+ subtest ("skip all") {
+ val output = new ByteArrayOutputStream
val builder = new TestBuilder(SkipAll(), output)
val expected =
"1..0 # SKIP\n"
- assert(output.toString === expected)
+ is(output.toString, expected)
}
- test ("skip all with reason") {
+ subtest ("skip all with reason") {
+ val output = new ByteArrayOutputStream
val builder = new TestBuilder(SkipAll("foo bar"), output)
val expected =
"1..0 # SKIP foo bar\n"
- assert(output.toString === expected)
+ is(output.toString, expected)
}
- test ("skip") {
+ subtest ("skip") {
+ val output = new ByteArrayOutputStream
val builder = new TestBuilder(output)
builder.ok(false)
@@ -147,10 +155,11 @@ class TestBuilderTest extends FunSuite with BeforeAndAfter {
"1..3\n" +
"# Looks like you failed 1 test of 3.\n"
- assert(output.toString === expected)
+ is(output.toString, expected)
}
- test ("todo") {
+ subtest ("todo") {
+ val output = new ByteArrayOutputStream
val builder = new TestBuilder(output)
builder.ok(false, "do a thing", todo = "not working yet")
@@ -162,6 +171,6 @@ class TestBuilderTest extends FunSuite with BeforeAndAfter {
"ok 2 # TODO is it?\n" +
"1..2\n"
- assert(output.toString === expected)
+ is(output.toString, expected)
}
}