Commit | Line | Data |
b965d173 |
1 | #!/usr/bin/perl -w |
2 | |
3 | use strict; |
4 | use lib 't/lib'; |
5 | |
6 | use Test::More qw( no_plan ); |
7 | |
8 | use File::Spec; |
9 | use TAP::Parser; |
10 | use TAP::Parser::Multiplexer; |
11 | use TAP::Parser::Iterator::Process; |
12 | |
13 | my $fork_desc |
14 | = TAP::Parser::Iterator::Process->_use_open3 |
15 | ? 'fork' |
16 | : 'nofork'; |
17 | |
18 | my @schedule = ( |
19 | { name => 'Single non-selectable source', |
20 | |
21 | # Returns a list of parser, stash pairs. The stash contains the |
22 | # TAP that we expect from this parser. |
23 | sources => sub { |
24 | my @tap = ( |
25 | '1..1', |
26 | 'ok 1 Just fine' |
27 | ); |
28 | |
29 | return [ |
30 | TAP::Parser->new( { tap => join( "\n", @tap ) . "\n" } ), |
31 | \@tap, |
32 | ]; |
33 | }, |
34 | }, |
35 | { name => 'Two non-selectable sources', |
36 | sources => sub { |
37 | my @tap = ( |
38 | [ '1..1', |
39 | 'ok 1 Just fine' |
40 | ], |
41 | [ '1..2', |
42 | 'not ok 1 Oh dear', |
43 | 'ok 2 Better' |
44 | ] |
45 | ); |
46 | |
47 | return map { |
48 | [ TAP::Parser->new( { tap => join( "\n", @$_ ) . "\n" } ), |
49 | $_ |
50 | ] |
51 | } @tap; |
52 | }, |
53 | }, |
54 | { name => 'Single selectable source', |
55 | sources => sub { |
56 | return [ |
57 | TAP::Parser->new( |
58 | { source => File::Spec->catfile( |
f7c69158 |
59 | ( $ENV{PERL_CORE} ? 'lib' : 't' ), 'sample-tests', |
60 | 'simple' |
b965d173 |
61 | ), |
62 | } |
63 | ), |
64 | [ '1..5', |
65 | 'ok 1', |
66 | 'ok 2', |
67 | 'ok 3', |
68 | 'ok 4', |
69 | 'ok 5', |
70 | ] |
71 | ]; |
72 | }, |
73 | }, |
74 | { name => 'Three selectable sources', |
75 | sources => sub { |
76 | return map { |
77 | [ TAP::Parser->new( |
78 | { source => File::Spec->catfile( |
f7c69158 |
79 | ( $ENV{PERL_CORE} ? 'lib' : 't' ), |
80 | 'sample-tests', 'simple' |
b965d173 |
81 | ), |
82 | } |
83 | ), |
84 | [ '1..5', |
85 | 'ok 1', |
86 | 'ok 2', |
87 | 'ok 3', |
88 | 'ok 4', |
89 | 'ok 5', |
90 | ] |
91 | ] |
92 | } 1 .. 3; |
93 | }, |
94 | }, |
95 | { name => 'Three selectable sources, two non-selectable sources', |
96 | sources => sub { |
97 | my @tap = ( |
98 | [ '1..1', |
99 | 'ok 1 Just fine' |
100 | ], |
101 | [ '1..2', |
102 | 'not ok 1 Oh dear', |
103 | 'ok 2 Better' |
104 | ] |
105 | ); |
106 | |
107 | return ( |
108 | map { |
109 | [ TAP::Parser->new( |
110 | { tap => join( "\n", @$_ ) . "\n" } |
111 | ), |
112 | $_ |
113 | ] |
114 | } @tap |
115 | ), |
116 | ( map { |
117 | [ TAP::Parser->new( |
118 | { source => File::Spec->catfile( |
f7c69158 |
119 | ( $ENV{PERL_CORE} ? 'lib' : 't' ), |
120 | 'sample-tests', 'simple' |
b965d173 |
121 | ), |
122 | } |
123 | ), |
124 | [ '1..5', |
125 | 'ok 1', |
126 | 'ok 2', |
127 | 'ok 3', |
128 | 'ok 4', |
129 | 'ok 5', |
130 | ] |
131 | ] |
132 | } 1 .. 3 |
133 | ); |
134 | }, |
135 | } |
136 | ); |
137 | |
138 | for my $test (@schedule) { |
139 | my $name = "$test->{name} ($fork_desc)"; |
140 | my @sources = $test->{sources}->(); |
141 | my $mux = TAP::Parser::Multiplexer->new; |
142 | |
143 | my $count = @sources; |
144 | $mux->add(@$_) for @sources; |
145 | |
146 | is $mux->parsers, $count, "$name: count OK"; |
147 | |
148 | while ( my ( $parser, $stash, $result ) = $mux->next ) { |
149 | |
150 | # use Data::Dumper; |
151 | # diag Dumper( { stash => $stash, result => $result } ); |
152 | if ( defined $result ) { |
153 | my $expect = ( shift @$stash ) || ' OOPS '; |
154 | my $got = $result->raw; |
155 | is $got, $expect, "$name: '$expect' OK"; |
156 | } |
157 | else { |
158 | ok @$stash == 0, "$name: EOF OK"; |
159 | |
160 | # Make sure we only get one EOF per stream |
161 | push @$stash, ' expect no more '; |
162 | } |
163 | } |
164 | is $mux->parsers, 0, "$name: All used up"; |
165 | } |
166 | |
167 | 1; |