lib/Apache/TestMM.pm

filter: Statementstmt 30.1% 22 / 73 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 53.8% 7 / 13 Podpod 40.0% 2 / 5 totaltotal 27.1% 31 / 114 CC 12 SCAR 28.0
CC
12
Cov
23%
test
42.0
generate_script
20.0
import
12.2
CRAP 16.4
« blib/lib/Apache/TestSSLCA.pm ↑ Summary blib/lib/Apache/TestBuild.pm »
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 package Apache::TestMM;
17  
18 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Apache::TestConfig ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Apache::TestTrace;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Apache::TestSmoke;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 0 ▶sub import {
Subroutine import: not called CC=4 SCAR=25.0
27 0 my $class = shift;
28  
29 0 for my $section (@_) {
30 0 ▶ unless (defined &$section) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &$section) 0 0 0
31 0 die "unknown Apache::TestMM section: $section";
32 }
33 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 0 my $sub = "MY::$section";
35 # Force aliasing, since previous WriteMakefile might have
36 # moved it
37 0 ▶ undef &$sub if defined &$sub;
Branch: 1 branch
BranchTrueFalseTotal
if defined &$sub 0 0 0
38 0 *$sub = \&{$section};
39 }
40 }
41  
42 0 ▶sub add_dep {
Subroutine add_dep: not called CC=1 SCAR=6.9
Pod undocumented
43 0 my($string, $targ, $add) = @_;
44 0 $$string =~ s/($targ\s+::)/$1 $add /;
45 }
46  
47 0 ▶sub clean {
Subroutine clean: not called CC=1 SCAR=6.9
Pod undocumented
48 0 my $self = shift;
49 0 my $string = $self->MM::clean(@_);
50 0 add_dep(\$string, clean => 'test_clean');
51 0 $string;
52 }
53  
54 0 ▶sub test {
Subroutine test: not called CC=6 SCAR=37.4
Pod undocumented
55 0 my $self = shift;
56 0 my $env = Apache::TestConfig->passenv_makestr();
57  
58 0 my $tests = "TEST_FILES =\n";
59  
60 0 ▶ if (ref $self && exists $self->{'test'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self and exists $self->{"test"}) 0 0 0
Condition0%0/3
ref $self and exists $self->{"test"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self and exists $self->{"test"}
ref $self exists $self->{"test"}
Truth table0%0/3
A and B
A= ref $selfB= exists $self->{"test"}
ABresult
0X0
100
111
61 0 $tests = 'TEST_FILES = ' . $self->{'test'}->{'TESTS'} . "\n";
62 }
63  
64 0 my $preamble = Apache::TestConfig::WIN32 ? "" : <<EOF;
65 PASSENV = $env
66 EOF
67  
68 0 my $cover;
69  
70 0 ▶ if (eval { require Devel::Cover }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Devel::Cover } }) { } 0 0 0
71 0 my $atdir = File::Spec->catfile($ENV{HOME}, '.apache-test');
72  
73 0 my $cover_exec = Apache::TestConfig::which("cover");
74  
75 0 my @cover = ("", "testcover :", );
76 0 ▶ push @cover, "\t-\@$cover_exec -delete" if $cover_exec;
Branch: 1 branch
BranchTrueFalseTotal
if $cover_exec 0 0 0
77 0 push @cover, "\t-HARNESS_PERL_SWITCHES=-MDevel::Cover=+inc,$atdir \\",
78 "\tAPACHE_TEST_EXTRA_ARGS=-one-process \$(MAKE) test";
79 0 ▶ push @cover, "\t-\@$cover_exec" if $cover_exec;
Branch: 1 branch
BranchTrueFalseTotal
if $cover_exec 0 0 0
80 0 $cover = join "\n", @cover, "";
81 }
82 else {
83  
84 0 $cover = <<'EOF';
85  
86 testcover :
87 @echo "Cannot run testcover action unless Devel::Cover is installed"
88 @echo "Don't forget to rebuild your Makefile after installing Devel::Cover"
89 EOF
90 }
91  
92 0 return $preamble . $tests . <<'EOF' . $cover;
93 TEST_VERBOSE = 0
94  
95 test_clean :
96 $(FULLPERL) -I$(INST_ARCHLIB) -I$(INST_LIB) \
97 t/TEST $(APACHE_TEST_EXTRA_ARGS) -clean
98  
99 run_tests :
100 $(PASSENV) \
101 $(FULLPERL) -I$(INST_ARCHLIB) -I$(INST_LIB) \
102 t/TEST $(APACHE_TEST_EXTRA_ARGS) -bugreport -verbose=$(TEST_VERBOSE) $(TEST_FILES)
103  
104 test :: pure_all test_clean run_tests
105  
106 test_config :
107 $(PASSENV) \
108 $(FULLPERL) -I$(INST_ARCHLIB) -I$(INST_LIB) \
109 t/TEST $(APACHE_TEST_EXTRA_ARGS) -conf
110  
111 cmodules: test_config
112 cd c-modules && $(MAKE) all
113  
114 cmodules_clean: test_config
115 cd c-modules && $(MAKE) clean
116 EOF
117  
118 }
119  
120 0 ▶sub generate_script {
Subroutine generate_script: not called CC=4 SCAR=30.0
Pod documented
121 0 my $file = shift;
122  
123 0 ▶ unlink $file if -e $file;
Branch: 1 branch
BranchTrueFalseTotal
if -e $file 0 0 0
124  
125 0 my $body = "BEGIN { eval { require blib && blib->import; } }\n";
126  
127 0 my %args = @Apache::TestMM::Argv;
128 0 ▶ while (my($k, $v) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 0 0 0
129 0 $v =~ s/\|/\\|/g;
130 0 $body .= "\n\$Apache::TestConfig::Argv{'$k'} = q|$v|;\n";
131 }
132  
133 0 my $in = Symbol::gensym();
134 0 ▶ open $in, "$file.PL" or die "Couldn't open $file.PL: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $in, "$file.PL" or die "Couldn't open $file.PL: $!" 0 0 0
135 {
136 0 local $/;
137 0 $body .= <$in>;
138 }
139 0 close $in;
140  
141 0 info "generating script $file";
142 0 Apache::Test::basic_config()->write_perlscript($file, $body);
143 0 Apache::TestSmoke->generate_script;
144 }
145  
146 0 ▶sub filter_args {
Subroutine filter_args: not called CC=1 SCAR=6.9
Pod documented
147 0 my($argv, $vars) =
148 Apache::TestConfig::filter_args(\@ARGV, \%Apache::TestConfig::Usage);
149 0 @ARGV = @$argv;
150 0 @Apache::TestMM::Argv = %$vars;
151 }
152  
153 1 1;
154  
155 =head1 NAME
156  
157 Apache::TestMM - Provide MakeMaker Wrapper Methods
158  
159 =head1 SYNOPSIS
160  
161 require Apache::TestMM;
162
163 # import MY::test and MY::clean overrides for MM
164 Apache::TestMM->import(qw(test clean));
165
166 # parse command line args
167 Apache::TestMM::filter_args();
168
169 # autogenerate the script
170 Apache::TestMM::generate_script('t/TEST');
171  
172 =head1 DESCRIPTION
173  
174 C<Apache::TestMM> provides wrappers for the C<ExtUtils::MakeMaker>
175 craft, making it easier to extend the autogenerated F<Makefile> with
176 C<Apache::Test>.
177  
178 =head1 FUNCTIONS
179  
180 =head2 C<import>
181  
182 use Apache::TestMM qw(test clean);
183  
184 or:
185  
186 Apache::TestMM->import(qw(test clean));
187  
188 Imports C<MY::> overrides for the default C<ExtUtils::MakeMaker>
189 I<test> and I<clean> targets, as if you have defined:
190  
191 sub MY::test {...}
192 sub MY::clean {...}
193  
194 in F<Makefile.PL>. C<Apache::TestMM> does this for you so that these Makefile
195 targets will run the Apache server and the tests for it, and clean up after
196 its mess.
197  
198 =head2 C<filter_args>
199  
200 push @ARGV, '-apxs', $apxs_path;
201 Apache::TestMM::filter_args();
202 WriteMakefile(...);
203  
204 When C<WriteMakefile()> is called it parses C<@ARGV>, hoping to find
205 special options like C<PREFIX=/home/stas/perl>. C<Apache::Test>
206 accepts a lot of configuration options of its own. When
207 C<Apache::TestMM::filter_args()> is called, it removes any
208 C<Apache::Test>-specific options from C<@ARGV> and stores them
209 internally, so when C<WriteMakefile()> is called they aren't in
210 C<@ARGV> and thus won't be processed by C<WriteMakefile()>.
211  
212 The options can be set when F<Makefile.PL> is called:
213  
214 % perl Makefile.PL -apxs /path/to/apxs
215  
216 Or you can push them manually to C<@ARGV> from the code:
217  
218 push @ARGV, '-apxs', $apxs_path;
219  
220 When:
221  
222 Apache::TestMM::generate_script('t/TEST');
223  
224 is called, C<Apache::Test>-specific options extracted by
225 C<Apache::TestMM::filter_args()> are written to the autogenerated
226 file. In our example, the autogenerated F<t/TEST> will include:
227  
228 %Apache::TestConfig::Argv = qw(apxs /path/to/apxs);
229  
230 which is going to be used by the C<Apache::Test> runtime.
231  
232 The other frequently used options are: C<-httpd>, telling where to
233 find the httpd (usually when the C<-apxs> option is not used),
234 C<-libmodperl> to use a specific mod_perl shared object (if your
235 mod_perl is built as DSO), C<-maxclients> to change the default number
236 of the configured C<MaxClients> directive, C<-port> to start the
237 server on a specific port, etc. To get the complete list of available
238 configuration options and their purpose and syntax, run:
239  
240 % perl -MApache::TestConfig -le 'Apache::TestConfig::usage()'
241  
242 You may wish to document some of these in your application's F<README>
243 file, especially the C<-apxs> and C<-httpd> options.
244  
245  
246 =head2 C<generate_script>
247  
248 Apache::TestMM::generate_script('t/TEST');
249  
250 C<generate_script()> accepts the name of the script to generate and
251 will look for a template with the same name and suffix I<.PL>. So in
252 our example it'll look for F<t/TEST.PL>. The autogenerated script
253 F<t/TEST> will include the contents of F<t/TEST.PL>, and special
254 directives, including any configuration options passed via
255 C<L<filter_args()|/C_filter_args_>> called from F<Makefile.PL>, special
256 fixup code, etc.
257  
258 =cut
« blib/lib/Apache/TestSSLCA.pm ↑ Summary blib/lib/Apache/TestBuild.pm »