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