From 7efb2caf7d8832a7d3a9d2ac55862e43267a3eb2 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 6 Mar 2013 15:32:26 -0600 Subject: move the directory structure too --- .../com/iinteractive/test/ExtensionTest.scala | 57 +++++ .../com/iinteractive/test/ExternalTestTest.scala | 3 + .../scala/com/iinteractive/test/PlanTest.scala | 29 +++ .../scala/com/iinteractive/test/TestMoreTest.scala | 147 +++++++++++++ .../com/iinteractive/test/tap/ParserTest.scala | 127 +++++++++++ .../iinteractive/test/tap/TestBuilderTest.scala | 241 +++++++++++++++++++++ src/test/scala/org/perl8/test/ExtensionTest.scala | 57 ----- .../scala/org/perl8/test/ExternalTestTest.scala | 3 - src/test/scala/org/perl8/test/PlanTest.scala | 29 --- src/test/scala/org/perl8/test/TestMoreTest.scala | 147 ------------- src/test/scala/org/perl8/test/tap/ParserTest.scala | 127 ----------- .../scala/org/perl8/test/tap/TestBuilderTest.scala | 241 --------------------- 12 files changed, 604 insertions(+), 604 deletions(-) create mode 100644 src/test/scala/com/iinteractive/test/ExtensionTest.scala create mode 100644 src/test/scala/com/iinteractive/test/ExternalTestTest.scala create mode 100644 src/test/scala/com/iinteractive/test/PlanTest.scala create mode 100644 src/test/scala/com/iinteractive/test/TestMoreTest.scala create mode 100644 src/test/scala/com/iinteractive/test/tap/ParserTest.scala create mode 100644 src/test/scala/com/iinteractive/test/tap/TestBuilderTest.scala delete mode 100644 src/test/scala/org/perl8/test/ExtensionTest.scala delete mode 100644 src/test/scala/org/perl8/test/ExternalTestTest.scala delete mode 100644 src/test/scala/org/perl8/test/PlanTest.scala delete mode 100644 src/test/scala/org/perl8/test/TestMoreTest.scala delete mode 100644 src/test/scala/org/perl8/test/tap/ParserTest.scala delete mode 100644 src/test/scala/org/perl8/test/tap/TestBuilderTest.scala (limited to 'src/test') diff --git a/src/test/scala/com/iinteractive/test/ExtensionTest.scala b/src/test/scala/com/iinteractive/test/ExtensionTest.scala new file mode 100644 index 0000000..5c49f21 --- /dev/null +++ b/src/test/scala/com/iinteractive/test/ExtensionTest.scala @@ -0,0 +1,57 @@ +package com.iinteractive.test + +import java.io.ByteArrayOutputStream + +import com.iinteractive.test.tap.Parser + +trait NumberZero { this: TestMore => + def is_zero (i: Int, desc: String): Boolean = hideTestMethod { + is(i, 0, desc) + } +} + +trait NumberZeroWrapped extends NumberZero { this: TestMore => + def isZero (i: Int): Boolean = hideTestMethod { + is_zero(i, "the number is zero") + } +} + +class ExtensionTest extends TestMore { + val lineZero = Thread.currentThread.getStackTrace()(1).getLineNumber + 3 + def line (offset: Int) = lineZero + offset + + private class ExtensionTestTest extends TestMore with NumberZeroWrapped { + is_zero(0, "it's zero") + is_zero(1, "it's not zero") + isZero(0) + isZero(1) + } + + val out = new ByteArrayOutputStream + val exitCode = Console.withOut(out) { + Console.withErr(out) { + (new ExtensionTestTest).run + } + } + + is((new Parser).parse(out).exitCode, 2) + is(exitCode, 2) + + val tap = + "ok 1 - it's zero\n" + + "not ok 2 - it's not zero\n" + + "# Failed test 'it's not zero'\n" + + "# at ExtensionTest.scala line " + line(2) + ".\n" + + "# got: '1'\n" + + "# expected: '0'\n" + + "ok 3 - the number is zero\n" + + "not ok 4 - the number is zero\n" + + "# Failed test 'the number is zero'\n" + + "# at ExtensionTest.scala line " + line(4) + ".\n" + + "# got: '1'\n" + + "# expected: '0'\n" + + "1..4\n" + + "# Looks like you failed 2 tests of 4.\n" + + is(out.toString, tap) +} diff --git a/src/test/scala/com/iinteractive/test/ExternalTestTest.scala b/src/test/scala/com/iinteractive/test/ExternalTestTest.scala new file mode 100644 index 0000000..e830abe --- /dev/null +++ b/src/test/scala/com/iinteractive/test/ExternalTestTest.scala @@ -0,0 +1,3 @@ +package com.iinteractive.test + +class ExternalTestTest extends ExternalTest("perl", "perl/test.t") diff --git a/src/test/scala/com/iinteractive/test/PlanTest.scala b/src/test/scala/com/iinteractive/test/PlanTest.scala new file mode 100644 index 0000000..6d1690b --- /dev/null +++ b/src/test/scala/com/iinteractive/test/PlanTest.scala @@ -0,0 +1,29 @@ +package com.iinteractive.test + +import java.io.ByteArrayOutputStream + +import com.iinteractive.test.tap.Parser + +class PlanTest extends TestMore { + private class PlanTestTest extends TestMore(2) { + is(1, 1) + is(2, 2) + } + + val out = new ByteArrayOutputStream + val exitCode = Console.withOut(out) { + Console.withErr(out) { + (new PlanTestTest).run + } + } + + is((new Parser).parse(out).exitCode, 0) + is(exitCode, 0) + + val tap = + "1..2\n" + + "ok 1\n" + + "ok 2\n" + + is(out.toString, tap) +} diff --git a/src/test/scala/com/iinteractive/test/TestMoreTest.scala b/src/test/scala/com/iinteractive/test/TestMoreTest.scala new file mode 100644 index 0000000..ead9823 --- /dev/null +++ b/src/test/scala/com/iinteractive/test/TestMoreTest.scala @@ -0,0 +1,147 @@ +package com.iinteractive.test + +import java.io.ByteArrayOutputStream + +import com.iinteractive.test.tap.Parser + +class TestMoreTest extends TestMore { + val lineZero = Thread.currentThread.getStackTrace()(1).getLineNumber + 3 + def line (offset: Int) = lineZero + offset + + private class MyBasicTest extends TestMore { + 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 + } + } + + val out = new ByteArrayOutputStream + val exitCode = Console.withOut(out) { + Console.withErr(out) { + (new MyBasicTest).run + } + } + + is((new Parser).parse(out).exitCode, 9, "got the right plan") + is(exitCode, 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 " + line(3) + ".\n" + + "ok 3\n" + + "not ok 4\n" + + "# Failed test at TestMoreTest.scala line " + line(5) + ".\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 " + line(9) + ".\n" + + "# got: '1'\n" + + "# expected: '0'\n" + + "ok 7\n" + + "not ok 8\n" + + "# Failed test at TestMoreTest.scala line " + line(11) + ".\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 " + line(15) + ".\n" + + "# got: '1'\n" + + "# expected: anything else\n" + + "ok 11\n" + + "not ok 12\n" + + "# Failed test at TestMoreTest.scala line " + line(17) + ".\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 " + line(21) + ".\n" + + "# 'foo'\n" + + "# doesn't match 'bar'\n" + + "ok 15\n" + + "not ok 16\n" + + "# Failed test at TestMoreTest.scala line " + line(23) + ".\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 " + line(28) + ".\n" + + " # 'foo'\n" + + " # matches 'foo'\n" + + " ok 3\n" + + " not ok 4\n" + + " # Failed test at TestMoreTest.scala line " + line(30) + ".\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 " + line(25) + ".\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 " + line(44) + ".\n" + + "not ok 23 # TODO not working yet\n" + + "# Failed (TODO) test at TestMoreTest.scala line " + line(45) + ".\n" + + "1..23\n" + + "# Looks like you failed 9 tests of 23.\n" + + is(out.toString, expected, "correct tap") +} diff --git a/src/test/scala/com/iinteractive/test/tap/ParserTest.scala b/src/test/scala/com/iinteractive/test/tap/ParserTest.scala new file mode 100644 index 0000000..bb871ee --- /dev/null +++ b/src/test/scala/com/iinteractive/test/tap/ParserTest.scala @@ -0,0 +1,127 @@ +package com.iinteractive.test.tap + +import com.iinteractive.test.{TestMore,SkipAll,NumericPlan} + +class ParserTest extends TestMore { + subtest ("basic") { + val tap = + "1..1\n" + + "ok 1\n" + + val result = (new Parser).parse(tap) + is(result.plan, NumericPlan(1), "got the right plan") + is(result.results.map(_.passed), Seq(true), "got the right results") + } + + subtest ("skip all") { + val tap = + "1..0 # SKIP nope\n" + + val result = (new Parser).parse(tap) + is(result.plan, SkipAll("nope"), "got the right plan") + is(result.results, Nil, "got the right results") + } + + subtest ("more complicated") { + val tap = + "# starting...\n" + + "ok 1 - stuff\n" + + "not ok 2 - does this work?\n" + + "not ok 3 - eventually # TODO doesn't work yet\n" + + "# skipping some stuff\n" + + "ok 4 # skip don't do this yet\n" + + "# finished!\n" + + "1..4\n" + + "# Looks like you failed 1 test of 4.\n" + + val result = (new Parser).parse(tap) + 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", + "" + ) + ) + + is( + result.results.map(_.directive), + Seq( + None, + None, + Some(TodoDirective(Some("doesn't work yet"))), + Some(SkipDirective(Some("don't do this yet"))) + ) + ) + } + + subtest ("subtests") { + val tap = + "ok 1 - not subtest\n" + + " ok 1 - passed\n" + + " not ok 2 - failed\n" + + " ok 3 - passed again\n" + + " 1..1\n" + + " ok 1 - sub-sub-test\n" + + " ok 4 - nested subtests\n" + + " 1..4\n" + + " # Looks like you failed 1 test of 4.\n" + + "not ok 2 - subtest\n" + + "1..2\n" + + "# Looks like you failed 1 test of 2.\n" + + val result = (new Parser).parse(tap) + 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" + ) + ) + is(result.results.map(_.directive), Seq(None, None)) + + is(result.results(0).subtest, None) + ok(result.results(1).subtest.isDefined) + + val subtest = result.results(1).subtest.get + 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" + ) + ) + is(subtest.results.map(_.directive), Seq(None, None, None, None)) + + 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 + 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" + ) + ) + is(subsubtest.results.map(_.directive), Seq(None)) + + is(subsubtest.results(0).subtest, None) + } +} diff --git a/src/test/scala/com/iinteractive/test/tap/TestBuilderTest.scala b/src/test/scala/com/iinteractive/test/tap/TestBuilderTest.scala new file mode 100644 index 0000000..bc873c8 --- /dev/null +++ b/src/test/scala/com/iinteractive/test/tap/TestBuilderTest.scala @@ -0,0 +1,241 @@ +package com.iinteractive.test.tap + +import java.io.ByteArrayOutputStream + +import com.iinteractive.test.{TestMore,SkipAll,BailOutException} + +class TestBuilderTest extends TestMore { + subtest ("ok") { + val output = new ByteArrayOutputStream + Console.withOut(output) { + 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 = + "1..4\n" + + "ok 1 test succeeded\n" + + "not ok 2 test failed\n" + + "ok 3\n" + + "not ok 4\n" + + "# Looks like you failed 2 tests of 4.\n" + + is(output.toString, expected) + } + + subtest ("no plan") { + val output = new ByteArrayOutputStream + Console.withOut(output) { + 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 = + "ok 1 test succeeded\n" + + "not ok 2 test failed\n" + + "ok 3\n" + + "not ok 4\n" + + "1..4\n" + + "# Looks like you failed 2 tests of 4.\n" + + is(output.toString, expected) + } + + subtest ("empty") { + val output = new ByteArrayOutputStream + Console.withOut(output) { + Console.withErr(output) { + val builder = new TestBuilder + builder.doneTesting + } + } + + val expected = + "1..0\n" + + "# No tests run!\n" + + is(output.toString, expected) + } + + subtest ("diag") { + val output = new ByteArrayOutputStream + Console.withOut(output) { + 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 = + "ok 1 the test passes\n" + + "not ok 2 the test passes\n" + + "# got false, expected true\n" + + "ok 3\n" + + "# ending\n" + + "# now\n" + + "1..3\n" + + "# Looks like you failed 1 test of 3.\n" + + is(output.toString, expected) + } + + subtest ("is passing") { + val output = new ByteArrayOutputStream + val oldOut = Console.out + val oldErr = Console.err + + is( + Console.withOut(output) { + Console.withErr(output) { + val builder = new TestBuilder + builder.doneTesting + } + }, + false + ) + + is( + Console.withOut(output) { + Console.withErr(output) { + val builder = new TestBuilder + builder.ok(true) + builder.doneTesting + } + }, + true + ) + + is( + Console.withOut(output) { + Console.withErr(output) { + val builder = new TestBuilder + builder.ok(true) + builder.ok(false) + builder.doneTesting + } + }, + false + ) + + is( + Console.withOut(output) { + Console.withErr(output) { + val builder = new TestBuilder + builder.ok(true) + builder.ok(false) + builder.ok(true) + builder.doneTesting + } + }, + false + ) + } + + subtest ("bail out") { + val output = new ByteArrayOutputStream + val oldOut = Console.out + val oldErr = Console.err + Console.withOut(output) { + 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, "Bail out! oh no!") + } + } + case _: Throwable => Console.withOut(oldOut) { + Console.withErr(oldErr) { + fail + } + } + } + } + } + + val expected = + "ok 1\n" + + "Bail out! oh no!\n" + + is(output.toString, expected) + } + + subtest ("skip all") { + val output = new ByteArrayOutputStream + Console.withOut(output) { + Console.withErr(output) { + val builder = new TestBuilder(SkipAll("foo bar")) + } + } + + val expected = + "1..0 # SKIP foo bar\n" + + is(output.toString, expected) + } + + subtest ("skip") { + val output = new ByteArrayOutputStream + Console.withOut(output) { + Console.withErr(output) { + val builder = new TestBuilder + builder.ok(false) + builder.skip("not now") + builder.doneTesting + } + } + + val expected = + "not ok 1\n" + + "ok 2 # skip not now\n" + + "1..2\n" + + "# Looks like you failed 1 test of 2.\n" + + is(output.toString, expected) + } + + subtest ("todo") { + val output = new ByteArrayOutputStream + Console.withOut(output) { + Console.withErr(output) { + val builder = new TestBuilder + builder.todo("not working yet", false, "do a thing") + builder.todo("is it?", true) + builder.doneTesting + } + } + + val expected = + "not ok 1 do a thing # TODO not working yet\n" + + "ok 2 # TODO is it?\n" + + "1..2\n" + + is(output.toString, expected) + } +} diff --git a/src/test/scala/org/perl8/test/ExtensionTest.scala b/src/test/scala/org/perl8/test/ExtensionTest.scala deleted file mode 100644 index 5c49f21..0000000 --- a/src/test/scala/org/perl8/test/ExtensionTest.scala +++ /dev/null @@ -1,57 +0,0 @@ -package com.iinteractive.test - -import java.io.ByteArrayOutputStream - -import com.iinteractive.test.tap.Parser - -trait NumberZero { this: TestMore => - def is_zero (i: Int, desc: String): Boolean = hideTestMethod { - is(i, 0, desc) - } -} - -trait NumberZeroWrapped extends NumberZero { this: TestMore => - def isZero (i: Int): Boolean = hideTestMethod { - is_zero(i, "the number is zero") - } -} - -class ExtensionTest extends TestMore { - val lineZero = Thread.currentThread.getStackTrace()(1).getLineNumber + 3 - def line (offset: Int) = lineZero + offset - - private class ExtensionTestTest extends TestMore with NumberZeroWrapped { - is_zero(0, "it's zero") - is_zero(1, "it's not zero") - isZero(0) - isZero(1) - } - - val out = new ByteArrayOutputStream - val exitCode = Console.withOut(out) { - Console.withErr(out) { - (new ExtensionTestTest).run - } - } - - is((new Parser).parse(out).exitCode, 2) - is(exitCode, 2) - - val tap = - "ok 1 - it's zero\n" + - "not ok 2 - it's not zero\n" + - "# Failed test 'it's not zero'\n" + - "# at ExtensionTest.scala line " + line(2) + ".\n" + - "# got: '1'\n" + - "# expected: '0'\n" + - "ok 3 - the number is zero\n" + - "not ok 4 - the number is zero\n" + - "# Failed test 'the number is zero'\n" + - "# at ExtensionTest.scala line " + line(4) + ".\n" + - "# got: '1'\n" + - "# expected: '0'\n" + - "1..4\n" + - "# Looks like you failed 2 tests of 4.\n" - - is(out.toString, tap) -} diff --git a/src/test/scala/org/perl8/test/ExternalTestTest.scala b/src/test/scala/org/perl8/test/ExternalTestTest.scala deleted file mode 100644 index e830abe..0000000 --- a/src/test/scala/org/perl8/test/ExternalTestTest.scala +++ /dev/null @@ -1,3 +0,0 @@ -package com.iinteractive.test - -class ExternalTestTest extends ExternalTest("perl", "perl/test.t") diff --git a/src/test/scala/org/perl8/test/PlanTest.scala b/src/test/scala/org/perl8/test/PlanTest.scala deleted file mode 100644 index 6d1690b..0000000 --- a/src/test/scala/org/perl8/test/PlanTest.scala +++ /dev/null @@ -1,29 +0,0 @@ -package com.iinteractive.test - -import java.io.ByteArrayOutputStream - -import com.iinteractive.test.tap.Parser - -class PlanTest extends TestMore { - private class PlanTestTest extends TestMore(2) { - is(1, 1) - is(2, 2) - } - - val out = new ByteArrayOutputStream - val exitCode = Console.withOut(out) { - Console.withErr(out) { - (new PlanTestTest).run - } - } - - is((new Parser).parse(out).exitCode, 0) - is(exitCode, 0) - - val tap = - "1..2\n" + - "ok 1\n" + - "ok 2\n" - - is(out.toString, tap) -} diff --git a/src/test/scala/org/perl8/test/TestMoreTest.scala b/src/test/scala/org/perl8/test/TestMoreTest.scala deleted file mode 100644 index ead9823..0000000 --- a/src/test/scala/org/perl8/test/TestMoreTest.scala +++ /dev/null @@ -1,147 +0,0 @@ -package com.iinteractive.test - -import java.io.ByteArrayOutputStream - -import com.iinteractive.test.tap.Parser - -class TestMoreTest extends TestMore { - val lineZero = Thread.currentThread.getStackTrace()(1).getLineNumber + 3 - def line (offset: Int) = lineZero + offset - - private class MyBasicTest extends TestMore { - 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 - } - } - - val out = new ByteArrayOutputStream - val exitCode = Console.withOut(out) { - Console.withErr(out) { - (new MyBasicTest).run - } - } - - is((new Parser).parse(out).exitCode, 9, "got the right plan") - is(exitCode, 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 " + line(3) + ".\n" + - "ok 3\n" + - "not ok 4\n" + - "# Failed test at TestMoreTest.scala line " + line(5) + ".\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 " + line(9) + ".\n" + - "# got: '1'\n" + - "# expected: '0'\n" + - "ok 7\n" + - "not ok 8\n" + - "# Failed test at TestMoreTest.scala line " + line(11) + ".\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 " + line(15) + ".\n" + - "# got: '1'\n" + - "# expected: anything else\n" + - "ok 11\n" + - "not ok 12\n" + - "# Failed test at TestMoreTest.scala line " + line(17) + ".\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 " + line(21) + ".\n" + - "# 'foo'\n" + - "# doesn't match 'bar'\n" + - "ok 15\n" + - "not ok 16\n" + - "# Failed test at TestMoreTest.scala line " + line(23) + ".\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 " + line(28) + ".\n" + - " # 'foo'\n" + - " # matches 'foo'\n" + - " ok 3\n" + - " not ok 4\n" + - " # Failed test at TestMoreTest.scala line " + line(30) + ".\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 " + line(25) + ".\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 " + line(44) + ".\n" + - "not ok 23 # TODO not working yet\n" + - "# Failed (TODO) test at TestMoreTest.scala line " + line(45) + ".\n" + - "1..23\n" + - "# Looks like you failed 9 tests of 23.\n" - - is(out.toString, expected, "correct tap") -} diff --git a/src/test/scala/org/perl8/test/tap/ParserTest.scala b/src/test/scala/org/perl8/test/tap/ParserTest.scala deleted file mode 100644 index bb871ee..0000000 --- a/src/test/scala/org/perl8/test/tap/ParserTest.scala +++ /dev/null @@ -1,127 +0,0 @@ -package com.iinteractive.test.tap - -import com.iinteractive.test.{TestMore,SkipAll,NumericPlan} - -class ParserTest extends TestMore { - subtest ("basic") { - val tap = - "1..1\n" + - "ok 1\n" - - val result = (new Parser).parse(tap) - is(result.plan, NumericPlan(1), "got the right plan") - is(result.results.map(_.passed), Seq(true), "got the right results") - } - - subtest ("skip all") { - val tap = - "1..0 # SKIP nope\n" - - val result = (new Parser).parse(tap) - is(result.plan, SkipAll("nope"), "got the right plan") - is(result.results, Nil, "got the right results") - } - - subtest ("more complicated") { - val tap = - "# starting...\n" + - "ok 1 - stuff\n" + - "not ok 2 - does this work?\n" + - "not ok 3 - eventually # TODO doesn't work yet\n" + - "# skipping some stuff\n" + - "ok 4 # skip don't do this yet\n" + - "# finished!\n" + - "1..4\n" + - "# Looks like you failed 1 test of 4.\n" - - val result = (new Parser).parse(tap) - 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", - "" - ) - ) - - is( - result.results.map(_.directive), - Seq( - None, - None, - Some(TodoDirective(Some("doesn't work yet"))), - Some(SkipDirective(Some("don't do this yet"))) - ) - ) - } - - subtest ("subtests") { - val tap = - "ok 1 - not subtest\n" + - " ok 1 - passed\n" + - " not ok 2 - failed\n" + - " ok 3 - passed again\n" + - " 1..1\n" + - " ok 1 - sub-sub-test\n" + - " ok 4 - nested subtests\n" + - " 1..4\n" + - " # Looks like you failed 1 test of 4.\n" + - "not ok 2 - subtest\n" + - "1..2\n" + - "# Looks like you failed 1 test of 2.\n" - - val result = (new Parser).parse(tap) - 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" - ) - ) - is(result.results.map(_.directive), Seq(None, None)) - - is(result.results(0).subtest, None) - ok(result.results(1).subtest.isDefined) - - val subtest = result.results(1).subtest.get - 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" - ) - ) - is(subtest.results.map(_.directive), Seq(None, None, None, None)) - - 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 - 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" - ) - ) - is(subsubtest.results.map(_.directive), Seq(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 deleted file mode 100644 index bc873c8..0000000 --- a/src/test/scala/org/perl8/test/tap/TestBuilderTest.scala +++ /dev/null @@ -1,241 +0,0 @@ -package com.iinteractive.test.tap - -import java.io.ByteArrayOutputStream - -import com.iinteractive.test.{TestMore,SkipAll,BailOutException} - -class TestBuilderTest extends TestMore { - subtest ("ok") { - val output = new ByteArrayOutputStream - Console.withOut(output) { - 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 = - "1..4\n" + - "ok 1 test succeeded\n" + - "not ok 2 test failed\n" + - "ok 3\n" + - "not ok 4\n" + - "# Looks like you failed 2 tests of 4.\n" - - is(output.toString, expected) - } - - subtest ("no plan") { - val output = new ByteArrayOutputStream - Console.withOut(output) { - 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 = - "ok 1 test succeeded\n" + - "not ok 2 test failed\n" + - "ok 3\n" + - "not ok 4\n" + - "1..4\n" + - "# Looks like you failed 2 tests of 4.\n" - - is(output.toString, expected) - } - - subtest ("empty") { - val output = new ByteArrayOutputStream - Console.withOut(output) { - Console.withErr(output) { - val builder = new TestBuilder - builder.doneTesting - } - } - - val expected = - "1..0\n" + - "# No tests run!\n" - - is(output.toString, expected) - } - - subtest ("diag") { - val output = new ByteArrayOutputStream - Console.withOut(output) { - 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 = - "ok 1 the test passes\n" + - "not ok 2 the test passes\n" + - "# got false, expected true\n" + - "ok 3\n" + - "# ending\n" + - "# now\n" + - "1..3\n" + - "# Looks like you failed 1 test of 3.\n" - - is(output.toString, expected) - } - - subtest ("is passing") { - val output = new ByteArrayOutputStream - val oldOut = Console.out - val oldErr = Console.err - - is( - Console.withOut(output) { - Console.withErr(output) { - val builder = new TestBuilder - builder.doneTesting - } - }, - false - ) - - is( - Console.withOut(output) { - Console.withErr(output) { - val builder = new TestBuilder - builder.ok(true) - builder.doneTesting - } - }, - true - ) - - is( - Console.withOut(output) { - Console.withErr(output) { - val builder = new TestBuilder - builder.ok(true) - builder.ok(false) - builder.doneTesting - } - }, - false - ) - - is( - Console.withOut(output) { - Console.withErr(output) { - val builder = new TestBuilder - builder.ok(true) - builder.ok(false) - builder.ok(true) - builder.doneTesting - } - }, - false - ) - } - - subtest ("bail out") { - val output = new ByteArrayOutputStream - val oldOut = Console.out - val oldErr = Console.err - Console.withOut(output) { - 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, "Bail out! oh no!") - } - } - case _: Throwable => Console.withOut(oldOut) { - Console.withErr(oldErr) { - fail - } - } - } - } - } - - val expected = - "ok 1\n" + - "Bail out! oh no!\n" - - is(output.toString, expected) - } - - subtest ("skip all") { - val output = new ByteArrayOutputStream - Console.withOut(output) { - Console.withErr(output) { - val builder = new TestBuilder(SkipAll("foo bar")) - } - } - - val expected = - "1..0 # SKIP foo bar\n" - - is(output.toString, expected) - } - - subtest ("skip") { - val output = new ByteArrayOutputStream - Console.withOut(output) { - Console.withErr(output) { - val builder = new TestBuilder - builder.ok(false) - builder.skip("not now") - builder.doneTesting - } - } - - val expected = - "not ok 1\n" + - "ok 2 # skip not now\n" + - "1..2\n" + - "# Looks like you failed 1 test of 2.\n" - - is(output.toString, expected) - } - - subtest ("todo") { - val output = new ByteArrayOutputStream - Console.withOut(output) { - Console.withErr(output) { - val builder = new TestBuilder - builder.todo("not working yet", false, "do a thing") - builder.todo("is it?", true) - builder.doneTesting - } - } - - val expected = - "not ok 1 do a thing # TODO not working yet\n" + - "ok 2 # TODO is it?\n" + - "1..2\n" - - is(output.toString, expected) - } -} -- cgit v1.2.3-54-g00ecf