line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Script::Shebang; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1677
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
101
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
88
|
|
5
|
3
|
|
|
3
|
|
69
|
use 5.006_002; |
|
3
|
|
|
|
|
17
|
|
|
3
|
|
|
|
|
183
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
16
|
use File::Spec; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
72
|
|
9
|
3
|
|
|
3
|
|
15
|
use Test::Builder; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
216
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $tb = Test::Builder->new; |
12
|
|
|
|
|
|
|
my $ok = 1; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub import { |
15
|
3
|
|
|
3
|
|
15
|
my $self = shift; |
16
|
3
|
|
|
|
|
8
|
my $caller = caller; |
17
|
|
|
|
|
|
|
|
18
|
3
|
|
|
|
|
7
|
for my $func (qw/check_shebang check_shebang_from_dir/) { |
19
|
3
|
|
|
3
|
|
20
|
no strict 'refs'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1976
|
|
20
|
6
|
|
|
|
|
13
|
*{$caller."::".$func} = \&$func; |
|
6
|
|
|
|
|
33
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
|
|
14
|
$tb->exported_to($caller); |
24
|
3
|
|
|
|
|
27
|
$tb->plan(@_); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub check_shebang { |
28
|
5
|
|
|
5
|
1
|
2863
|
my @files = @_; |
29
|
|
|
|
|
|
|
|
30
|
5
|
|
|
|
|
12
|
for my $file (@files) { |
31
|
7
|
100
|
|
|
|
131
|
unless (-f $file) { |
32
|
1
|
|
|
|
|
5
|
$tb->ok(0, $file); |
33
|
1
|
|
|
|
|
543
|
$tb->diag("$file dose not exists"); |
34
|
1
|
|
|
|
|
73
|
next; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
6
|
50
|
|
|
|
218
|
open my $fh, '<', $file or die "$file: $!"; |
38
|
6
|
|
|
|
|
27
|
local $/ = "\n"; |
39
|
6
|
|
|
|
|
114
|
chomp(my $line = <$fh>); |
40
|
6
|
50
|
|
|
|
90
|
close $fh or die "$file: $!"; |
41
|
|
|
|
|
|
|
|
42
|
6
|
100
|
|
|
|
39
|
unless ($line =~ s/^\s*\#!\s*//) { |
43
|
2
|
|
|
|
|
10
|
$tb->ok(0, $file); |
44
|
2
|
|
|
|
|
1071
|
$tb->diag("Not a shebang file: $file"); |
45
|
2
|
|
|
|
|
147
|
next; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
4
|
|
|
|
|
17
|
my ($cmd, $arg) = split ' ', $line, 2; |
49
|
4
|
|
|
|
|
12
|
$cmd =~ s|^.*/||; |
50
|
4
|
100
|
|
|
|
17
|
unless ($cmd =~ m{^perl(?:\z|[^a-z])}) { |
51
|
2
|
|
|
|
|
11
|
$tb->ok(0, $file); |
52
|
2
|
|
|
|
|
1079
|
$tb->diag("$file is not perl script"); |
53
|
2
|
|
|
|
|
144
|
next; |
54
|
|
|
|
|
|
|
} |
55
|
2
|
|
|
|
|
13
|
$tb->ok(1, $file); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
5
|
|
|
|
|
563
|
return $ok; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub check_shebang_from_dir { |
62
|
2
|
|
|
2
|
1
|
1664
|
my @dirs = @_; |
63
|
|
|
|
|
|
|
|
64
|
2
|
|
|
|
|
8
|
for my $dir (sort @dirs) { |
65
|
2
|
100
|
|
|
|
130
|
unless (-d $dir) { |
66
|
1
|
|
|
|
|
6
|
$tb->ok(0, $dir); |
67
|
1
|
|
|
|
|
579
|
$tb->diag("$dir dose not exists"); |
68
|
1
|
|
|
|
|
65
|
next; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
1
|
50
|
|
|
|
55
|
opendir my $dh, $dir or die "$dir: $!"; |
72
|
1
|
|
|
|
|
31
|
my @files = map { File::Spec->catfile($dir, $_) } grep !/^\.{1,2}$/, sort readdir $dh; |
|
3
|
|
|
|
|
33
|
|
73
|
1
|
50
|
|
|
|
22
|
closedir $dh or die "$dir: $!"; |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
3
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
76
|
1
|
|
|
|
|
6
|
$tb->ok(check_shebang(@files), $dir); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
2
|
|
|
|
|
238
|
return $ok; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
__END__ |