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