Upgrade to Test::Harness 3.05
[p5sagit/p5-mst-13.2.git] / lib / Test / Harness / t / streams.t
1 #!/usr/bin/perl -wT
2
3 use strict;
4 use lib 't/lib';
5
6 use Test::More tests => 47;
7
8 use TAP::Parser;
9 use TAP::Parser::Iterator;
10
11 my ( $STREAMED, $ITER ) = ( 'TAP::Parser', 'TAP::Parser::Iterator' );
12 my $ITER_FH    = "${ITER}::Stream";
13 my $ITER_ARRAY = "${ITER}::Array";
14
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';
20
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';
42
43 ok !$parser->parse_errors, '... and we should have no parse errors';
44
45 # plan at end
46
47 my $tap = <<'END_TAP';
48 ok 1 - input file opened
49 ... this is junk
50 not ok first line of the input valid # todo some data
51 # this is a comment
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
55 1..5
56 END_TAP
57
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';
80
81 ok !$parser->parse_errors, '... and we should have no parse errors';
82
83 # misplaced plan (and one-off errors)
84
85 $tap = <<'END_TAP';
86 ok 1 - input file opened
87 1..5
88 ... this is junk
89 not ok first line of the input valid # todo some data
90 # this is a comment
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
94 END_TAP
95
96 $stream = $ITER->new( [ split /\n/ => $tap ] );
97
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';
117
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';
122
123 $tap = <<'END_TAP';
124 ok 1 - input file opened
125 ... this is junk
126 not ok first line of the input valid # todo some data
127 # this is a comment
128 ok 3 - read the rest of the file
129 not ok 4 - this is a real failure
130 1..5
131 ok 5 # skip we have no description
132 END_TAP
133
134 $stream = $ITER->new( [ split /\n/ => $tap ] );
135
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';
155
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';
160
161 __DATA__
162 1..5
163 ok 1 - input file opened
164 ... this is junk
165 not ok first line of the input valid # todo some data
166 # this is a comment
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