Skip to content
Browse files

Implement "Bail out!" parsing

  • Loading branch information...
1 parent 616aec8 commit 0d642b9666c6b7b7252261b2dd34b60b62445770 @leto committed Jan 21, 2010
Showing with 34 additions and 2 deletions.
  1. +2 −1 TODO
  2. +11 −0 lib/Tapir/Parser.pir
  3. +21 −1 t/02-parse_tapstream.t
View
3 TODO
@@ -21,8 +21,9 @@ Please let me know if you start hacking on one of these or if you have any amazi
* Running tests in parallel
How to do it? There should be examples in the Parrot test suite
-* Parse bailout correctly
+* Parse bailout correctly - This is implemented, but should be tested more
+ http://search.cpan.org/~petdance/TAP-1.00/TAP.pm
http://cpansearch.perl.org/src/ANDYA/Test-Harness-3.17/lib/TAP/Parser/Grammar.pm
* Be able to run tests written in different languages in the same test run
View
11 lib/Tapir/Parser.pir
@@ -8,6 +8,15 @@ Written and maintained by Jonathan "Duke" Leto C<< jonathan@leto.net >>.
.namespace [ 'Tapir'; 'Parser' ]
+.sub bail_if_necessary :method
+ .param string line
+ $S0 = substr line, 0, 9
+ if $S0 == 'Bail out!' goto bail_out
+ .return(0)
+ bail_out:
+ .return(1)
+.end
+
.sub parse_tapstream :method
.param string tap
.param int exit_code :optional
@@ -37,6 +46,8 @@ Written and maintained by Jonathan "Duke" Leto C<< jonathan@leto.net >>.
loop:
if i >= $I0 goto done
curr_line = tap_lines[i]
+ $I1 = self.'bail_if_necessary'(curr_line)
+ if $I1 goto done
split parts, "ok ", curr_line
View
22 t/02-parse_tapstream.t
@@ -7,7 +7,7 @@
load_bytecode 'lib/Tapir/Parser.pbc'
load_bytecode 'lib/Tapir/Stream.pbc'
- plan(59)
+ plan(61)
# setup test data
klass = newclass [ 'Tapir'; 'Parser' ]
@@ -24,6 +24,26 @@
test_parse_tapstream_not_enough_tests(tapir)
test_parse_tapstream_todo(tapir)
test_parse_tapstream_skip(tapir)
+ test_parse_tapstream_bail(tapir)
+.end
+
+
+.sub test_parse_tapstream_bail
+ .param pmc tapir
+ .local pmc stream
+ .local string tap
+ tap = <<"TAP"
+1..2
+ok 1 - Testing some stuff
+Bail out! Ruh roh
+ok 2 - This test is never run
+TAP
+ stream = tapir.'parse_tapstream'(tap)
+ $I0 = stream.'get_pass'()
+ is($I0,1,'parse_tapstream bails out properly')
+
+ $I0 = stream.'get_fail'()
+ is($I0,0,'parse_tapstream gets the right number of fails when bailing')
.end
.sub test_parse_tapstream_skip

0 comments on commit 0d642b9

Please sign in to comment.
Something went wrong with that request. Please try again.