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
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)
49 curr_line = tap_lines[i]
50 $I1 = self.'bail_if_necessary'(curr_line)
53 $I1 = self.'is_tap'(curr_line)
54 unless $I1 goto unrecognized
56 split parts, "ok ", curr_line
59 reported_test = parts[1]
61 if prefix == 'not ' goto fail_or_todo
63 if reported_test == curr_test goto pass_or_skip
67 unrecognized: # doesn't look like TAP, just ignore
71 split parts, "# ", curr_line
73 $S0 = substr $S0, 0, 4
75 if $S0 != "skip" goto passz
82 split parts, "# ", curr_line
84 $S0 = substr $S0, 0, 4
86 if $S0 != "todo" goto failz
104 stream = new [ 'Tapir'; 'Stream' ]
105 stream.'set_pass'(pass)
106 stream.'set_fail'(fail)
107 stream.'set_todo'(todo)
108 stream.'set_skip'(skip)
109 stream.'set_plan'(plan)
110 stream.'set_exit_code'(exit_code)
115 .param string tapline
116 $S0 = substr tapline, 0, 3
117 if $S0 == "ok " goto yes
119 $S0 = substr tapline, 0, 7
120 if $S0 == "not ok " goto yes
129 # parse_plan returns the expected number of tests given a plan line as a string
131 .sub parse_plan :method
132 .param string plan_line
133 .local pmc plan_parts
135 .local num num_expected_tests
137 $I0 = length plan_line
138 if $I0 < 4 goto plan_error
140 # this needs to take into account TAP Versions
141 $S0 = substr plan_line, 0, 3
142 unless $S0 == "1.." goto plan_error
144 plan_parts = new 'FixedPMCArray'
147 split plan_parts, "..", plan_line
148 num_expected_tests = plan_parts[1]
150 $I1 = num_expected_tests
151 unless $I1 == num_expected_tests goto plan_error
152 .return (num_expected_tests)
154 # this indicates an invalid plan
163 # vim: expandtab shiftwidth=4 ft=pir: