Upgrade to Test::Harness 3.05
[p5sagit/p5-mst-13.2.git] / lib / Test / Harness / t / source.t
1 #!/usr/bin/perl -w
2
3 BEGIN {
4     if ($ENV{PERL_CORE}) {
5         # FIXME
6         print "1..0 # Skip pending resolution of how to set the library with -I\n";
7         exit 0;
8     }
9 }
10
11 use strict;
12 use lib 't/lib';
13
14 use Test::More tests => 30;
15
16 use File::Spec;
17
18 use TAP::Parser::Source;
19 use TAP::Parser::Source::Perl;
20
21 my $test = File::Spec->catfile( $ENV{PERL_CORE} ? 'lib' : 't', 'source_tests',
22                                 'source' );
23
24 my $perl = $^X;
25
26 can_ok 'TAP::Parser::Source', 'new';
27 my $source = TAP::Parser::Source->new;
28 isa_ok $source, 'TAP::Parser::Source';
29
30 can_ok $source, 'source';
31 eval { $source->source("$perl -It/lib $test") };
32 ok my $error = $@, '... and calling it with a string should fail';
33 like $error, qr/^Argument to &source must be an array reference/,
34   '... with an appropriate error message';
35 ok $source->source( [ $perl, '-It/lib', '-T', $test ] ),
36   '... and calling it with valid args should succeed';
37
38 can_ok $source, 'get_stream';
39 my $stream = $source->get_stream;
40
41 isa_ok $stream, 'TAP::Parser::Iterator::Process',
42   'get_stream returns the right object';
43 can_ok $stream, 'next';
44 is $stream->next, '1..1', '... and the first line should be correct';
45 is $stream->next, 'ok 1', '... as should the second';
46 ok !$stream->next, '... and we should have no more results';
47
48 can_ok 'TAP::Parser::Source::Perl', 'new';
49 $source = TAP::Parser::Source::Perl->new;
50 isa_ok $source, 'TAP::Parser::Source::Perl', '... and the object it returns';
51
52 can_ok $source, 'source';
53 ok $source->source( [$test] ),
54   '... and calling it with valid args should succeed';
55
56 can_ok $source, 'get_stream';
57 $stream = $source->get_stream;
58
59 isa_ok $stream, 'TAP::Parser::Iterator::Process',
60   '... and the object it returns';
61 can_ok $stream, 'next';
62 is $stream->next, '1..1', '... and the first line should be correct';
63 is $stream->next, 'ok 1', '... as should the second';
64 ok !$stream->next, '... and we should have no more results';
65
66 # internals tests!
67
68 can_ok $source, '_switches';
69 ok( 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
79     my $source = TAP::Parser::Source->new();
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
94 {
95
96     # coverage testing for error
97
98     my $source = TAP::Parser::Source->new();
99
100     my $error = $source->error;
101
102     is $error, undef, 'coverage testing for error()';
103
104     $source->error('save me');
105
106     $error = $source->error;
107
108     is $error, 'save me', '...and we got the expected message';
109 }
110
111 {
112
113     # coverage testing for exit
114
115     my $source = TAP::Parser::Source->new();
116
117     my $exit = $source->exit;
118
119     is $exit, undef, 'coverage testing for exit()';
120
121     $source->exit('save me');
122
123     $exit = $source->exit;
124
125     is $exit, 'save me', '...and we got the expected message';
126 }