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