6 use Test::More tests => 47;
9 use TAP::Parser::Iterator;
11 my ( $STREAMED, $ITER ) = ( 'TAP::Parser', 'TAP::Parser::Iterator' );
12 my $ITER_FH = "${ITER}::Stream";
13 my $ITER_ARRAY = "${ITER}::Array";
15 my $stream = TAP::Parser::Iterator->new( \*DATA );
16 isa_ok $stream, 'TAP::Parser::Iterator';
17 my $parser = TAP::Parser->new( { stream => $stream } );
18 isa_ok $parser, 'TAP::Parser',
19 '... and creating a streamed parser should succeed';
21 can_ok $parser, '_stream';
22 is ref $parser->_stream, $ITER_FH,
23 '... and it should return the proper iterator';
24 can_ok $parser, 'next';
25 is $parser->next->as_string, '1..5',
26 '... and the plan should parse correctly';
27 is $parser->next->as_string, 'ok 1 - input file opened',
28 '... and the first test should parse correctly';
29 is $parser->next->as_string, '... this is junk',
30 '... and junk should parse correctly';
31 is $parser->next->as_string,
32 'not ok 2 first line of the input valid # TODO some data',
33 '... and the second test should parse correctly';
34 is $parser->next->as_string, '# this is a comment',
35 '... and comments should parse correctly';
36 is $parser->next->as_string, 'ok 3 - read the rest of the file',
37 '... and the third test should parse correctly';
38 is $parser->next->as_string, 'not ok 4 - this is a real failure',
39 '... and the fourth test should parse correctly';
40 is $parser->next->as_string, 'ok 5 # SKIP we have no description',
41 '... and fifth test should parse correctly';
43 ok !$parser->parse_errors, '... and we should have no parse errors';
47 my $tap = <<'END_TAP';
48 ok 1 - input file opened
50 not ok first line of the input valid # todo some data
52 ok 3 - read the rest of the file
53 not ok 4 - this is a real failure
54 ok 5 # skip we have no description
58 $stream = $ITER->new( [ split /\n/ => $tap ] );
59 ok $parser = TAP::Parser->new( { stream => $stream } ),
60 'Now we create a parser with the plan at the end';
61 isa_ok $parser->_stream, $ITER_ARRAY,
62 '... and now we should have an array iterator';
63 is $parser->next->as_string, 'ok 1 - input file opened',
64 '... and the first test should parse correctly';
65 is $parser->next->as_string, '... this is junk',
66 '... and junk should parse correctly';
67 is $parser->next->as_string,
68 'not ok 2 first line of the input valid # TODO some data',
69 '... and the second test should parse correctly';
70 is $parser->next->as_string, '# this is a comment',
71 '... and comments should parse correctly';
72 is $parser->next->as_string, 'ok 3 - read the rest of the file',
73 '... and the third test should parse correctly';
74 is $parser->next->as_string, 'not ok 4 - this is a real failure',
75 '... and the fourth test should parse correctly';
76 is $parser->next->as_string, 'ok 5 # SKIP we have no description',
77 '... and fifth test should parse correctly';
78 is $parser->next->as_string, '1..5',
79 '... and the plan should parse correctly';
81 ok !$parser->parse_errors, '... and we should have no parse errors';
83 # misplaced plan (and one-off errors)
86 ok 1 - input file opened
89 not ok first line of the input valid # todo some data
91 ok 3 - read the rest of the file
92 not ok 4 - this is a real failure
93 ok 5 # skip we have no description
96 $stream = $ITER->new( [ split /\n/ => $tap ] );
98 ok $parser = TAP::Parser->new( { stream => $stream } ),
99 'Now we create a parser with a plan as the second line';
100 is $parser->next->as_string, 'ok 1 - input file opened',
101 '... and the first test should parse correctly';
102 is $parser->next->as_string, '1..5',
103 '... and the plan should parse correctly';
104 is $parser->next->as_string, '... this is junk',
105 '... and junk should parse correctly';
106 is $parser->next->as_string,
107 'not ok 2 first line of the input valid # TODO some data',
108 '... and the second test should parse correctly';
109 is $parser->next->as_string, '# this is a comment',
110 '... and comments should parse correctly';
111 is $parser->next->as_string, 'ok 3 - read the rest of the file',
112 '... and the third test should parse correctly';
113 is $parser->next->as_string, 'not ok 4 - this is a real failure',
114 '... and the fourth test should parse correctly';
115 is $parser->next->as_string, 'ok 5 # SKIP we have no description',
116 '... and fifth test should parse correctly';
118 ok $parser->parse_errors, '... and we should have one parse error';
119 is + ( $parser->parse_errors )[0],
120 'Plan (1..5) must be at the beginning or end of the TAP output',
121 '... telling us that our plan went awry';
124 ok 1 - input file opened
126 not ok first line of the input valid # todo some data
128 ok 3 - read the rest of the file
129 not ok 4 - this is a real failure
131 ok 5 # skip we have no description
134 $stream = $ITER->new( [ split /\n/ => $tap ] );
136 ok $parser = TAP::Parser->new( { stream => $stream } ),
137 'Now we create a parser with the plan as the second to last line';
138 is $parser->next->as_string, 'ok 1 - input file opened',
139 '... and the first test should parse correctly';
140 is $parser->next->as_string, '... this is junk',
141 '... and junk should parse correctly';
142 is $parser->next->as_string,
143 'not ok 2 first line of the input valid # TODO some data',
144 '... and the second test should parse correctly';
145 is $parser->next->as_string, '# this is a comment',
146 '... and comments should parse correctly';
147 is $parser->next->as_string, 'ok 3 - read the rest of the file',
148 '... and the third test should parse correctly';
149 is $parser->next->as_string, 'not ok 4 - this is a real failure',
150 '... and the fourth test should parse correctly';
151 is $parser->next->as_string, '1..5',
152 '... and the plan should parse correctly';
153 is $parser->next->as_string, 'ok 5 # SKIP we have no description',
154 '... and fifth test should parse correctly';
156 ok $parser->parse_errors, '... and we should have one parse error';
157 is + ( $parser->parse_errors )[0],
158 'Plan (1..5) must be at the beginning or end of the TAP output',
159 '... telling us that our plan went awry';
163 ok 1 - input file opened
165 not ok first line of the input valid # todo some data
167 ok 3 - read the rest of the file
168 not ok 4 - this is a real failure
169 ok 5 # skip we have no description