2 # Copyright (C) 2010, Parrot Foundation.
11 Test the TAP/Parser library
15 % prove t/library/tap_parser.t
20 .include 'test_more.pir'
22 load_bytecode 'TAP/Parser.pir'
26 test_grammar_bailout()
27 test_grammar_comment()
29 test_grammar_version()
31 test_tap_with_blank_lines()
32 test_tap_has_problem()
33 test_tap_version_wrong_place()
34 test_tap_trailing_plan()
38 .sub 'test_grammar_plan'
39 .local pmc grammar, token
40 grammar = new ['TAP';'Parser';'Grammar']
41 token = grammar.'tokenize'("1..42")
42 $P0 = get_class ['TAP';'Parser';'Result';'Plan']
44 $P0 = getattribute token, 'raw'
46 $P0 = getattribute token, 'plan'
48 $P0 = getattribute token, 'tests_planned'
49 is($P0, 42, "tests_planned")
51 token = grammar.'tokenize'("1..0 # SKIP why not?")
52 $P0 = get_class ['TAP';'Parser';'Result';'Plan']
54 $P0 = getattribute token, 'raw'
55 is($P0, "1..0 # SKIP why not?")
56 $P0 = getattribute token, 'plan'
58 $P0 = getattribute token, 'tests_planned'
59 is($P0, 0, "tests_planned")
60 $P0 = getattribute token, 'directive'
61 is($P0, 'SKIP', "directive")
62 $P0 = getattribute token, 'explanation'
63 is($P0, 'why not?', "explanation")
65 token = grammar.'tokenize'("1..0")
66 $P0 = get_class ['TAP';'Parser';'Result';'Plan']
68 $P0 = getattribute token, 'raw'
70 $P0 = getattribute token, 'plan'
72 $P0 = getattribute token, 'tests_planned'
73 is($P0, 0, "tests_planned")
74 $P0 = getattribute token, 'directive'
75 is($P0, 'SKIP', "directive")
78 .sub 'test_grammar_bailout'
79 .local pmc grammar, token
80 grammar = new ['TAP';'Parser';'Grammar']
81 token = grammar.'tokenize'("Bail out!")
82 $P0 = get_class ['TAP';'Parser';'Result';'Bailout']
84 $P0 = getattribute token, 'raw'
86 $P0 = getattribute token, 'explanation'
87 is($P0, '', "no explanation")
89 token = grammar.'tokenize'("Bail out! some explanation")
90 $P0 = get_class ['TAP';'Parser';'Result';'Bailout']
92 $P0 = getattribute token, 'raw'
93 is($P0, "Bail out! some explanation")
94 $P0 = getattribute token, 'explanation'
95 is($P0, "some explanation", "explanation")
98 .sub 'test_grammar_comment'
99 .local pmc grammar, token
100 grammar = new ['TAP';'Parser';'Grammar']
101 token = grammar.'tokenize'("# this is a comment")
102 $P0 = get_class ['TAP';'Parser';'Result';'Comment']
104 $P0 = getattribute token, 'raw'
105 is($P0, "# this is a comment")
106 $P0 = getattribute token, 'comment'
107 is($P0, 'this is a comment', "comment")
110 .sub 'test_grammar_tests'
111 .local pmc grammar, token
112 grammar = new ['TAP';'Parser';'Grammar']
113 token = grammar.'tokenize'("ok 1 this is a test")
114 $P0 = get_class ['TAP';'Parser';'Result';'Test']
116 $P0 = getattribute token, 'raw'
117 is($P0, "ok 1 this is a test")
118 $P0 = getattribute token, 'ok'
120 $P0 = getattribute token, 'test_num'
121 is($P0, 1, "test_num")
122 $P0 = getattribute token, 'description'
123 is($P0, 'this is a test', "description")
125 token = grammar.'tokenize'("not ok 2 this is a test # TODO whee!")
126 $P0 = get_class ['TAP';'Parser';'Result';'Test']
128 $P0 = getattribute token, 'raw'
129 is($P0, "not ok 2 this is a test # TODO whee!")
130 $P0 = getattribute token, 'ok'
131 is($P0, 'not ok', "ok")
132 $P0 = getattribute token, 'test_num'
133 is($P0, 2, "test_num")
134 $P0 = getattribute token, 'description'
135 is($P0, 'this is a test', "description")
136 $P0 = getattribute token, 'directive'
137 is($P0, 'TODO', "directive")
138 $P0 = getattribute token, 'explanation'
139 is($P0, 'whee!', "explanation")
141 token = grammar.'tokenize'("ok 22 this is a test \\# TODO whee!")
142 $P0 = get_class ['TAP';'Parser';'Result';'Test']
144 $P0 = getattribute token, 'raw'
145 is($P0, "ok 22 this is a test \\# TODO whee!")
146 $P0 = getattribute token, 'ok'
148 $P0 = getattribute token, 'test_num'
149 is($P0, 22, "test_num")
150 $P0 = getattribute token, 'description'
151 is($P0, 'this is a test \# TODO whee!', "description")
153 token = grammar.'tokenize'("not ok")
154 $P0 = get_class ['TAP';'Parser';'Result';'Test']
156 $P0 = getattribute token, 'raw'
158 $P0 = getattribute token, 'ok'
159 is($P0, 'not ok', "ok")
160 $P0 = getattribute token, 'test_num'
162 is($P0, $P1, "test_num")
163 $P0 = getattribute token, 'description'
165 is($P0, $P1, "description")
167 token = grammar.'tokenize'("ok 42")
168 $P0 = get_class ['TAP';'Parser';'Result';'Test']
170 $P0 = getattribute token, 'raw'
172 $P0 = getattribute token, 'ok'
174 $P0 = getattribute token, 'test_num'
175 is($P0, 42, "test_num")
176 $P0 = getattribute token, 'description'
178 is($P0, $P1, "description")
181 .sub 'test_grammar_version'
182 .local pmc grammar, token
183 grammar = new ['TAP';'Parser';'Grammar']
184 token = grammar.'tokenize'("TAP version 12")
185 $P0 = get_class ['TAP';'Parser';'Result';'Version']
187 $P0 = getattribute token, 'raw'
188 is($P0, "TAP version 12")
189 $P0 = getattribute token, 'version'
190 is($P0, 12, "version")
196 result = new 'ResizablePMCArray'
197 $P0 = get_hll_global ['TAP';'Parser'], 'next'
199 coro = newclosure $P0
210 .local pmc parser, result, token
211 parser = new ['TAP';'Parser']
212 parser.'tap'(<<'END_TAP')
215 ok 1 - input file opened
217 not ok first line of the input valid # todo some data
219 ok 3 - read the rest of the file
220 not ok 4 - this is a real failure
221 ok 5 # skip we have no description
222 ok 6 - you shall not pass! # TODO should have failed
223 not ok 7 - Gandalf wins. Game over. # TODO 'bout time!
225 result = _get_results(parser)
226 $I0 = elements result
227 is($I0, 11, "elements")
230 $P0 = get_class ['TAP';'Parser';'Result';'Version']
232 $P0 = getattribute token, 'version'
233 is($P0, 13, "version")
236 $P0 = get_class ['TAP';'Parser';'Result';'Plan']
238 $P0 = getattribute token, 'plan'
239 is($P0, "1..7", "plan")
240 $P0 = getattribute token, 'tests_planned'
241 is($P0, 7, "tests_planned")
244 $P0 = get_class ['TAP';'Parser';'Result';'Test']
246 $P0 = getattribute token, 'ok'
248 $P0 = getattribute token, 'test_num'
249 is($P0, 1, "test_num")
250 $P0 = getattribute token, 'description'
251 is($P0, '- input file opened', "description")
252 $I0 = token.'is_ok'()
254 $I0 = token.'is_actual_ok'()
256 $I0 = token.'has_todo'()
258 $I0 = token.'has_skip'()
262 $P0 = get_class ['TAP';'Parser';'Result';'Unknown']
264 $P0 = getattribute token, 'raw'
265 is($P0, '... this is junk', "raw")
268 $P0 = get_class ['TAP';'Parser';'Result';'Test']
270 $P0 = getattribute token, 'ok'
271 is($P0, 'not ok', "ok")
272 $P0 = getattribute token, 'test_num'
273 is($P0, 2, "test_num")
274 $P0 = getattribute token, 'description'
275 is($P0, 'first line of the input valid', "description")
276 $I0 = token.'is_ok'()
278 $I0 = token.'is_actual_ok'()
280 $I0 = token.'has_todo'()
282 $I0 = token.'has_skip'()
284 $P0 = getattribute token, 'explanation'
285 is($P0, 'some data', "explanation")
288 $P0 = get_class ['TAP';'Parser';'Result';'Comment']
290 $P0 = getattribute token, 'comment'
291 is($P0, 'this is a comment', "comment")
294 $P0 = get_class ['TAP';'Parser';'Result';'Test']
296 $P0 = getattribute token, 'ok'
298 $P0 = getattribute token, 'test_num'
299 is($P0, 3, "test_num")
300 $P0 = getattribute token, 'description'
301 is($P0, '- read the rest of the file', "description")
302 $I0 = token.'is_ok'()
304 $I0 = token.'is_actual_ok'()
306 $I0 = token.'has_todo'()
308 $I0 = token.'has_skip'()
312 $P0 = get_class ['TAP';'Parser';'Result';'Test']
314 $P0 = getattribute token, 'ok'
315 is($P0, 'not ok', "ok")
316 $P0 = getattribute token, 'test_num'
317 is($P0, 4, "test_num")
318 $P0 = getattribute token, 'description'
319 is($P0, '- this is a real failure', "description")
320 $I0 = token.'is_ok'()
322 $I0 = token.'is_actual_ok'()
324 $I0 = token.'has_todo'()
326 $I0 = token.'has_skip'()
330 $P0 = get_class ['TAP';'Parser';'Result';'Test']
332 $P0 = getattribute token, 'ok'
334 $P0 = getattribute token, 'test_num'
335 is($P0, 5, "test_num")
336 $I0 = token.'is_ok'()
338 $I0 = token.'is_actual_ok'()
340 $I0 = token.'has_todo'()
342 $I0 = token.'has_skip'()
344 $P0 = getattribute token, 'explanation'
345 is($P0, 'we have no description', "explanation")
348 $P0 = get_class ['TAP';'Parser';'Result';'Test']
350 $P0 = getattribute token, 'ok'
352 $P0 = getattribute token, 'test_num'
353 is($P0, 6, "test_num")
354 $P0 = getattribute token, 'description'
355 is($P0, '- you shall not pass!', "description")
356 $I0 = token.'is_ok'()
358 $I0 = token.'is_actual_ok'()
360 $I0 = token.'has_todo'()
362 $I0 = token.'has_skip'()
364 $P0 = getattribute token, 'explanation'
365 is($P0, 'should have failed', "explanation")
368 $P0 = get_class ['TAP';'Parser';'Result';'Test']
370 $P0 = getattribute token, 'ok'
371 is($P0, 'not ok', "ok")
372 $P0 = getattribute token, 'test_num'
373 is($P0, 7, "test_num")
374 $P0 = getattribute token, 'description'
375 is($P0, '- Gandalf wins. Game over.', "description")
376 $I0 = token.'is_ok'()
378 $I0 = token.'is_actual_ok'()
380 $I0 = token.'has_todo'()
382 $I0 = token.'has_skip'()
384 $P0 = getattribute token, 'explanation'
385 is($P0, "'bout time!", "explanation")
387 $P0 = getattribute parser, 'passed'
389 is($S0, "1, 2, 3, 5, 6, 7", "passed")
390 $P0 = getattribute parser, 'failed'
392 is($S0, "4", "failed")
393 $P0 = getattribute parser, 'actual_passed'
395 is($S0, "1, 3, 5, 6", "actual_passed")
396 $P0 = getattribute parser, 'actual_failed'
398 is($S0, "2, 4, 7", "actual_failed")
399 $P0 = getattribute parser, 'todo'
401 is($S0, "2, 6, 7", "todo")
402 $P0 = getattribute parser, 'skipped'
404 is($S0, "5", "skipped")
405 $P0 = getattribute parser, 'todo_passed'
407 is($S0, "6", "todo_passed")
409 $P0 = getattribute parser, 'plan'
410 is($P0, "1..7", "plan")
411 $P0 = getattribute parser, 'tests_planned'
412 is($P0, 7, "tests_planned")
415 .sub 'test_tap_with_blank_lines'
416 .local pmc parser, result, token
417 parser = new ['TAP';'Parser']
418 parser.'tap'(<<'END_TAP')
420 ok 1 - input file opened
423 ok 2 - read the rest of the file
425 result = _get_results(parser)
426 $I0 = elements result
427 is($I0, 5, "elements")
430 $P0 = get_class ['TAP';'Parser';'Result';'Plan']
432 $P0 = getattribute token, 'plan'
433 is($P0, "1..2", "plan")
434 $P0 = getattribute token, 'tests_planned'
435 is($P0, 2, "tests_planned")
438 $P0 = get_class ['TAP';'Parser';'Result';'Test']
440 $P0 = getattribute token, 'ok'
442 $P0 = getattribute token, 'test_num'
443 is($P0, 1, "test_num")
444 $P0 = getattribute token, 'description'
445 is($P0, '- input file opened', "description")
446 $I0 = token.'is_ok'()
448 $I0 = token.'is_actual_ok'()
450 $I0 = token.'has_todo'()
452 $I0 = token.'has_skip'()
456 $P0 = get_class ['TAP';'Parser';'Result';'Unknown']
458 $P0 = getattribute token, 'raw'
462 $P0 = get_class ['TAP';'Parser';'Result';'Unknown']
464 $P0 = getattribute token, 'raw'
468 $P0 = get_class ['TAP';'Parser';'Result';'Test']
470 $P0 = getattribute token, 'ok'
472 $P0 = getattribute token, 'test_num'
473 is($P0, 2, "test_num")
474 $P0 = getattribute token, 'description'
475 is($P0, '- read the rest of the file', "description")
476 $I0 = token.'is_ok'()
478 $I0 = token.'is_actual_ok'()
480 $I0 = token.'has_todo'()
482 $I0 = token.'has_skip'()
486 .sub 'test_tap_has_problem'
488 parser = new ['TAP';'Parser']
489 parser.'tap'(<<'END_TAP')
492 ok 1 - input file opened
493 ok 2 - Gandalf wins. Game over. # TODO 'bout time!
496 $I0 = parser.'failed'()
497 is($I0, 0, "not failed")
498 $I0 = parser.'todo_passed'()
499 is($I0, 1, "todo_passed")
500 $I0 = parser.'has_problems'()
501 nok($I0, "has not problem")
503 parser = new ['TAP';'Parser']
504 parser.'tap'(<<'END_TAP')
510 $I0 = parser.'failed'()
511 is($I0, 0, "not failed")
512 $I0 = parser.'todo_passed'()
513 is($I0, 0, "todo_passed")
514 $I0 = parser.'parse_errors'()
515 is($I0, 2, "parse_errors")
516 $I0 = parser.'has_problems'()
517 ok($I0, "has_problems")
520 .sub 'test_tap_version_wrong_place'
522 parser = new ['TAP';'Parser']
523 parser.'tap'(<<'END_TAP')
525 ok 1 - input file opened
530 $I0 = parser.'failed'()
531 is($I0, 0, "not failed")
532 $I0 = parser.'parse_errors'()
533 is($I0, 1, "parse_errors")
534 $P0 = getattribute parser, 'parse_errors'
536 is($S0, "If TAP version is present it must be the first line of output")
539 .sub 'test_tap_trailing_plan'
540 .local pmc parser, result, token
541 parser = new ['TAP';'Parser']
542 parser.'tap'(<<'END_TAP')
543 ok 1 - input file opened
547 result = _get_results(parser)
548 $I0 = elements result
549 is($I0, 3, "elements")
552 $P0 = get_class ['TAP';'Parser';'Result';'Test']
554 $P0 = getattribute token, 'ok'
556 $P0 = getattribute token, 'test_num'
557 is($P0, 1, "test_num")
558 $P0 = getattribute token, 'description'
559 is($P0, '- input file opened', "description")
560 $I0 = token.'is_ok'()
562 $I0 = token.'is_actual_ok'()
564 $I0 = token.'is_unplanned'()
565 nok($I0, "unplanned")
568 $P0 = get_class ['TAP';'Parser';'Result';'Test']
570 $P0 = getattribute token, 'ok'
572 $P0 = getattribute token, 'test_num'
573 is($P0, 2, "test_num")
574 $P0 = getattribute token, 'description'
575 is($P0, '- Gandalf wins', "description")
576 $I0 = token.'is_ok'()
578 $I0 = token.'is_actual_ok'()
580 $I0 = token.'is_unplanned'()
581 nok($I0, "unplanned")
584 $P0 = get_class ['TAP';'Parser';'Result';'Plan']
586 $P0 = getattribute token, 'plan'
587 is($P0, "1..2", "plan")
588 $P0 = getattribute token, 'tests_planned'
589 is($P0, 2, "tests_planned")
591 $I0 = parser.'passed'()
593 $I0 = parser.'failed'()
595 $I0 = parser.'parse_errors'()
596 is($I0, 0, "parse_errors")
597 $I0 = parser.'has_problems'()
598 is($I0, 0, "has_problems")
600 $P0 = getattribute parser, 'plan'
601 is($P0, "1..2", "plan")
602 $P0 = getattribute parser, 'tests_planned'
603 is($P0, 2, "tests_planned")
606 .sub 'test_aggregator'
607 .local pmc parser1, parser2, agg
608 parser1 = new ['TAP';'Parser']
609 parser1.'tap'(<<'END_TAP')
611 ok 1 - input file opened
613 not ok first line of the input valid # todo some data
615 ok 3 - read the rest of the file
616 not ok 4 - this is a real failure
617 ok 5 # skip we have no description
621 parser2 = new ['TAP';'Parser']
622 parser2.'tap'(<<'END_TAP')
624 ok 1 - gentlemen, start your engines
625 not ok first line of the input valid # todo some data
627 ok 3 - read the rest of the file
628 not ok 4 - this is a real failure
630 ok 6 - you shall not pass! # TODO should have failed
631 not ok 7 - Gandalf wins. Game over. # TODO 'bout time!
635 agg = new ['TAP';'Parser';'Aggregator']
636 agg.'add'('tap1', parser1)
637 agg.'add'('tap2', parser2)
639 $P0 = agg.'descriptions'()
641 is($I0, 2, "descriptions")
643 $P0 = getattribute agg, 'passed'
644 is($P0, 10, "passed")
645 $P0 = getattribute agg, 'failed'
647 $P0 = getattribute agg, 'todo'
649 $P0 = getattribute agg, 'skipped'
650 is($P0, 1, "skipped")
651 $P0 = getattribute agg, 'parse_errors'
652 is($P0, 1, "parse_errors")
653 $P0 = getattribute agg, 'todo_passed'
654 is($P0, 1, "todo_passed")
655 $P0 = getattribute agg, 'total'
657 $P0 = getattribute agg, 'planned'
658 is($P0, 12, "planned")
660 $I0 = agg.'has_problems'()
661 ok($I0, "has_problems")
662 $I0 = agg.'has_errors'()
663 ok($I0, "has_errors")
664 $S0 = agg.'get_status'()
665 is($S0, 'FAIL', "status")
666 $I0 = agg.'all_passed'()
667 nok($I0, "all_passed")
674 # vim: expandtab shiftwidth=4 ft=pir: