Move Test::Harness from ext/ to cpan/
[p5sagit/p5-mst-13.2.git] / cpan / Test-Harness / t / streams.t
CommitLineData
b965d173 1#!/usr/bin/perl -wT
2
3use strict;
4use lib 't/lib';
5
6use Test::More tests => 47;
7
8use TAP::Parser;
f7c69158 9use TAP::Parser::IteratorFactory;
b965d173 10
f7c69158 11my $STREAMED = 'TAP::Parser';
12my $ITER = 'TAP::Parser::Iterator';
b965d173 13my $ITER_FH = "${ITER}::Stream";
14my $ITER_ARRAY = "${ITER}::Array";
15
f7c69158 16my $factory = TAP::Parser::IteratorFactory->new;
17my $stream = $factory->make_iterator( \*DATA );
b965d173 18isa_ok $stream, 'TAP::Parser::Iterator';
19my $parser = TAP::Parser->new( { stream => $stream } );
20isa_ok $parser, 'TAP::Parser',
21 '... and creating a streamed parser should succeed';
22
23can_ok $parser, '_stream';
24is ref $parser->_stream, $ITER_FH,
25 '... and it should return the proper iterator';
26can_ok $parser, 'next';
27is $parser->next->as_string, '1..5',
28 '... and the plan should parse correctly';
29is $parser->next->as_string, 'ok 1 - input file opened',
30 '... and the first test should parse correctly';
31is $parser->next->as_string, '... this is junk',
32 '... and junk should parse correctly';
33is $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';
36is $parser->next->as_string, '# this is a comment',
37 '... and comments should parse correctly';
38is $parser->next->as_string, 'ok 3 - read the rest of the file',
39 '... and the third test should parse correctly';
40is $parser->next->as_string, 'not ok 4 - this is a real failure',
41 '... and the fourth test should parse correctly';
42is $parser->next->as_string, 'ok 5 # SKIP we have no description',
43 '... and fifth test should parse correctly';
44
45ok !$parser->parse_errors, '... and we should have no parse errors';
46
47# plan at end
48
49my $tap = <<'END_TAP';
50ok 1 - input file opened
51... this is junk
52not ok first line of the input valid # todo some data
53# this is a comment
54ok 3 - read the rest of the file
55not ok 4 - this is a real failure
56ok 5 # skip we have no description
571..5
58END_TAP
59
f7c69158 60$stream = $factory->make_iterator( [ split /\n/ => $tap ] );
b965d173 61ok $parser = TAP::Parser->new( { stream => $stream } ),
62 'Now we create a parser with the plan at the end';
63isa_ok $parser->_stream, $ITER_ARRAY,
64 '... and now we should have an array iterator';
65is $parser->next->as_string, 'ok 1 - input file opened',
66 '... and the first test should parse correctly';
67is $parser->next->as_string, '... this is junk',
68 '... and junk should parse correctly';
69is $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';
72is $parser->next->as_string, '# this is a comment',
73 '... and comments should parse correctly';
74is $parser->next->as_string, 'ok 3 - read the rest of the file',
75 '... and the third test should parse correctly';
76is $parser->next->as_string, 'not ok 4 - this is a real failure',
77 '... and the fourth test should parse correctly';
78is $parser->next->as_string, 'ok 5 # SKIP we have no description',
79 '... and fifth test should parse correctly';
80is $parser->next->as_string, '1..5',
81 '... and the plan should parse correctly';
82
83ok !$parser->parse_errors, '... and we should have no parse errors';
84
85# misplaced plan (and one-off errors)
86
87$tap = <<'END_TAP';
88ok 1 - input file opened
891..5
90... this is junk
91not ok first line of the input valid # todo some data
92# this is a comment
93ok 3 - read the rest of the file
94not ok 4 - this is a real failure
95ok 5 # skip we have no description
96END_TAP
97
f7c69158 98$stream = $factory->make_iterator( [ split /\n/ => $tap ] );
b965d173 99
100ok $parser = TAP::Parser->new( { stream => $stream } ),
101 'Now we create a parser with a plan as the second line';
102is $parser->next->as_string, 'ok 1 - input file opened',
103 '... and the first test should parse correctly';
104is $parser->next->as_string, '1..5',
105 '... and the plan should parse correctly';
106is $parser->next->as_string, '... this is junk',
107 '... and junk should parse correctly';
108is $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';
111is $parser->next->as_string, '# this is a comment',
112 '... and comments should parse correctly';
113is $parser->next->as_string, 'ok 3 - read the rest of the file',
114 '... and the third test should parse correctly';
115is $parser->next->as_string, 'not ok 4 - this is a real failure',
116 '... and the fourth test should parse correctly';
117is $parser->next->as_string, 'ok 5 # SKIP we have no description',
118 '... and fifth test should parse correctly';
119
120ok $parser->parse_errors, '... and we should have one parse error';
121is + ( $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';
124
125$tap = <<'END_TAP';
126ok 1 - input file opened
127... this is junk
128not ok first line of the input valid # todo some data
129# this is a comment
130ok 3 - read the rest of the file
131not ok 4 - this is a real failure
1321..5
133ok 5 # skip we have no description
134END_TAP
135
f7c69158 136$stream = $factory->make_iterator( [ split /\n/ => $tap ] );
b965d173 137
138ok $parser = TAP::Parser->new( { stream => $stream } ),
139 'Now we create a parser with the plan as the second to last line';
140is $parser->next->as_string, 'ok 1 - input file opened',
141 '... and the first test should parse correctly';
142is $parser->next->as_string, '... this is junk',
143 '... and junk should parse correctly';
144is $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';
147is $parser->next->as_string, '# this is a comment',
148 '... and comments should parse correctly';
149is $parser->next->as_string, 'ok 3 - read the rest of the file',
150 '... and the third test should parse correctly';
151is $parser->next->as_string, 'not ok 4 - this is a real failure',
152 '... and the fourth test should parse correctly';
153is $parser->next->as_string, '1..5',
154 '... and the plan should parse correctly';
155is $parser->next->as_string, 'ok 5 # SKIP we have no description',
156 '... and fifth test should parse correctly';
157
158ok $parser->parse_errors, '... and we should have one parse error';
159is + ( $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';
162
163__DATA__
1641..5
165ok 1 - input file opened
166... this is junk
167not ok first line of the input valid # todo some data
168# this is a comment
169ok 3 - read the rest of the file
170not ok 4 - this is a real failure
171ok 5 # skip we have no description