aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-03-18 16:16:16 -0500
committerJesse Luehrs <doy@tozt.net>2013-03-18 16:19:40 -0500
commit6791a833a94a28a6b4f7179dd8a08f565cd6c4eb (patch)
tree00358b1c48f6e9b2908d01fbddfea0cc8de4426b
parent761f40d02ce336fa811265e9fe14b12f4c50cf21 (diff)
downloadscala-test-more-6791a833a94a28a6b4f7179dd8a08f565cd6c4eb.tar.gz
scala-test-more-6791a833a94a28a6b4f7179dd8a08f565cd6c4eb.zip
fix broken backtracking behavior
don't even try recursing if the indentation isn't correct for it to potentially be a subtest. this was causing exponential behavior since it would try to parse a plan as a result, fail, then try to parse it as a subtest result, and try to treat it as the start of a plan-first tap stream when that shouldn't be possible at all because the indentation should indicate that it's not a subtest
-rw-r--r--src/main/scala/com/iinteractive/test/tap/Parser.scala31
-rw-r--r--src/test/scala/com/iinteractive/test/SubtestsTest.scala14
2 files changed, 33 insertions, 12 deletions
diff --git a/src/main/scala/com/iinteractive/test/tap/Parser.scala b/src/main/scala/com/iinteractive/test/tap/Parser.scala
index c66b1a7..31a6b6f 100644
--- a/src/main/scala/com/iinteractive/test/tap/Parser.scala
+++ b/src/main/scala/com/iinteractive/test/tap/Parser.scala
@@ -111,18 +111,25 @@ class Parser private (
private def subtest: Parser[TAPResult] =
LineParser("subtest") { in =>
- // can't just return the result directly, because it's of a different
- // type (the path dependent type associated with the new Parser
- // instance we create here, rather than the path dependent type
- // associated with this)
- val subParser = new TAPParser(
- e => (),
- in.first.indent
- )
- subParser.tap(in) match {
- case subParser.Success(p, rest) => Success(p, rest)
- case subParser.Failure(m, rest) => Failure(m, rest)
- case subParser.Error(m, rest) => Error(m, rest)
+ val newIndent = in.first.indent
+
+ if (newIndent.startsWith(indent) && newIndent != indent) {
+ // can't just return the result directly, because it's of a
+ // different type (the path dependent type associated with the new
+ // Parser instance we create here, rather than the path dependent
+ // type associated with this)
+ val subParser = new TAPParser(
+ e => (),
+ newIndent
+ )
+ subParser.tap(in) match {
+ case subParser.Success(p, rest) => Success(p, rest)
+ case subParser.Failure(m, rest) => Failure(m, rest)
+ case subParser.Error(m, rest) => Error(m, rest)
+ }
+ }
+ else {
+ Failure("not a subtest", in)
}
}
diff --git a/src/test/scala/com/iinteractive/test/SubtestsTest.scala b/src/test/scala/com/iinteractive/test/SubtestsTest.scala
new file mode 100644
index 0000000..1e569b7
--- /dev/null
+++ b/src/test/scala/com/iinteractive/test/SubtestsTest.scala
@@ -0,0 +1,14 @@
+package com.iinteractive.test
+
+import java.io.ByteArrayOutputStream
+
+import com.iinteractive.test.tap.Parser
+
+// ensure subtest parsing works properly
+class SubtestsTest extends TestMore {
+ for (i <- 1 to 100) {
+ subtest ("subtest " + i) {
+ pass
+ }
+ }
+}