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, 2
117 if $S0 == "ok" goto yes
119 $S0 = substr tapline, 0, 5
120 if $S0 == "not ok" goto yes
127 # parse_plan returns the expected number of tests given a plan line as a string
129 .sub parse_plan :method
130 .param string plan_line
131 .local pmc plan_parts
133 .local num num_expected_tests
135 $I0 = length plan_line
136 if $I0 < 4 goto plan_error
138 # this needs to take into account TAP Versions
139 $S0 = substr plan_line, 0, 3
140 unless $S0 == "1.." goto plan_error
142 plan_parts = new 'FixedPMCArray'
145 split plan_parts, "..", plan_line
146 num_expected_tests = plan_parts[1]
148 $I1 = num_expected_tests
149 unless $I1 == num_expected_tests goto plan_error
150 .return (num_expected_tests)
152 # this indicates an invalid plan
161 # vim: expandtab shiftwidth=4 ft=pir: