4 if ( $ENV{PERL_CORE} ) {
6 @INC = ( '../lib', 'lib' );
15 use Test::More tests => 26;
20 use TAP::Parser::Source;
21 use TAP::Parser::Source::Perl;
23 my $parser = EmptyParser->new;
24 my $test = File::Spec->catfile(
25 ( $ENV{PERL_CORE} ? 'lib' : 't' ), 'source_tests',
31 can_ok 'TAP::Parser::Source', 'new';
32 my $source = TAP::Parser::Source->new;
33 isa_ok $source, 'TAP::Parser::Source';
35 can_ok $source, 'source';
36 eval { $source->source("$perl -It/lib $test") };
37 ok my $error = $@, '... and calling it with a string should fail';
38 like $error, qr/^Argument to &source must be an array reference/,
39 '... with an appropriate error message';
40 ok $source->source( [ $perl, '-It/lib', '-T', $test ] ),
41 '... and calling it with valid args should succeed';
43 can_ok $source, 'get_stream';
44 my $stream = $source->get_stream($parser);
46 isa_ok $stream, 'TAP::Parser::Iterator::Process',
47 'get_stream returns the right object';
48 can_ok $stream, 'next';
49 is $stream->next, '1..1', '... and the first line should be correct';
50 is $stream->next, 'ok 1', '... as should the second';
51 ok !$stream->next, '... and we should have no more results';
53 can_ok 'TAP::Parser::Source::Perl', 'new';
54 $source = TAP::Parser::Source::Perl->new;
55 isa_ok $source, 'TAP::Parser::Source::Perl', '... and the object it returns';
57 can_ok $source, 'source';
58 ok $source->source( [$test] ),
59 '... and calling it with valid args should succeed';
61 can_ok $source, 'get_stream';
62 $stream = $source->get_stream($parser);
64 isa_ok $stream, 'TAP::Parser::Iterator::Process',
65 '... and the object it returns';
66 can_ok $stream, 'next';
67 is $stream->next, '1..1', '... and the first line should be correct';
68 is $stream->next, 'ok 1', '... as should the second';
69 ok !$stream->next, '... and we should have no more results';
73 can_ok $source, '_switches';
74 ok( grep( $_ =~ /^['"]?-T['"]?$/, $source->_switches ),
75 '... and it should find the taint switch'
78 # coverage test for TAP::PArser::Source
82 # coverage for method get_steam
84 my $source = TAP::Parser::Source->new( { parser => $parser } );
89 local $SIG{__DIE__} = sub { push @die, @_ };
94 is @die, 1, 'coverage testing of get_stream';
96 like pop @die, qr/No command found!/, '...and it failed as expect';