| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Test::Syntax::Aggregate; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
38310
|
use 5.008; |
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
60
|
|
|
4
|
2
|
|
|
2
|
|
9
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
52
|
|
|
5
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
58
|
|
|
6
|
2
|
|
|
2
|
|
1381
|
use parent qw(Test::Builder::Module Exporter); |
|
|
2
|
|
|
|
|
558
|
|
|
|
2
|
|
|
|
|
10
|
|
|
7
|
2
|
|
|
2
|
|
1571
|
use IPC::Open2; |
|
|
2
|
|
|
|
|
9802
|
|
|
|
2
|
|
|
|
|
828
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT = ('check_scripts_syntax'); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Test::Syntax::Aggregate - Check syntax of multiple scripts |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
This module allows you to check syntax of multiple scripts using the same common module. |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Test::Syntax::Aggregate; |
|
22
|
|
|
|
|
|
|
check_scripts_syntax( |
|
23
|
|
|
|
|
|
|
preload => [ @modules ], |
|
24
|
|
|
|
|
|
|
scripts => [ @scripts ], |
|
25
|
|
|
|
|
|
|
); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Suppose you have a lot of cgi scripts that use the same set of preloaded |
|
30
|
|
|
|
|
|
|
modules. If you running syntax check on these scripts it may take a lot of time |
|
31
|
|
|
|
|
|
|
mostly because of loading perl and common modules for every single script. This |
|
32
|
|
|
|
|
|
|
module borrows idea and some code from L and |
|
33
|
|
|
|
|
|
|
L. It preloads specified modules first, and when compiles |
|
34
|
|
|
|
|
|
|
scripts wrapping them into functions. |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 SUBROUTINES |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 check_scripts_syntax(%parameters) |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Runs syntax checks for all specified files. Accepts following parameters: |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=over 4 |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=item preload |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Reference to array with list of modules that must be preloaded before testing. |
|
47
|
|
|
|
|
|
|
Preloading modules allows you significantly speedup testing. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item scripts |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Reference to array containing list of scripts to check syntax. |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item libs |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
List of directories to look for modules files. Defaults to I<@INC>. |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item hide_warnings |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Hide any warnings produced by scripts during checks unless check failed. |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=back |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub check_scripts_syntax { |
|
66
|
0
|
|
|
0
|
1
|
|
my %params = @_; |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
my @libs = $params{libs} ? @{ $params{libs} } : @INC; |
|
|
0
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
my @modules = $params{preload} ? @{ $params{preload} } : (); |
|
|
0
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
push @modules, "Test::Syntax::Aggregate::Checker"; |
|
71
|
0
|
|
|
|
|
|
my @scripts = @{ $params{scripts} }; |
|
|
0
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
my $hide_warnings = $params{hide_warnings} ? 1 : 0; |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
my $subtest = __PACKAGE__->builder->child( $params{name} ? $params{name} : "Scripts syntax" ); |
|
75
|
0
|
|
|
|
|
|
$subtest->plan( tests => 0 + @scripts ); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# This child will actually check scripts |
|
78
|
0
|
|
|
|
|
|
my ( $wrfd, $rdfd ); |
|
79
|
0
|
|
|
|
|
|
my $pid = open2( $rdfd, $wrfd, $^X, (map { "-I$_" } @libs), (map { "-M$_" } @modules), "-e", "Test::Syntax::Aggregate::Checker->run(hide_warnings => $hide_warnings)" ); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$wrfd->autoflush; |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
for (@scripts) { |
|
83
|
0
|
0
|
|
|
|
|
if ( -r $_ ) { |
|
84
|
0
|
|
|
|
|
|
print $wrfd "$_\n"; |
|
85
|
0
|
|
|
|
|
|
chomp( my $result = <$rdfd> ); |
|
86
|
0
|
0
|
|
|
|
|
if ( $result =~ /^ok/ ) { |
|
|
|
0
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$subtest->ok( 1, $_ ); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
elsif ( $result =~ /^not ok/ ) { |
|
90
|
0
|
|
|
|
|
|
$subtest->ok( 0, $_ ); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
else { |
|
93
|
0
|
|
|
|
|
|
die "Got invalid response from checker process: $result"; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
else { |
|
97
|
0
|
|
|
|
|
|
warn "Can't read $_\n"; |
|
98
|
0
|
|
|
|
|
|
$subtest->ok( 0, $_ ); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
} |
|
101
|
0
|
|
|
|
|
|
close $wrfd; |
|
102
|
0
|
|
|
|
|
|
waitpid $pid, 0; |
|
103
|
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
return $subtest->finalize; |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |