6 use Test::More tests => 76;
10 use TAP::Parser::IteratorFactory;
15 my @lines = split /\n/ => $string;
19 # we slurp __DATA__ and then reset it so we don't have to duplicate our TAP
20 my $offset = tell DATA;
21 my $tap = do { local $/; <DATA> };
22 seek DATA, $offset, 0;
27 my $setup = sub { $did_setup++ };
28 my $teardown = sub { $did_teardown++ };
30 package NoForkProcess;
32 @ISA = qw( TAP::Parser::Iterator::Process );
34 sub _use_open3 {return}
40 subclass => 'TAP::Parser::Iterator::Process',
45 ( $ENV{PERL_CORE} ? 'lib' : 't' ),
46 'sample-tests', 'out_err_mix'
51 teardown => $teardown,
54 is $did_setup, 1, "setup called";
55 is $did_teardown, 1, "teardown called";
60 subclass => 'TAP::Parser::Iterator::Array',
61 source => array_ref_from($tap),
64 subclass => 'TAP::Parser::Iterator::Stream',
67 { name => 'Process (Perl -e)',
68 subclass => 'TAP::Parser::Iterator::Process',
70 { command => [ $^X, '-e', 'print qq/one\ntwo\n\nthree\n/' ] },
72 { name => 'Process (NoFork)',
73 subclass => 'TAP::Parser::Iterator::Process',
74 class => 'NoForkProcess',
76 { command => [ $^X, '-e', 'print qq/one\ntwo\n\nthree\n/' ] },
81 return $^O eq 'MSWin32' || $Config{d_fork};
84 my $factory = TAP::Parser::IteratorFactory->new;
85 for my $test (@schedule) {
87 my $name = $test->{name};
88 my $need_open3 = $test->{need_open3};
89 skip "No open3", $need_open3 if $need_open3 && !_can_open3();
90 my $subclass = $test->{subclass};
91 my $source = $test->{source};
92 my $class = $test->{class};
95 ? $class->new($source)
96 : $factory->make_iterator($source);
97 ok $iter, "$name: We should be able to create a new iterator";
98 isa_ok $iter, 'TAP::Parser::Iterator',
99 '... and the object it returns';
100 isa_ok $iter, $subclass, '... and the object it returns';
102 can_ok $iter, 'exit';
103 ok !defined $iter->exit,
104 "$name: ... and it should be undef before we are done ($subclass)";
106 can_ok $iter, 'next';
107 is $iter->next, 'one', "$name: next() should return the first result";
109 is $iter->next, 'two',
110 "$name: next() should return the second result";
112 is $iter->next, '', "$name: next() should return the third result";
114 is $iter->next, 'three',
115 "$name: next() should return the fourth result";
117 ok !defined $iter->next,
118 "$name: next() should return undef after it is empty";
121 "$name: ... and exit should now return 0 ($subclass)";
123 is $iter->wait, 0, "$name: wait should also now return 0 ($subclass)";
125 if ( my $after = $test->{after} ) {
133 # coverage tests for the ctor
135 my $stream = $factory->make_iterator( IO::Handle->new );
137 isa_ok $stream, 'TAP::Parser::Iterator::Stream';
142 local $SIG{__DIE__} = sub { push @die, @_ };
144 $factory->make_iterator( \1 ); # a ref to a scalar
147 is @die, 1, 'coverage of error case';
149 like pop @die, qr/Can't iterate with a SCALAR/,
150 '...and we died as expected';
155 # coverage test for VMS case
157 my $stream = $factory->make_iterator(
163 is $stream->next, 'not ok 1 - I hate VMS',
164 'coverage of VMS line-splitting case';
166 # coverage test for VMS case - nothing after 'not'
168 $stream = $factory->make_iterator(
173 is $stream->next, 'not ', '...and we find "not" by itself';
177 skip "No open3", 4 unless _can_open3();
179 # coverage testing for TAP::Parser::Iterator::Process ctor
184 local $SIG{__DIE__} = sub { push @die, @_ };
186 $factory->make_iterator( {} );
189 is @die, 1, 'coverage testing for TPI::Process';
191 like pop @die, qr/Must supply a command to execute/,
192 '...and we died as expected';
194 my $parser = $factory->make_iterator(
197 File::Spec->catfile( 't', 'sample-tests', 'out_err_mix' )
203 is $parser->{err}, '', 'confirm we set err to empty string';
204 is $parser->{sel}, undef, '...and selector to undef';
206 # And then we read from the parser to sidestep the Mac OS / open3
207 # bug which frequently throws an error here otherwise.