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',
52 teardown => $teardown,
55 is $did_setup, 1, "setup called";
56 is $did_teardown, 1, "teardown called";
61 subclass => 'TAP::Parser::Iterator::Array',
62 source => array_ref_from($tap),
65 subclass => 'TAP::Parser::Iterator::Stream',
68 { name => 'Process (Perl -e)',
69 subclass => 'TAP::Parser::Iterator::Process',
71 { command => [ $^X, '-e', 'print qq/one\ntwo\n\nthree\n/' ] },
73 { name => 'Process (NoFork)',
74 subclass => 'TAP::Parser::Iterator::Process',
75 class => 'NoForkProcess',
77 { command => [ $^X, '-e', 'print qq/one\ntwo\n\nthree\n/' ] },
82 return $Config{d_fork};
85 my $factory = TAP::Parser::IteratorFactory->new;
86 for my $test (@schedule) {
88 my $name = $test->{name};
89 my $need_open3 = $test->{need_open3};
90 skip "No open3", $need_open3 if $need_open3 && !_can_open3();
91 my $subclass = $test->{subclass};
92 my $source = $test->{source};
93 my $class = $test->{class};
96 ? $class->new($source)
97 : $factory->make_iterator($source);
98 ok $iter, "$name: We should be able to create a new iterator";
99 isa_ok $iter, 'TAP::Parser::Iterator',
100 '... and the object it returns';
101 isa_ok $iter, $subclass, '... and the object it returns';
103 can_ok $iter, 'exit';
104 ok !defined $iter->exit,
105 "$name: ... and it should be undef before we are done ($subclass)";
107 can_ok $iter, 'next';
108 is $iter->next, 'one', "$name: next() should return the first result";
110 is $iter->next, 'two',
111 "$name: next() should return the second result";
113 is $iter->next, '', "$name: next() should return the third result";
115 is $iter->next, 'three',
116 "$name: next() should return the fourth result";
118 ok !defined $iter->next,
119 "$name: next() should return undef after it is empty";
122 "$name: ... and exit should now return 0 ($subclass)";
124 is $iter->wait, 0, "$name: wait should also now return 0 ($subclass)";
126 if ( my $after = $test->{after} ) {
134 # coverage tests for the ctor
136 my $stream = $factory->make_iterator( IO::Handle->new );
138 isa_ok $stream, 'TAP::Parser::Iterator::Stream';
143 local $SIG{__DIE__} = sub { push @die, @_ };
145 $factory->make_iterator( \1 ); # a ref to a scalar
148 is @die, 1, 'coverage of error case';
150 like pop @die, qr/Can't iterate with a SCALAR/,
151 '...and we died as expected';
156 # coverage test for VMS case
158 my $stream = $factory->make_iterator(
164 is $stream->next, 'not ok 1 - I hate VMS',
165 'coverage of VMS line-splitting case';
167 # coverage test for VMS case - nothing after 'not'
169 $stream = $factory->make_iterator(
174 is $stream->next, 'not ', '...and we find "not" by itself';
178 skip "No open3", 4 unless _can_open3();
180 # coverage testing for TAP::Parser::Iterator::Process ctor
185 local $SIG{__DIE__} = sub { push @die, @_ };
187 $factory->make_iterator( {} );
190 is @die, 1, 'coverage testing for TPI::Process';
192 like pop @die, qr/Must supply a command to execute/,
193 '...and we died as expected';
195 my $parser = $factory->make_iterator(
198 File::Spec->catfile( 't', 'sample-tests', 'out_err_mix' )
204 is $parser->{err}, '', 'confirm we set err to empty string';
205 is $parser->{sel}, undef, '...and selector to undef';
207 # And then we read from the parser to sidestep the Mac OS / open3
208 # bug which frequently throws an error here otherwise.