Debian lenny version packages
[pkg-perl] / deb-src / libtest-harness-perl / libtest-harness-perl-3.12 / 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::IteratorFactory;
10
11 my $STREAMED   = 'TAP::Parser';
12 my $ITER       = 'TAP::Parser::Iterator';
13 my $ITER_FH    = "${ITER}::Stream";
14 my $ITER_ARRAY = "${ITER}::Array";
15
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';
22
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';
44
45 ok !$parser->parse_errors, '... and we should have no parse errors';
46
47 # plan at end
48
49 my $tap = <<'END_TAP';
50 ok 1 - input file opened
51 ... this is junk
52 not ok first line of the input valid # todo some data
53 # this is a comment
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
57 1..5
58 END_TAP
59
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';
82
83 ok !$parser->parse_errors, '... and we should have no parse errors';
84
85 # misplaced plan (and one-off errors)
86
87 $tap = <<'END_TAP';
88 ok 1 - input file opened
89 1..5
90 ... this is junk
91 not ok first line of the input valid # todo some data
92 # this is a comment
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
96 END_TAP
97
98 $stream = $factory->make_iterator( [ split /\n/ => $tap ] );
99
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';
119
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';
124
125 $tap = <<'END_TAP';
126 ok 1 - input file opened
127 ... this is junk
128 not ok first line of the input valid # todo some data
129 # this is a comment
130 ok 3 - read the rest of the file
131 not ok 4 - this is a real failure
132 1..5
133 ok 5 # skip we have no description
134 END_TAP
135
136 $stream = $factory->make_iterator( [ split /\n/ => $tap ] );
137
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';
157
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';
162
163 __DATA__
164 1..5
165 ok 1 - input file opened
166 ... this is junk
167 not ok first line of the input valid # todo some data
168 # this is a comment
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