Add tests to start a Bug Hunt
[tapir.git] / t / 02-parse_tapstream.t
blobc1f40576b4eed748ab5a8d960437a2c19f86d72a
1 #!/usr/bin/env parrot
4 .sub main :main
5     .include 'test_more.pir'
6     .local pmc tapir, klass
7     load_bytecode 'lib/Tapir/Parser.pbc'
8     load_bytecode 'lib/Tapir/Stream.pbc'
10     plan(68)
12     # setup test data
13     klass = newclass [ 'Tapir'; 'Parser' ]
14     tapir = klass.'new'()
16     # run tests
17     test_is_pass(tapir)
18     test_really_simple(tapir)
19     test_parse_tapstream_simple(tapir)
20     test_parse_tapstream_all_pass(tapir)
21     test_parse_tapstream_all_fail(tapir)
22     test_parse_tapstream_diagnostics(tapir)
23     test_parse_tapstream_too_many_passing_tests(tapir)
24     test_parse_tapstream_not_enough_tests(tapir)
25     test_parse_tapstream_todo(tapir)
26     test_parse_tapstream_skip(tapir)
27     test_parse_tapstream_bail(tapir)
28     test_parse_tapstream_correct_number_of_failed(tapir)
29 .end
32 .sub test_parse_tapstream_correct_number_of_failed
33     .param pmc tapir
34     .local pmc stream
35     .local string tap
36     tap = <<"TAP"
37 1..3
39 not ok 1
40 # Failed test 1
41 #         have: NULL
42 #         want: 1
43 ok 2
44 not ok 3
45 # Failed test 3
46 #         have: NULL
47 #         want: cheese
48 # Looks like you failed 2 tests of 3
49 TAP
50     stream = tapir.'parse_tapstream'(tap)
52     $I0 = stream.'get_plan'()
53     is($I0,3,"parse_tapstream detects the plan correctly")
55     $I0 = stream.'get_pass'()
56     is($I0,1,"parse_tapstream detects 1 passing test")
58     $I0 = stream.'get_fail'()
59     is($I0,2,"parse_tapstream detects 2 failing tests")
61     $I0 = stream.'get_todo'()
62     is($I0,0,"parse_tapstream detects no todo tests")
64     $I0 = stream.'get_skip'()
65     is($I0,0,"parse_tapstream detects two skipped test")
67     $I0 = stream.'total'()
68     is($I0,3,"parse_tapstream detected 3 tests in total")
70     $I0 = stream.'is_pass'()
71     is($I0,0,"parse_tapstream fails this")
72 .end
74 .sub test_parse_tapstream_bail
75     .param pmc tapir
76     .local pmc stream
77     .local string tap
78     tap = <<"TAP"
79 1..2
80 ok 1 - Testing some stuff
81 Bail out! Ruh roh
82 ok 2 - This test is never run
83 TAP
84     stream = tapir.'parse_tapstream'(tap)
85     $I0 = stream.'get_pass'()
86     is($I0,1,'parse_tapstream bails out properly')
88     $I0 = stream.'get_fail'()
89     is($I0,0,'parse_tapstream gets the right number of fails when bailing')
90 .end
92 .sub test_parse_tapstream_skip
93     .param pmc tapir
94     .local pmc stream
95     .local string tap
96     tap = <<"TAP"
97 1..3
98 ok 1 - Testing some stuff
99 ok 2 # skip some great reason
100 ok 3 # SKIP another great reason
102     stream = tapir.'parse_tapstream'(tap)
104     $I0 = stream.'get_plan'()
105     is($I0,3,"parse_tapstream detects the plan correctly")
107     $I0 = stream.'get_pass'()
108     is($I0,1,"parse_tapstream detects 1 passing test")
110     $I0 = stream.'get_fail'()
111     is($I0,0,"parse_tapstream detects no failing test")
113     $I0 = stream.'get_todo'()
114     is($I0,0,"parse_tapstream detects no todo tests")
116     $I0 = stream.'get_skip'()
117     is($I0,2,"parse_tapstream detects two skipped test")
119     $I0 = stream.'total'()
120     is($I0,3,"parse_tapstream detected 3 tests in total")
122     $I0 = stream.'is_pass'()
123     is($I0,1,"parse_tapstream will pass a TAP stream with todo tests")
124 .end
127 .sub test_parse_tapstream_todo
128     .param pmc tapir
129     .local pmc stream
130     .local string tap
131     tap = <<"TAP"
132 1..3
133 ok 1 - Class of Tapir::Parser is of the correct type
134 ok 2 - new returns a Tapir::Parser object isa Tapir;Parser
135 not ok 3 # TODO make lots of money
137     stream = tapir.'parse_tapstream'(tap)
139     $I0 = stream.'get_plan'()
140     is($I0,3,"parse_tapstream detects the plan correctly")
142     $I0 = stream.'get_pass'()
143     is($I0,2,"parse_tapstream detects 2 passing tests")
145     $I0 = stream.'get_fail'()
146     is($I0,0,"parse_tapstream detects no failing test")
148     $I0 = stream.'get_todo'()
149     is($I0,1,"parse_tapstream detects one todo test")
151     $I0 = stream.'get_skip'()
152     is($I0,0,"parse_tapstream detects no skipped test")
154     $I0 = stream.'total'()
155     is($I0,3,"parse_tapstream detected 3 tests in total")
157     $I0 = stream.'is_pass'()
158     is($I0,1,"parse_tapstream will pass a TAP stream with todo tests")
160 .end
162 .sub test_parse_tapstream_not_enough_tests
163     .param pmc tapir
164     .local pmc stream
165     .local string tap
166     tap = <<"TAP"
167 1..5
168 ok 1 - Class of Tapir::Parser is of the correct type
169 ok 2 - new returns a Tapir::Parser object isa Tapir;Parser
171     stream = tapir.'parse_tapstream'(tap)
173     $I0 = stream.'get_plan'()
174     is($I0,5,"parse_tapstream detects the plan correctly")
176     $I0 = stream.'get_pass'()
177     is($I0,2,"parse_tapstream detects 2 passing tests")
179     $I0 = stream.'get_fail'()
180     is($I0,0,"parse_tapstream detects a failing test")
182     $I0 = stream.'get_todo'()
183     is($I0,0,"parse_tapstream detects no todo test")
185     $I0 = stream.'get_skip'()
186     is($I0,0,"parse_tapstream detects no skipped test")
188     $I0 = stream.'total'()
189     is($I0,2,"parse_tapstream detected 2 tests in total")
191     $I0 = stream.'is_pass'()
192     is($I0,0,"parse_tapstream does not pass a TAP stream with not enough tests")
193 .end
195 .sub test_parse_tapstream_too_many_passing_tests
196     .param pmc tapir
197     .local pmc stream
198     .local string tap
199     tap = <<"TAP"
200 1..2
201 ok 1 - Class of Tapir::Parser is of the correct type
202 ok 2 - new returns a Tapir::Parser object isa Tapir;Parser
203 ok 3
205     stream = tapir.'parse_tapstream'(tap)
207     $I0 = stream.'get_plan'()
208     is($I0,2,"parse_tapstream detects the plan correctly")
210     $I0 = stream.'get_pass'()
211     is($I0,3,"parse_tapstream detects a passing test")
213     $I0 = stream.'get_fail'()
214     is($I0,0,"parse_tapstream detects a failing test")
216     $I0 = stream.'get_todo'()
217     is($I0,0,"parse_tapstream detects no todo test")
219     $I0 = stream.'get_skip'()
220     is($I0,0,"parse_tapstream detects no skipped test")
222     $I0 = stream.'total'()
223     is($I0,3,"parse_tapstream detected 2 tests in total")
225     $I0 = stream.'is_pass'()
226     is($I0,0,"parse_tapstream does not pass a TAP stream with too many tests")
227 .end
229 .sub test_is_pass
230     .param pmc tapir
231     .local pmc stream
232     $S0  = "1..2\nok 1 - i like cheese\nok 2 - foobar\n"
233     stream = tapir.'parse_tapstream'($S0)
234     $I0 = stream.'is_pass'()
235     is($I0,1,"is_pass correctly detects 2 passing tests")
237     $S0  = "1..3\nok 1 - i like cheese\nok 2 - foobar\nnot ok 3 - blammo!\n"
238     stream = tapir.'parse_tapstream'($S0)
239     $I0 = stream.'is_pass'()
240     is($I0,0,"is_pass correctly detected 1 failing test")
242     $S0  = "1..2\nok 1 - i like cheese\nok 2 - foobar\nok 3 - blammo!\n"
243     stream = tapir.'parse_tapstream'($S0)
244     $I0 = stream.'is_pass'()
245     is($I0,0,"is_pass correctly detects that too many tests have run")
247     $S0  = "1..4\nok 1 - i like cheese\nok 2 - foobar\nok 3 - blammo!\n"
248     stream = tapir.'parse_tapstream'($S0)
249     $I0 = stream.'is_pass'()
250     is($I0,0,"is_pass correctly detects that too few tests have run")
251 .end
253 .sub test_parse_tapstream_diagnostics
254     .param pmc tapir
255     .local pmc stream
256     $S0  = "1..2\nok 1 - i like cheese\nok 2 - foobar\n"
257     stream = tapir.'parse_tapstream'($S0)
258     $I0 = stream.'get_plan'()
259     is($I0,2,"parse_tapstream detects the plan correctly")
261     $I0 = stream.'get_pass'()
262     is($I0,2,"parse_tapstream detects a passing test with diag")
264     $I0 = stream.'get_fail'()
265     is($I0,0,"parse_tapstream detects no failing test")
267     $S0  = "1..2\nnot ok 1 - i like cheese\nnot ok 2 - foobar\n"
268     stream = tapir.'parse_tapstream'($S0)
269     $I0 = stream.'get_plan'()
270     is($I0,2,"parse_tapstream detects the plan correctly")
272     $I0 = stream.'get_pass'()
273     is($I0,0,"parse_tapstream detects no passing tests with diag")
275     $I0 = stream.'get_fail'()
276     is($I0,2,"parse_tapstream detects 2 failing tests with diag")
278     $I0 = stream.'total'()
279     is($I0,2,"parse_tapstream detected 2 tests in total")
280 .end
282 .sub test_parse_tapstream_all_pass
283     .param pmc tapir
284     .local pmc stream
285     $S0  = "1..2\nok 1\nok 2\n"
286     stream = tapir.'parse_tapstream'($S0)
288     $I0 = stream.'get_plan'()
289     is($I0,2,"parse_tapstream detects the plan correctly")
291     $I0 = stream.'get_pass'()
292     is($I0,2,"parse_tapstream detects a passing test")
294     $I0 = stream.'get_fail'()
295     is($I0,0,"parse_tapstream detects a failing test")
297     $I0 = stream.'get_todo'()
298     is($I0,0,"parse_tapstream detects no todo test")
300     $I0 = stream.'get_skip'()
301     is($I0,0,"parse_tapstream detects no skipped test")
303     $I0 = stream.'total'()
304     is($I0,2,"parse_tapstream detected 2 tests in total")
305 .end
307 .sub test_parse_tapstream_all_fail
308     .param pmc tapir
309     .local pmc stream
310     $S0  = "1..2\nnot ok 1\nnot ok 2\n"
311     stream = tapir.'parse_tapstream'($S0)
313     $I0 = stream.'get_plan'()
314     is($I0,2,"parse_tapstream detects the plan correctly")
316     $I0 = stream.'get_pass'()
317     is($I0,0,"parse_tapstream detects no passing tests")
319     $I0 = stream.'get_fail'()
320     is($I0,2,"parse_tapstream detects 2 failing tests")
322     $I0 = stream.'get_todo'()
323     is($I0,0,"parse_tapstream detects no todo test")
325     $I0 = stream.'get_skip'()
326     is($I0,0,"parse_tapstream detects no skipped test")
328     $I0 = stream.'total'()
329     is($I0,2,"parse_tapstream detected 2 tests in total")
330 .end
332 .sub test_parse_tapstream_simple
333     .param pmc tapir
334     .local pmc stream
335     $S0  = "1..2\nok 1\nnot ok 2\n"
336     stream = tapir.'parse_tapstream'($S0)
337     $S1 = typeof stream
338     is($S1,"Tapir;Stream","parse_tapstream returns a Tapir;Stream object")
340     $I0 = stream.'get_plan'()
341     is($I0,2,"parse_tapstream detects the plan correctly")
343     $I0 = stream.'get_pass'()
344     is($I0,1,"parse_tapstream detects a passing test")
346     $I0 = stream.'get_fail'()
347     is($I0,1,"parse_tapstream detects a failing test")
349     $I0 = stream.'get_todo'()
350     is($I0,0,"parse_tapstream detects no todo test")
352     $I0 = stream.'get_skip'()
353     is($I0,0,"parse_tapstream detects no skipped test")
355     $I0 = stream.'total'()
356     is($I0,2,"parse_tapstream detected 2 tests in total")
357 .end
359 .sub test_really_simple
360     .param pmc tapir
361     .local pmc stream
362     $S0  = <<"TAP"
363 1..1
364 ok 1 - parse_tapstream does not pass a dead test
366     stream = tapir.'parse_tapstream'($S0)
367     $I0    = stream.'is_pass'()
368     is($I0,1,"a single passed test with diagnostic works")
369 .end