1 # Copyright (C) 2009, Jonathan "Duke" Leto
5 Written and maintained by Jonathan "Duke" Leto C<< jonathan@leto.net >>.
9 .namespace [ 'Tapir'; 'Parser' ]
11 .sub bail_if_necessary :method
13 $S0 = substr line, 0, 9
14 if $S0 == 'Bail out!' goto bail_out
20 .sub parse_tapstream :method
22 .param int exit_code :optional
23 .local string curr_line
24 .local pmc plan, pass, fail, skip, todo
25 .local int i, curr_test, reported_test, ordered, num_lines
26 .local pmc tap_lines, parts, klass, stream
36 tap_lines = new 'ResizablePMCArray'
37 parts = new 'ResizablePMCArray'
39 split tap_lines, "\n", tap
42 .local string plan_line
43 plan_line = tap_lines[0]
44 plan = self.'parse_plan'(plan_line)
48 if i >= num_lines goto done
49 curr_line = tap_lines[i]
51 .local int need_to_bail
52 need_to_bail = self.'bail_if_necessary'(curr_line)
53 if need_to_bail goto done
56 is_tap = self.'is_tap'(curr_line)
57 unless is_tap goto unrecognized
59 split parts, "ok ", curr_line
62 reported_test = parts[1]
64 if prefix == 'not ' goto fail_or_todo
66 if reported_test == curr_test goto pass_or_skip
72 unrecognized: # doesn't look like TAP, just ignore
77 split parts, "# ", curr_line
79 $S0 = substr $S0, 0, 4
81 if $S0 != "skip" goto passz
88 split parts, "# ", curr_line
90 $S0 = substr $S0, 0, 4
92 if $S0 != "todo" goto failz
110 stream = new [ 'Tapir'; 'Stream' ]
111 stream.'set_ordered'(ordered)
112 stream.'set_pass'(pass)
113 stream.'set_fail'(fail)
114 stream.'set_todo'(todo)
115 stream.'set_skip'(skip)
116 stream.'set_plan'(plan)
117 stream.'set_exit_code'(exit_code)
122 .param string tapline
123 $S0 = substr tapline, 0, 3
124 if $S0 == "ok " goto yes
126 $S0 = substr tapline, 0, 7
127 if $S0 == "not ok " goto yes
135 # parse_plan returns the expected number of tests given a plan line as a string
137 .sub parse_plan :method
138 .param string plan_line
139 .local pmc plan_parts
141 .local num num_expected_tests
143 $I0 = length plan_line
144 if $I0 < 4 goto plan_error
146 # this needs to take into account TAP Versions
147 $S0 = substr plan_line, 0, 3
148 unless $S0 == "1.." goto plan_error
150 plan_parts = new 'FixedPMCArray'
153 split plan_parts, "..", plan_line
154 num_expected_tests = plan_parts[1]
156 $I1 = num_expected_tests
157 unless $I1 == num_expected_tests goto plan_error
158 .return (num_expected_tests)
160 # this indicates an invalid plan
169 # vim: expandtab shiftwidth=4 ft=pir: