line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TAP::Parser::SourceHandler::Executable; |
2
|
|
|
|
|
|
|
|
3
|
38
|
|
|
38
|
|
3224
|
use strict; |
|
38
|
|
|
|
|
108
|
|
|
38
|
|
|
|
|
1248
|
|
4
|
38
|
|
|
38
|
|
311
|
use warnings; |
|
38
|
|
|
|
|
116
|
|
|
38
|
|
|
|
|
1314
|
|
5
|
|
|
|
|
|
|
|
6
|
38
|
|
|
38
|
|
620
|
use TAP::Parser::IteratorFactory (); |
|
38
|
|
|
|
|
104
|
|
|
38
|
|
|
|
|
697
|
|
7
|
38
|
|
|
38
|
|
12733
|
use TAP::Parser::Iterator::Process (); |
|
38
|
|
|
|
|
134
|
|
|
38
|
|
|
|
|
1182
|
|
8
|
|
|
|
|
|
|
|
9
|
38
|
|
|
38
|
|
295
|
use base 'TAP::Parser::SourceHandler'; |
|
38
|
|
|
|
|
133
|
|
|
38
|
|
|
|
|
19269
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
TAP::Parser::IteratorFactory->register_handler(__PACKAGE__); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
TAP::Parser::SourceHandler::Executable - Stream output from an executable TAP source |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Version 3.40_01 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '3.40_01'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use TAP::Parser::Source; |
28
|
|
|
|
|
|
|
use TAP::Parser::SourceHandler::Executable; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $source = TAP::Parser::Source->new->raw(['/usr/bin/ruby', 'mytest.rb']); |
31
|
|
|
|
|
|
|
$source->assemble_meta; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $class = 'TAP::Parser::SourceHandler::Executable'; |
34
|
|
|
|
|
|
|
my $vote = $class->can_handle( $source ); |
35
|
|
|
|
|
|
|
my $iter = $class->make_iterator( $source ); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This is an I L - it has 2 jobs: |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1. Figure out if the L it's given is an executable |
42
|
|
|
|
|
|
|
command (L). |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
2. Creates an iterator for executable commands (L). |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Unless you're writing a plugin or subclassing L, you |
47
|
|
|
|
|
|
|
probably won't need to use this module directly. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 METHODS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 Class Methods |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head3 C |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $vote = $class->can_handle( $source ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Only votes if $source looks like an executable file. Casts the |
58
|
|
|
|
|
|
|
following votes: |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
0.9 if it's a hash with an 'exec' key |
61
|
|
|
|
|
|
|
0.8 if it's a .bat file |
62
|
|
|
|
|
|
|
0.75 if it's got an execute bit set |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub can_handle { |
67
|
310
|
|
|
310
|
1
|
1216
|
my ( $class, $src ) = @_; |
68
|
310
|
|
|
|
|
1316
|
my $meta = $src->meta; |
69
|
|
|
|
|
|
|
|
70
|
310
|
100
|
|
|
|
1407
|
if ( $meta->{is_file} ) { |
|
|
100
|
|
|
|
|
|
71
|
224
|
|
|
|
|
2892
|
my $file = $meta->{file}; |
72
|
|
|
|
|
|
|
|
73
|
224
|
50
|
66
|
|
|
1236
|
return 0.85 if $file->{execute} && $file->{binary}; |
74
|
224
|
100
|
|
|
|
1367
|
return 0.8 if $file->{lc_ext} eq '.bat'; |
75
|
222
|
100
|
|
|
|
884
|
return 0.25 if $file->{execute}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
elsif ( $meta->{is_hash} ) { |
78
|
12
|
50
|
|
|
|
50
|
return 0.9 if $src->raw->{exec}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
292
|
|
|
|
|
1419
|
return 0; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head3 C |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $iterator = $class->make_iterator( $source ); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Returns a new L for the source. |
89
|
|
|
|
|
|
|
C<$source-Eraw> must be in one of the following forms: |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
{ exec => [ @exec ] } |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
[ @exec ] |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$file |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Cs on error. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub make_iterator { |
102
|
15
|
|
|
15
|
1
|
119
|
my ( $class, $source ) = @_; |
103
|
15
|
|
|
|
|
64
|
my $meta = $source->meta; |
104
|
|
|
|
|
|
|
|
105
|
15
|
|
|
|
|
65
|
my @command; |
106
|
15
|
100
|
|
|
|
84
|
if ( $meta->{is_hash} ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
107
|
11
|
50
|
|
|
|
38
|
@command = @{ $source->raw->{exec} || [] }; |
|
11
|
|
|
|
|
50
|
|
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
elsif ( $meta->{is_scalar} ) { |
110
|
1
|
|
|
|
|
4
|
@command = ${ $source->raw }; |
|
1
|
|
|
|
|
7
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
elsif ( $meta->{is_array} ) { |
113
|
1
|
|
|
|
|
2
|
@command = @{ $source->raw }; |
|
1
|
|
|
|
|
3
|
|
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
15
|
100
|
|
|
|
78
|
$class->_croak('No command found in $source->raw!') unless @command; |
117
|
|
|
|
|
|
|
|
118
|
13
|
|
|
|
|
116
|
$class->_autoflush( \*STDOUT ); |
119
|
13
|
|
|
|
|
72
|
$class->_autoflush( \*STDERR ); |
120
|
|
|
|
|
|
|
|
121
|
13
|
100
|
|
|
|
39
|
push @command, @{ $source->test_args || [] }; |
|
13
|
|
|
|
|
65
|
|
122
|
|
|
|
|
|
|
|
123
|
13
|
|
|
|
|
124
|
return $class->iterator_class->new( |
124
|
|
|
|
|
|
|
{ command => \@command, |
125
|
|
|
|
|
|
|
merge => $source->merge |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head3 C |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
The class of iterator to use, override if you're sub-classing. Defaults |
133
|
|
|
|
|
|
|
to L. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
38
|
|
|
38
|
|
317
|
use constant iterator_class => 'TAP::Parser::Iterator::Process'; |
|
38
|
|
|
|
|
102
|
|
|
38
|
|
|
|
|
5651
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# Turns on autoflush for the handle passed |
140
|
|
|
|
|
|
|
sub _autoflush { |
141
|
450
|
|
|
450
|
|
1380
|
my ( $class, $flushed ) = @_; |
142
|
450
|
|
|
|
|
2022
|
my $old_fh = select $flushed; |
143
|
450
|
|
|
|
|
1442
|
$| = 1; |
144
|
450
|
|
|
|
|
2326
|
select $old_fh; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 SUBCLASSING |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Please see L for a subclassing overview. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 Example |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
package MyRubySourceHandler; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
use strict; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
use Carp qw( croak ); |
160
|
|
|
|
|
|
|
use TAP::Parser::SourceHandler::Executable; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
use base 'TAP::Parser::SourceHandler::Executable'; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# expect $handler->(['mytest.rb', 'cmdline', 'args']); |
165
|
|
|
|
|
|
|
sub make_iterator { |
166
|
|
|
|
|
|
|
my ($self, $source) = @_; |
167
|
|
|
|
|
|
|
my @test_args = @{ $source->test_args }; |
168
|
|
|
|
|
|
|
my $rb_file = $test_args[0]; |
169
|
|
|
|
|
|
|
croak("error: Ruby file '$rb_file' not found!") unless (-f $rb_file); |
170
|
|
|
|
|
|
|
return $self->SUPER::raw_source(['/usr/bin/ruby', @test_args]); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 SEE ALSO |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
L, |
176
|
|
|
|
|
|
|
L, |
177
|
|
|
|
|
|
|
L, |
178
|
|
|
|
|
|
|
L, |
179
|
|
|
|
|
|
|
L, |
180
|
|
|
|
|
|
|
L, |
181
|
|
|
|
|
|
|
L, |
182
|
|
|
|
|
|
|
L |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |