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