xref: /openbsd-src/gnu/usr.bin/perl/cpan/Test-Harness/t/streams.t (revision 6fb12b7054efc6b436584db6cef9c2f85c0d7e27)
1#!/usr/bin/perl -wT
2
3use strict;
4use warnings;
5use lib 't/lib';
6
7use Test::More tests => 49;
8
9use TAP::Parser;
10use TAP::Parser::Iterator::Array;
11use TAP::Parser::Iterator::Stream;
12
13my $ITER       = 'TAP::Parser::Iterator';
14my $ITER_FH    = "${ITER}::Stream";
15my $ITER_ARRAY = "${ITER}::Array";
16
17my $iterator = $ITER_FH->new( \*DATA );
18isa_ok $iterator, 'TAP::Parser::Iterator';
19my $parser = TAP::Parser->new( { iterator => $iterator } );
20isa_ok $parser, 'TAP::Parser',
21  '... and creating a streamed parser should succeed';
22
23can_ok $parser, '_iterator';
24is ref $parser->_iterator, $ITER_FH,
25  '... and it should return the proper iterator';
26can_ok $parser, '_stream';    # deprecated
27is $parser->_stream, $parser->_iterator, '... _stream (deprecated)';
28
29can_ok $parser, 'next';
30is $parser->next->as_string, '1..5',
31  '... and the plan should parse correctly';
32is $parser->next->as_string, 'ok 1 - input file opened',
33  '... and the first test should parse correctly';
34is $parser->next->as_string, '... this is junk',
35  '... and junk should parse correctly';
36is $parser->next->as_string,
37  'not ok 2 first line of the input valid # TODO some data',
38  '... and the second test should parse correctly';
39is $parser->next->as_string, '# this is a comment',
40  '... and comments should parse correctly';
41is $parser->next->as_string, 'ok 3 - read the rest of the file',
42  '... and the third test should parse correctly';
43is $parser->next->as_string, 'not ok 4 - this is a real failure',
44  '... and the fourth test should parse correctly';
45is $parser->next->as_string, 'ok 5 # SKIP we have no description',
46  '... and fifth test should parse correctly';
47
48ok !$parser->parse_errors, '... and we should have no parse errors';
49
50# plan at end
51
52my $tap = <<'END_TAP';
53ok 1 - input file opened
54... this is junk
55not ok first line of the input valid # todo some data
56# this is a comment
57ok 3 - read the rest of the file
58not ok 4 - this is a real failure
59ok 5 # skip we have no description
601..5
61END_TAP
62
63$iterator = $ITER_ARRAY->new( [ split /\n/ => $tap ] );
64ok $parser = TAP::Parser->new( { iterator => $iterator } ),
65  'Now we create a parser with the plan at the end';
66isa_ok $parser->_iterator, $ITER_ARRAY,
67  '... and now we should have an array iterator';
68is $parser->next->as_string, 'ok 1 - input file opened',
69  '... and the first test should parse correctly';
70is $parser->next->as_string, '... this is junk',
71  '... and junk should parse correctly';
72is $parser->next->as_string,
73  'not ok 2 first line of the input valid # TODO some data',
74  '... and the second test should parse correctly';
75is $parser->next->as_string, '# this is a comment',
76  '... and comments should parse correctly';
77is $parser->next->as_string, 'ok 3 - read the rest of the file',
78  '... and the third test should parse correctly';
79is $parser->next->as_string, 'not ok 4 - this is a real failure',
80  '... and the fourth test should parse correctly';
81is $parser->next->as_string, 'ok 5 # SKIP we have no description',
82  '... and fifth test should parse correctly';
83is $parser->next->as_string, '1..5',
84  '... and the plan should parse correctly';
85
86ok !$parser->parse_errors, '... and we should have no parse errors';
87
88# misplaced plan (and one-off errors)
89
90$tap = <<'END_TAP';
91ok 1 - input file opened
921..5
93... this is junk
94not ok first line of the input valid # todo some data
95# this is a comment
96ok 3 - read the rest of the file
97not ok 4 - this is a real failure
98ok 5 # skip we have no description
99END_TAP
100
101$iterator = $ITER_ARRAY->new( [ split /\n/ => $tap ] );
102
103ok $parser = TAP::Parser->new( { iterator => $iterator } ),
104  'Now we create a parser with a plan as the second line';
105is $parser->next->as_string, 'ok 1 - input file opened',
106  '... and the first test should parse correctly';
107is $parser->next->as_string, '1..5',
108  '... and the plan should parse correctly';
109is $parser->next->as_string, '... this is junk',
110  '... and junk should parse correctly';
111is $parser->next->as_string,
112  'not ok 2 first line of the input valid # TODO some data',
113  '... and the second test should parse correctly';
114is $parser->next->as_string, '# this is a comment',
115  '... and comments should parse correctly';
116is $parser->next->as_string, 'ok 3 - read the rest of the file',
117  '... and the third test should parse correctly';
118is $parser->next->as_string, 'not ok 4 - this is a real failure',
119  '... and the fourth test should parse correctly';
120is $parser->next->as_string, 'ok 5 # SKIP we have no description',
121  '... and fifth test should parse correctly';
122
123ok $parser->parse_errors, '... and we should have one parse error';
124is + ( $parser->parse_errors )[0],
125  'Plan (1..5) must be at the beginning or end of the TAP output',
126  '... telling us that our plan went awry';
127
128$tap = <<'END_TAP';
129ok 1 - input file opened
130... this is junk
131not ok first line of the input valid # todo some data
132# this is a comment
133ok 3 - read the rest of the file
134not ok 4 - this is a real failure
1351..5
136ok 5 # skip we have no description
137END_TAP
138
139$iterator = $ITER_ARRAY->new( [ split /\n/ => $tap ] );
140
141ok $parser = TAP::Parser->new( { iterator => $iterator } ),
142  'Now we create a parser with the plan as the second to last line';
143is $parser->next->as_string, 'ok 1 - input file opened',
144  '... and the first test should parse correctly';
145is $parser->next->as_string, '... this is junk',
146  '... and junk should parse correctly';
147is $parser->next->as_string,
148  'not ok 2 first line of the input valid # TODO some data',
149  '... and the second test should parse correctly';
150is $parser->next->as_string, '# this is a comment',
151  '... and comments should parse correctly';
152is $parser->next->as_string, 'ok 3 - read the rest of the file',
153  '... and the third test should parse correctly';
154is $parser->next->as_string, 'not ok 4 - this is a real failure',
155  '... and the fourth test should parse correctly';
156is $parser->next->as_string, '1..5',
157  '... and the plan should parse correctly';
158is $parser->next->as_string, 'ok 5 # SKIP we have no description',
159  '... and fifth test should parse correctly';
160
161ok $parser->parse_errors, '... and we should have one parse error';
162is + ( $parser->parse_errors )[0],
163  'Plan (1..5) must be at the beginning or end of the TAP output',
164  '... telling us that our plan went awry';
165
166__DATA__
1671..5
168ok 1 - input file opened
169... this is junk
170not ok first line of the input valid # todo some data
171# this is a comment
172ok 3 - read the rest of the file
173not ok 4 - this is a real failure
174ok 5 # skip we have no description
175