From 6791a833a94a28a6b4f7179dd8a08f565cd6c4eb Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 18 Mar 2013 16:16:16 -0500 Subject: 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 --- .../scala/com/iinteractive/test/tap/Parser.scala | 31 +++++++++++++--------- .../scala/com/iinteractive/test/SubtestsTest.scala | 14 ++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 src/test/scala/com/iinteractive/test/SubtestsTest.scala 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 + } + } +} -- cgit v1.2.3