Upgrade to Test::Harness 3.14
[p5sagit/p5-mst-13.2.git] / ext / Test / Harness / t / source.t
CommitLineData
b965d173 1#!/usr/bin/perl -w
2
3BEGIN {
5e2a19fc 4 if ( $ENV{PERL_CORE} ) {
5 chdir 't';
6dcddb87 6 @INC = ( '../lib', '../ext/Test/Harness/t/lib' );
5e2a19fc 7 }
8 else {
9 unshift @INC, 't/lib';
b965d173 10 }
11}
12
13use strict;
b965d173 14
f7c69158 15use Test::More tests => 26;
b965d173 16
17use File::Spec;
18
f7c69158 19use EmptyParser;
b965d173 20use TAP::Parser::Source;
21use TAP::Parser::Source::Perl;
22
f7c69158 23my $parser = EmptyParser->new;
24my $test = File::Spec->catfile(
27fc0087 25 ( $ENV{PERL_CORE}
26 ? ( File::Spec->updir(), 'ext', 'Test', 'Harness' )
27 : ()
28 ),
29 't',
30 'source_tests',
31 'source'
5e2a19fc 32);
b965d173 33
34my $perl = $^X;
35
36can_ok 'TAP::Parser::Source', 'new';
37my $source = TAP::Parser::Source->new;
38isa_ok $source, 'TAP::Parser::Source';
39
40can_ok $source, 'source';
41eval { $source->source("$perl -It/lib $test") };
42ok my $error = $@, '... and calling it with a string should fail';
43like $error, qr/^Argument to &source must be an array reference/,
44 '... with an appropriate error message';
45ok $source->source( [ $perl, '-It/lib', '-T', $test ] ),
46 '... and calling it with valid args should succeed';
47
48can_ok $source, 'get_stream';
f7c69158 49my $stream = $source->get_stream($parser);
b965d173 50
51isa_ok $stream, 'TAP::Parser::Iterator::Process',
52 'get_stream returns the right object';
53can_ok $stream, 'next';
54is $stream->next, '1..1', '... and the first line should be correct';
55is $stream->next, 'ok 1', '... as should the second';
56ok !$stream->next, '... and we should have no more results';
57
58can_ok 'TAP::Parser::Source::Perl', 'new';
59$source = TAP::Parser::Source::Perl->new;
60isa_ok $source, 'TAP::Parser::Source::Perl', '... and the object it returns';
61
62can_ok $source, 'source';
63ok $source->source( [$test] ),
64 '... and calling it with valid args should succeed';
65
66can_ok $source, 'get_stream';
f7c69158 67$stream = $source->get_stream($parser);
b965d173 68
69isa_ok $stream, 'TAP::Parser::Iterator::Process',
70 '... and the object it returns';
71can_ok $stream, 'next';
72is $stream->next, '1..1', '... and the first line should be correct';
73is $stream->next, 'ok 1', '... as should the second';
74ok !$stream->next, '... and we should have no more results';
75
76# internals tests!
77
78can_ok $source, '_switches';
79ok( grep( $_ =~ /^['"]?-T['"]?$/, $source->_switches ),
80 '... and it should find the taint switch'
81);
82
83# coverage test for TAP::PArser::Source
84
85{
86
87 # coverage for method get_steam
88
f7c69158 89 my $source = TAP::Parser::Source->new( { parser => $parser } );
b965d173 90
91 my @die;
92
93 eval {
94 local $SIG{__DIE__} = sub { push @die, @_ };
95
96 $source->get_stream;
97 };
98
99 is @die, 1, 'coverage testing of get_stream';
100
101 like pop @die, qr/No command found!/, '...and it failed as expect';
102}
103