4 if ( $ENV{PERL_CORE} ) {
6 @INC = ( '../lib', 'lib' );
15 use Test::More tests => 30;
19 use TAP::Parser::Source;
20 use TAP::Parser::Source::Perl;
22 my $test = File::Spec->catfile(
23 ( $ENV{PERL_CORE} ? 'lib' : 't' ), 'source_tests',
29 can_ok 'TAP::Parser::Source', 'new';
30 my $source = TAP::Parser::Source->new;
31 isa_ok $source, 'TAP::Parser::Source';
33 can_ok $source, 'source';
34 eval { $source->source("$perl -It/lib $test") };
35 ok my $error = $@, '... and calling it with a string should fail';
36 like $error, qr/^Argument to &source must be an array reference/,
37 '... with an appropriate error message';
38 ok $source->source( [ $perl, '-It/lib', '-T', $test ] ),
39 '... and calling it with valid args should succeed';
41 can_ok $source, 'get_stream';
42 my $stream = $source->get_stream;
44 isa_ok $stream, 'TAP::Parser::Iterator::Process',
45 'get_stream returns the right object';
46 can_ok $stream, 'next';
47 is $stream->next, '1..1', '... and the first line should be correct';
48 is $stream->next, 'ok 1', '... as should the second';
49 ok !$stream->next, '... and we should have no more results';
51 can_ok 'TAP::Parser::Source::Perl', 'new';
52 $source = TAP::Parser::Source::Perl->new;
53 isa_ok $source, 'TAP::Parser::Source::Perl', '... and the object it returns';
55 can_ok $source, 'source';
56 ok $source->source( [$test] ),
57 '... and calling it with valid args should succeed';
59 can_ok $source, 'get_stream';
60 $stream = $source->get_stream;
62 isa_ok $stream, 'TAP::Parser::Iterator::Process',
63 '... and the object it returns';
64 can_ok $stream, 'next';
65 is $stream->next, '1..1', '... and the first line should be correct';
66 is $stream->next, 'ok 1', '... as should the second';
67 ok !$stream->next, '... and we should have no more results';
71 can_ok $source, '_switches';
72 ok( grep( $_ =~ /^['"]?-T['"]?$/, $source->_switches ),
73 '... and it should find the taint switch'
76 # coverage test for TAP::PArser::Source
80 # coverage for method get_steam
82 my $source = TAP::Parser::Source->new();
87 local $SIG{__DIE__} = sub { push @die, @_ };
92 is @die, 1, 'coverage testing of get_stream';
94 like pop @die, qr/No command found!/, '...and it failed as expect';
99 # coverage testing for error
101 my $source = TAP::Parser::Source->new();
103 my $error = $source->error;
105 is $error, undef, 'coverage testing for error()';
107 $source->error('save me');
109 $error = $source->error;
111 is $error, 'save me', '...and we got the expected message';
116 # coverage testing for exit
118 my $source = TAP::Parser::Source->new();
120 my $exit = $source->exit;
122 is $exit, undef, 'coverage testing for exit()';
124 $source->exit('save me');
126 $exit = $source->exit;
128 is $exit, 'save me', '...and we got the expected message';