Commit | Line | Data |
b965d173 |
1 | #!/usr/bin/perl -wT |
2 | |
3 | use strict; |
4 | use lib 't/lib'; |
5 | |
6 | use Test::More tests => 14; |
7 | |
8 | use TAP::Parser; |
f7c69158 |
9 | use TAP::Parser::IteratorFactory; |
b965d173 |
10 | |
11 | sub tap_to_lines { |
12 | my $string = shift; |
13 | my @lines = ( $string =~ /.*\n/g ); |
14 | return \@lines; |
15 | } |
16 | |
17 | my $tap = <<'END_TAP'; |
18 | 1..4 |
19 | ok 1 - input file opened |
20 | ... this is junk |
21 | not ok first line of the input valid # todo some data |
22 | # this is a comment |
23 | ok 3 - read the rest of the file |
24 | not ok 4 - this is a real failure |
25 | Bail out! We ran out of foobar. |
26 | not ok 5 |
27 | END_TAP |
28 | |
f7c69158 |
29 | my $factory = TAP::Parser::IteratorFactory->new; |
30 | my $parser = TAP::Parser->new( |
31 | { stream => $factory->make_iterator( tap_to_lines($tap) ), |
b965d173 |
32 | } |
33 | ); |
34 | |
35 | # results() is sane? |
36 | |
37 | # check the test plan |
38 | my $result = $parser->next(); |
39 | |
40 | # TEST |
41 | ok $result->is_plan, 'We should have a plan'; |
42 | |
43 | # a normal, passing test |
44 | |
45 | my $test = $parser->next(); |
46 | |
47 | # TEST |
48 | ok $test->is_test, '... and a test'; |
49 | |
50 | # junk lines should be preserved |
51 | |
52 | my $unknown = $parser->next(); |
53 | |
54 | # TEST |
55 | ok $unknown->is_unknown, '... and an unknown line'; |
56 | |
57 | # a failing test, which also happens to have a directive |
58 | |
59 | my $failed = $parser->next(); |
60 | |
61 | # TEST |
62 | ok $failed->is_test, '... and another test'; |
63 | |
64 | # comments |
65 | |
66 | my $comment = $parser->next(); |
67 | |
68 | # TEST |
69 | ok $comment->is_comment, '... and a comment'; |
70 | |
71 | # another normal, passing test |
72 | |
73 | $test = $parser->next(); |
74 | |
75 | # TEST |
76 | ok $test->is_test, '... and another test'; |
77 | |
78 | # a failing test |
79 | |
80 | $failed = $parser->next(); |
81 | |
82 | # TEST |
83 | ok $failed->is_test, '... and yet another test'; |
84 | |
85 | # ok 5 # skip we have no description |
86 | # skipped test |
87 | my $bailout = $parser->next(); |
88 | |
89 | # TEST |
90 | ok $bailout->is_bailout, 'And finally we should have a bailout'; |
91 | |
92 | # TEST |
93 | is $bailout->as_string, 'We ran out of foobar.', |
94 | '... and as_string() should return the explanation'; |
95 | |
96 | # TEST |
97 | is( $bailout->raw, 'Bail out! We ran out of foobar.', |
98 | '... and raw() should return the explanation' |
99 | ); |
100 | |
101 | # TEST |
102 | is( $bailout->explanation, 'We ran out of foobar.', |
103 | '... and it should have the correct explanation' |
104 | ); |
105 | |
106 | my $more_tap = "1..1\nok 1 - input file opened\n"; |
107 | |
108 | my $second_parser = TAP::Parser->new( |
f7c69158 |
109 | { stream => $factory->make_iterator( [ split( /\n/, $more_tap ) ] ), |
b965d173 |
110 | } |
111 | ); |
112 | |
113 | $result = $second_parser->next(); |
114 | |
115 | # TEST |
116 | ok $result->is_plan(), "Result is not the leftover line"; |
117 | |
118 | $result = $second_parser->next(); |
119 | |
120 | # TEST |
121 | ok $result->is_test(), "Result is a test"; |
122 | |
123 | # TEST |
124 | ok $result->is_ok(), "The event has passed"; |
125 | |