Move the modules, tests, prove and Changes file from lib/ to
[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';
6 @INC = ( '../lib', 'lib' );
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(
5e2a19fc 25 ( $ENV{PERL_CORE} ? 'lib' : 't' ), 'source_tests',
26 'source'
27);
b965d173 28
29my $perl = $^X;
30
31can_ok 'TAP::Parser::Source', 'new';
32my $source = TAP::Parser::Source->new;
33isa_ok $source, 'TAP::Parser::Source';
34
35can_ok $source, 'source';
36eval { $source->source("$perl -It/lib $test") };
37ok my $error = $@, '... and calling it with a string should fail';
38like $error, qr/^Argument to &source must be an array reference/,
39 '... with an appropriate error message';
40ok $source->source( [ $perl, '-It/lib', '-T', $test ] ),
41 '... and calling it with valid args should succeed';
42
43can_ok $source, 'get_stream';
f7c69158 44my $stream = $source->get_stream($parser);
b965d173 45
46isa_ok $stream, 'TAP::Parser::Iterator::Process',
47 'get_stream returns the right object';
48can_ok $stream, 'next';
49is $stream->next, '1..1', '... and the first line should be correct';
50is $stream->next, 'ok 1', '... as should the second';
51ok !$stream->next, '... and we should have no more results';
52
53can_ok 'TAP::Parser::Source::Perl', 'new';
54$source = TAP::Parser::Source::Perl->new;
55isa_ok $source, 'TAP::Parser::Source::Perl', '... and the object it returns';
56
57can_ok $source, 'source';
58ok $source->source( [$test] ),
59 '... and calling it with valid args should succeed';
60
61can_ok $source, 'get_stream';
f7c69158 62$stream = $source->get_stream($parser);
b965d173 63
64isa_ok $stream, 'TAP::Parser::Iterator::Process',
65 '... and the object it returns';
66can_ok $stream, 'next';
67is $stream->next, '1..1', '... and the first line should be correct';
68is $stream->next, 'ok 1', '... as should the second';
69ok !$stream->next, '... and we should have no more results';
70
71# internals tests!
72
73can_ok $source, '_switches';
74ok( grep( $_ =~ /^['"]?-T['"]?$/, $source->_switches ),
75 '... and it should find the taint switch'
76);
77
78# coverage test for TAP::PArser::Source
79
80{
81
82 # coverage for method get_steam
83
f7c69158 84 my $source = TAP::Parser::Source->new( { parser => $parser } );
b965d173 85
86 my @die;
87
88 eval {
89 local $SIG{__DIE__} = sub { push @die, @_ };
90
91 $source->get_stream;
92 };
93
94 is @die, 1, 'coverage testing of get_stream';
95
96 like pop @die, qr/No command found!/, '...and it failed as expect';
97}
98