lib/Apache/Test.pm

filter: Statementstmt 21.5% 71 / 330 Branchbran 8.5% 13 / 152 Conditioncond 7.9% 5 / 63 MC/DCmcdc 2.7% 1 / 37 Subroutinesub 25.9% 14 / 54 Podpod 77.1% 27 / 35 totaltotal 19.5% 131 / 671 CC 106 SCAR 41.0
CC
106
Cov
16%
need_module
210.0
plan
182.0
sok
110.0
CRAP 60.1
« blib/lib/Apache/TestHarnessPHP.pm ↑ Summary lib/Apache/TestRun.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::Test;
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 Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Apache::TestConfig ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Test qw/ok skip/;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
27 # Apache::Test loads a bunch of mp2 stuff while getting itself
28 # together. because we need to choose one of mp1 or mp2 to load
29 # check first (and we choose mp2) $mod_perl::VERSION == 2.0
30 # just because someone loaded Apache::Test. This Is Bad. so,
31 # let's try to correct for that here by removing mod_perl from
32 # %INC after the above use() statements settle in. nobody
33 # should be relying on us loading up mod_perl.pm anyway...
34  
35 1 delete $INC{'mod_perl.pm'};
36 }
37  
38 1 ▶use vars qw(@ISA @EXPORT %EXPORT_TAGS $VERSION %SubTests @SkipReasons);
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 1 $VERSION = '1.43';
41  
42 1 my @need = qw(need_lwp need_http11 need_cgi need_access need_auth
43 need_module need_apache need_min_apache_version need_min_apache_fix
44 need_apache_version need_perl need_min_perl_version
45 need_min_module_version need_threads need_fork need_apache_mpm
46 need_php need_php4 need_ssl need_imagemap need_cache_disk);
47  
48 1 my @have = map { (my $need = $_) =~ s/need/have/; $need } @need;
49  
50 1 @ISA = qw(Exporter);
51 1 @EXPORT = (qw(sok plan skip_reason under_construction need),
52 @need, @have);
53  
54 1 %SubTests = ();
55 1 @SkipReasons = ();
56  
57 1 ▶sub cp {
Subroutine cp: called CC=3 SCAR=11.7
Pod undocumented
58 1 my @l;
59 1 ▶ for( my $i=1; (@l=caller $i)[0] eq __PACKAGE__; $i++ ) {};
Branch: 1 branch
BranchTrueFalseTotal
if ((@l = caller $i)[0] eq __PACKAGE__) 0 1 1
60 1 ▶ return wantarray ? @l : $l[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
61 }
62  
63 1 my $Config;
64 my %wtm;
65 1 ▶sub import {
Subroutine import: called CC=16 SCAR=37.4
66 1 my $class=$_[0];
67 1 my $wtm=0;
68 1 my @base_exp;
69 my @exp;
70 1 my %my_exports;
71 1 undef @my_exports{@EXPORT};
72  
73 1 my ($caller,$f,$l)=cp;
74  
75 1 ▶ for( my $i=1; $i<@_; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @_) 1 1 2
76 1 ▶ if( $_[$i] eq '-withtestmore' ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($_[$i] eq '-withtestmore') { } 0 1 1
elsif ($_[$i] eq ':DEFAULT') { } 0 1 1
elsif ($_[$i] eq '!:DEFAULT') { } 1 0 1
elsif ($_[$i] =~ m[^[:/!]]) { } 0 0 0
elsif (exists $my_exports{$_[$i]}) { } 0 0 0
77 0 $wtm=1;
78 }
79 elsif( $_[$i] eq ':DEFAULT' ) {
80 0 push @exp, $_[$i];
81 0 push @base_exp, $_[$i];
82 }
83 elsif( $_[$i] eq '!:DEFAULT' ) {
84 1 push @exp, $_[$i];
85 1 push @base_exp, $_[$i];
86 }
87 elsif( $_[$i]=~m@^[:/!]@ ) {
88 0 warn("Ignoring import spec $_[$i] ".
89 "at $f line $l\n")
90 }
91 elsif( exists $my_exports{$_[$i]} ) {
92 0 push @exp, $_[$i];
93 }
94 else {
95 0 push @base_exp, $_[$i];
96 }
97 }
98 1 ▶ if (!@exp and @base_exp) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @exp and @base_exp) { } 0 1 1
elsif (@exp and not @base_exp) { } 0 1 1
Condition33%1/3
not @exp and @base_exp
!ll&&!rl&&r
100
MC/DC0%0/2
not @exp and @base_exp
not @exp @base_exp
Truth table33%1/3
not(A) and B
A= not @expB= @base_exp
ABresult
0X0
100
111
99 0 @exp=('!:DEFAULT');
100 }
101 ▶ elsif (@exp and !@base_exp) {
Condition33%1/3
@exp and not @base_exp
!ll&&!rl&&r
010
MC/DC0%0/2
@exp and not @base_exp
@exp not @base_exp
Truth table33%1/3
A and not(B)
A= @expB= not @base_exp
ABresult
0X0
100
111
102 0 @base_exp=('!:DEFAULT');
103 }
104  
105 1 ▶ $wtm{$caller}=[$wtm,$f,$l] unless exists $wtm{$caller};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $wtm{$caller} 1 0 1
106  
107 warn("Ignoring -withtestmore due to a previous call ".
108 "($wtm{$caller}->[1]:$wtm{$caller}->[2]) without it ".
109 "at $f line $l\n")
110 1 ▶ if $wtm{$caller}->[0]==0 and $wtm==1;
Branch: 1 branch
BranchTrueFalseTotal
if $wtm{$caller}[0] == 0 and $wtm == 1 0 1 1
Condition33%1/3
$wtm{$caller}[0] == 0 and $wtm == 1
!ll&&!rl&&r
010
MC/DC0%0/2
$wtm{$caller}[0] == 0 and $wtm == 1
$wtm{$caller}[0] == 0 $wtm == 1
Truth table33%1/3
A and B
A= $wtm{$caller}[0] == 0B= $wtm == 1
ABresult
0X0
100
111
111  
112 1 $class->export_to_level(1, $class, @exp);
113  
114 1 push @base_exp, '!plan';
115 1 ▶ if( $wtm{$caller}->[0] ) { # -withtestmore
Branch: 1 branch
BranchTrueFalseTotal
if ($wtm{$caller}[0]) { } 0 1 1
116 eval <<"EVAL"
117 package $caller;
118 #line $l $f
119 use Test::More import=>\\\@base_exp;
120 EVAL
121 0 }
122 else { # -withouttestmore
123 1 eval <<"EVAL";
124 package $caller;
125 #line $l $f
126 use Test \@base_exp;
127 EVAL
128 }
129 1 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
130 }
131  
132 0 ▶sub config {
Subroutine config: not called CC=2 SCAR=17.9
Pod documented
133 0 ▶ $Config ||= Apache::TestConfig->thaw->httpd_config;
Condition0%0/3
$Config ||= "Apache::TestConfig"->thaw->httpd_config
l!l&&r!l&&!r
000
MC/DC0%0/2
$Config ||= "Apache::TestConfig"->thaw->httpd_config
$Config "Apache::TestConfig"->thaw->httpd_config
Truth table0%0/3
A ||= B
A= $ConfigB= "Apache::TestConfig"->thaw->httpd_config
ABresult
1X1
011
000
134 }
135  
136 1 my $Basic_config;
137  
138 # config bits which doesn't require httpd to be found
139 0 ▶sub basic_config {
Subroutine basic_config: not called CC=2 SCAR=17.9
Pod documented
140 0 ▶ $Basic_config ||= Apache::TestConfig->thaw();
Condition0%0/3
$Basic_config ||= "Apache::TestConfig"->thaw
l!l&&r!l&&!r
000
MC/DC0%0/2
$Basic_config ||= "Apache::TestConfig"->thaw
$Basic_config "Apache::TestConfig"->thaw
Truth table0%0/3
A ||= B
A= $Basic_configB= "Apache::TestConfig"->thaw
ABresult
1X1
011
000
141 }
142  
143 0 ▶sub vars {
Subroutine vars: not called CC=2 SCAR=17.9
Pod documented
144 0 ▶ @_ ? @{ config()->{vars} }{ @_ } : config()->{vars};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
145 }
146  
147 0 ▶sub sok (&;$) {
Subroutine sok: not called CC=10 SCAR=47.0
Pod documented
148 0 my $sub = shift;
149 0 ▶ my $nok = shift || 1; #allow sok to have 'ok' within
Condition0%0/2
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
150  
151 0 my ($caller,$f,$l)=cp;
152  
153 0 ▶ if (exists $wtm{$caller} and $wtm{$caller}->[0]==1) { # -withtestmore
Branch: 1 branch
BranchTrueFalseTotal
if (exists $wtm{$caller} and $wtm{$caller}[0] == 1) { } 0 0 0
Condition0%0/3
exists $wtm{$caller} and $wtm{$caller}[0] == 1
!ll&&!rl&&r
000
MC/DC0%0/2
exists $wtm{$caller} and $wtm{$caller}[0] == 1
exists $wtm{$caller} $wtm{$caller}[0] == 1
Truth table0%0/3
A and B
A= exists $wtm{$caller}B= $wtm{$caller}[0] == 1
ABresult
0X0
100
111
154 0 require Test::Builder;
155 0 my $tb=Test::Builder->new;
156  
157 0 ▶ if (%SubTests and not $SubTests{ 1+$tb->current_test }) {
Branch: 1 branch
BranchTrueFalseTotal
if (%Apache::Test::SubTests and not $Apache::Test::SubTests{1 + $tb->current_test}) 0 0 0
Condition0%0/3
%Apache::Test::SubTests and not $Apache::Test::SubTests{1 + $tb->current_test}
!ll&&!rl&&r
000
MC/DC0%0/2
%Apache::Test::SubTests and not $Apache::Test::SubTests{1 + $tb->current_test}
%Apache::Test::SubTests not $Apache::Test::SubTests{1 + $tb->current_test}
Truth table0%0/3
A and not(B)
A= %Apache::Test::SubTestsB= not $Apache::Test::SubTests{1 + $tb->current_test}
ABresult
0X0
100
111
158 0 $tb->skip("skipping this subtest") for (1..$nok);
159 0 return;
160 }
161  
162 # trick ok() into reporting the caller filename/line when a
163 # sub-test fails in sok()
164 0 return eval <<EOE;
165 #line $l $f
166 Test::More::ok(\$sub->());
167 EOE
168 }
169 else {
170 0 ▶ if (%SubTests and not $SubTests{ $Test::ntest }) {
Branch: 1 branch
BranchTrueFalseTotal
if (%Apache::Test::SubTests and not $Apache::Test::SubTests{$Test::ntest}) 0 0 0
Condition0%0/3
%Apache::Test::SubTests and not $Apache::Test::SubTests{$Test::ntest}
!ll&&!rl&&r
000
MC/DC0%0/2
%Apache::Test::SubTests and not $Apache::Test::SubTests{$Test::ntest}
%Apache::Test::SubTests not $Apache::Test::SubTests{$Test::ntest}
Truth table0%0/3
A and not(B)
A= %Apache::Test::SubTestsB= not $Apache::Test::SubTests{$Test::ntest}
ABresult
0X0
100
111
171 0 skip("skipping this subtest", 0) for (1..$nok);
172 0 return;
173 }
174  
175 # trick ok() into reporting the caller filename/line when a
176 # sub-test fails in sok()
177 0 return eval <<EOE;
178 #line $l $f
179 Test::ok(\$sub->());
180 EOE
181 }
182 }
183  
184 #so Perl's Test.pm can be run inside mod_perl
185 0 ▶sub test_pm_refresh {
Subroutine test_pm_refresh: not called CC=5 SCAR=34.0
Pod documented
186 0 my ($caller,$f,$l)=cp;
187  
188 0 ▶ if (exists $wtm{$caller} and $wtm{$caller}->[0]==1) { # -withtestmore
Branch: 1 branch
BranchTrueFalseTotal
if (exists $wtm{$caller} and $wtm{$caller}[0] == 1) { } 0 0 0
Condition0%0/3
exists $wtm{$caller} and $wtm{$caller}[0] == 1
!ll&&!rl&&r
000
MC/DC0%0/2
exists $wtm{$caller} and $wtm{$caller}[0] == 1
exists $wtm{$caller} $wtm{$caller}[0] == 1
Truth table0%0/3
A and B
A= exists $wtm{$caller}B= $wtm{$caller}[0] == 1
ABresult
0X0
100
111
189 0 require Test::Builder;
190 0 my $builder = Test::Builder->new;
191  
192 0 $builder->reset;
193  
194 0 $builder->output(\*STDOUT);
195 0 $builder->todo_output(\*STDOUT);
196  
197 # this is STDOUT because Test::More seems to put
198 # most of the stuff we want on STDERR, so it ends
199 # up in the error_log instead of where the user can
200 # see it. consider leaving it alone based on
201 # later user reports.
202 0 $builder->failure_output(\*STDOUT);
203 }
204 else { # -withouttestmore
205 0 ▶ unless (exists $wtm{$caller}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $wtm{$caller}) 0 0 0
206 0 warn "You forgot to 'use Apache::Test' in package $caller\n";
207 0 $wtm{$caller}=[0,$f,$l];
208 }
209 0 ▶ if (defined &Test::_reset_globals) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &Test::_reset_globals) { } 0 0 0
210 0 Test::_reset_globals();
211 # Test.pm uses $TESTOUT=*STDOUT{IO}. We cannot do that
212 # due to the way SetupEnv works.
213 0 $Test::TESTOUT = \*STDOUT;
214 }
215 else {
216 0 $Test::TESTOUT = \*STDOUT;
217 0 $Test::planned = 0;
218 0 $Test::ntest = 1;
219 0 %Test::todo = ();
220 }
221 }
222 }
223  
224 0 ▶sub init_test_pm {
Subroutine init_test_pm: not called CC=2 SCAR=17.9
Pod undocumented
225 0 my $r = shift;
226  
227 # needed to load Apache2::RequestRec::TIEHANDLE
228 0 eval {require Apache2::RequestIO};
229 0 ▶ if (defined &Apache2::RequestRec::TIEHANDLE) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &Apache2::RequestRec::TIEHANDLE) { } 0 0 0
230 0 untie *STDOUT;
231 0 tie *STDOUT, $r;
232 0 require Apache2::RequestRec; # $r->pool
233 0 require APR::Pool;
234 0 ▶ $r->pool->cleanup_register(sub { untie *STDOUT });
Subroutine __ANON__: not called CC=1 SCAR=6.9
235 }
236 else {
237 0 $r->send_http_header; #1.xx
238 }
239  
240 0 $r->content_type('text/plain');
241 }
242  
243 0 ▶sub plan {
Subroutine plan: not called CC=13 SCAR=52.0
Pod documented
244 0 ▶ init_test_pm(shift) if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
245 0 test_pm_refresh();
246  
247 # extending Test::plan's functionality, by using the optional
248 # single value in @_ coming after a ballanced %hash which
249 # Test::plan expects
250 0 ▶ if (@_ % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2) 0 0 0
251 0 my $condition = pop @_;
252 0 my $ref = ref $condition;
253 0 my $meets_condition = 0;
254 0 ▶ if ($ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) { } 0 0 0
255 0 ▶ if ($ref eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if ($ref eq 'CODE') { } 0 0 0
elsif ($ref eq 'ARRAY') { } 0 0 0
256 #plan tests $n, \&has_lwp
257 0 $meets_condition = $condition->();
258 }
259 elsif ($ref eq 'ARRAY') {
260 #plan tests $n, [qw(php4 rewrite)];
261 0 $meets_condition = need_module($condition);
262 }
263 else {
264 0 die "don't know how to handle a condition of type $ref";
265 }
266 }
267 else {
268 # we have the verdict already: true/false
269 0 ▶ $meets_condition = $condition ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$condition ? : 0 0 0
270 }
271  
272 # trying to emulate a dual variable (ala errno)
273 0 ▶ unless ($meets_condition) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($meets_condition) 0 0 0
274 0 ▶ my $reason = join ', ',
Branch: 1 branch
BranchTrueFalseTotal
@Apache::Test::SkipReasons ? : 0 0 0
275 @SkipReasons ? @SkipReasons : "no reason given";
276 0 print "1..0 # skipped: $reason\n";
277 0 @SkipReasons = (); # reset
278 0 exit; #XXX: Apache->exit
279 }
280 }
281 0 @SkipReasons = (); # reset
282  
283 0 my ($caller,$f,$l)=cp;
284  
285 0 %SubTests=();
286 0 ▶ if (my $subtests=$ENV{HTTPD_TEST_SUBTESTS}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $subtests = $ENV{"HTTPD_TEST_SUBTESTS"}) 0 0 0
287 0 %SubTests=map { $_, 1 } split /\s+/, $subtests;
288 }
289  
290 0 ▶ if (exists $wtm{$caller} and $wtm{$caller}->[0]==1) { # -withtestmore
Branch: 1 branch
BranchTrueFalseTotal
if (exists $wtm{$caller} and $wtm{$caller}[0] == 1) { } 0 0 0
Condition0%0/3
exists $wtm{$caller} and $wtm{$caller}[0] == 1
!ll&&!rl&&r
000
MC/DC0%0/2
exists $wtm{$caller} and $wtm{$caller}[0] == 1
exists $wtm{$caller} $wtm{$caller}[0] == 1
Truth table0%0/3
A and B
A= exists $wtm{$caller}B= $wtm{$caller}[0] == 1
ABresult
0X0
100
111
291 0 Test::More::plan(@_);
292 }
293 else { # -withouttestmore
294 0 ▶ unless (exists $wtm{$caller}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $wtm{$caller}) 0 0 0
295 0 warn "You forgot to 'use Apache::Test' in package $caller\n";
296 0 $wtm{$caller}=[0,$f,$l];
297 }
298 0 Test::plan(@_);
299 }
300  
301 # add to Test.pm verbose output
302 0 print "# Using Apache/Test.pm version $VERSION\n";
303 }
304  
305 0 ▶sub need_http11 {
Subroutine need_http11: not called CC=2 SCAR=17.9
Pod documented
306 0 require Apache::TestRequest;
307 0 ▶ if (Apache::TestRequest::install_http11()) {
Branch: 1 branch
BranchTrueFalseTotal
if (Apache::TestRequest::install_http11()) { } 0 0 0
308 0 return 1;
309 }
310 else {
311 0 push @SkipReasons,
312 "LWP version 5.60+ required for HTTP/1.1 support";
313 0 return 0;
314 }
315 }
316  
317 0 ▶sub need_ssl {
Subroutine need_ssl: not called CC=1 SCAR=6.9
Pod documented
318 0 my $vars = vars();
319 0 need_module([$vars->{ssl_module_name}, 'IO::Socket::SSL']);
320 }
321  
322 0 ▶sub need_lwp {
Subroutine need_lwp: not called CC=2 SCAR=17.9
Pod documented
323 0 require Apache::TestRequest;
324 0 ▶ if (Apache::TestRequest::has_lwp()) {
Branch: 1 branch
BranchTrueFalseTotal
if (Apache::TestRequest::has_lwp()) { } 0 0 0
325 0 return 1;
326 }
327 else {
328 0 push @SkipReasons, "libwww-perl is not installed";
329 0 return 0;
330 }
331 }
332  
333 0 ▶sub need {
Subroutine need: not called CC=9 SCAR=45.0
Pod documented
334 0 my $need_all = 1;
335 0 for my $cond (@_) {
336 0 ▶ if (ref $cond eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $cond eq 'HASH') { } 0 0 0
elsif ($cond =~ /^(0|1)$/) { } 0 0 0
337 0 ▶ while (my($reason, $value) = each %$cond) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$cond) 0 0 0
338 0 ▶ $value = $value->() if ref $value eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "CODE" 0 0 0
339 0 ▶ next if $value;
Branch: 1 branch
BranchTrueFalseTotal
if $value 0 0 0
340 0 push @SkipReasons, $reason;
341 0 $need_all = 0;
342 }
343 }
344 elsif ($cond =~ /^(0|1)$/) {
345 0 ▶ $need_all = 0 if $cond == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $cond == 0 0 0 0
346 }
347 else {
348 0 ▶ $need_all = 0 unless need_module($cond);
Branch: 1 branch
BranchTrueFalseTotal
unless need_module($cond) 0 0 0
349 }
350 }
351 0 return $need_all;
352  
353 }
354  
355 0 ▶sub need_module {
Subroutine need_module: not called CC=14 SCAR=53.5
Pod documented
356 0 my $cfg = config();
357  
358 my @modules = grep defined $_,
359 0 ▶ ref($_[0]) eq 'ARRAY' ? @{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 0 0
360  
361 0 my @reasons = ();
362 0 for (@modules) {
363 0 ▶ if (/^[a-z0-9_.]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^[a-z0-9_.]+$/) 0 0 0
364 0 my $mod = $_;
365 0 ▶ $mod .= '.c' unless $mod =~ /\.c$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $mod =~ /\.c$/ 0 0 0
366 0 ▶ next if $cfg->{modules}->{$mod};
Branch: 1 branch
BranchTrueFalseTotal
if $cfg->{"modules"}{$mod} 0 0 0
367 0 ▶ $mod = 'mod_' . $mod unless $mod =~ /^mod_/;
Branch: 1 branch
BranchTrueFalseTotal
unless $mod =~ /^mod_/ 0 0 0
368 0 ▶ next if $cfg->{modules}->{$mod};
Branch: 1 branch
BranchTrueFalseTotal
if $cfg->{"modules"}{$mod} 0 0 0
369 0 ▶ if (exists $cfg->{cmodules_disabled}->{$mod}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cfg->{"cmodules_disabled"}{$mod}) 0 0 0
370 0 push @reasons, $cfg->{cmodules_disabled}->{$mod};
371 0 next;
372 }
373 }
374 0 ▶ die "bogus module name $_" unless /^[\w:.]+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^[\w:.]+$/ 0 0 0
375  
376 # if the module was explicitly passed with a .c extension,
377 # do not try to eval it as a Perl module
378 0 my $not_found = 1;
379 0 ▶ unless (/\.c$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/\.c$/) 0 0 0
380 0 eval "require $_";
381 0 ▶ $not_found = 0 unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 0 0
382 #print $@ if $@;
383 }
384 0 ▶ push @reasons, "cannot find module '$_'" if $not_found;
Branch: 1 branch
BranchTrueFalseTotal
if $not_found 0 0 0
385  
386 }
387 0 ▶ if (@reasons) {
Branch: 1 branch
BranchTrueFalseTotal
if (@reasons) { } 0 0 0
388 0 push @SkipReasons, @reasons;
389 0 return 0;
390 }
391 else {
392 0 return 1;
393 }
394 }
395  
396 0 ▶sub need_min_perl_version {
Subroutine need_min_perl_version: not called CC=2 SCAR=17.9
Pod documented
397 0 my $version = shift;
398  
399 0 ▶ return 1 if $] >= $version;
Branch: 1 branch
BranchTrueFalseTotal
if $] >= $version 0 0 0
400  
401 0 push @SkipReasons, "perl >= $version is required";
402 0 return 0;
403 }
404  
405 # currently supports only perl modules
406 0 ▶sub need_min_module_version {
Subroutine need_min_module_version: not called CC=3 SCAR=19.6
Pod documented
407 0 my($module, $version) = @_;
408  
409 # need_module requires the perl module
410 0 ▶ return 0 unless need_module($module);
Branch: 1 branch
BranchTrueFalseTotal
unless need_module($module) 0 0 0
411  
412 # support dev versions like 0.18_01
413 return 1
414 0 ▶ if eval { no warnings qw(numeric); $module->VERSION($version) };
Subroutine BEGIN: called CC=1 SCAR=1.7
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { BEGIN {${^WARNING_BITS} = "\xff\xff\xff\xf3\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"} $module->VERSION($version) } } 0 0 0
415  
416 0 push @SkipReasons, "$module version $version or higher is required";
417 0 return 0;
418 }
419  
420 0 ▶sub need_cgi {
Subroutine need_cgi: not called CC=1 SCAR=6.9
Pod documented
421 0 return _need_multi(qw(cgi.c cgid.c));
422 }
423  
424 0 ▶sub need_cache_disk {
Subroutine need_cache_disk: not called CC=1 SCAR=6.9
Pod documented
425 0 return _need_multi(qw(cache_disk.c disk_cache.c));
426 }
427  
428  
429 0 ▶sub need_php {
Subroutine need_php: not called CC=1 SCAR=6.9
Pod documented
430 0 return _need_multi(qw(php4 php5 sapi_apache2.c));
431 }
432  
433 0 ▶sub need_php4 {
Subroutine need_php4: not called CC=1 SCAR=6.9
Pod documented
434 0 return _need_multi(qw(php4 sapi_apache2.c));
435 }
436  
437 0 ▶sub need_access {
Subroutine need_access: not called CC=1 SCAR=6.9
Pod undocumented
438 0 return _need_multi(qw(access authz_host));
439 }
440  
441 0 ▶sub need_auth {
Subroutine need_auth: not called CC=1 SCAR=6.9
Pod undocumented
442 0 return _need_multi(qw(auth auth_basic));
443 }
444  
445 0 ▶sub need_imagemap {
Subroutine need_imagemap: not called CC=2 SCAR=17.9
Pod documented
446 0 ▶ return need_module("imagemap") || need_module("imap");
Condition0%0/3
need_module('imagemap') || need_module('imap')
l!l&&r!l&&!r
000
MC/DC0%0/2
need_module('imagemap') || need_module('imap')
need_module('imagemap') need_module('imap')
Truth table0%0/3
A || B
A= need_module('imagemap')B= need_module('imap')
ABresult
1X1
011
000
447 }
448  
449 0 ▶sub _need_multi {
Subroutine _need_multi: not called CC=4 SCAR=30.0
450  
451 0 my @check = @_;
452  
453 0 my $rc = 0;
454  
455 {
456 0 local @SkipReasons;
457  
458 0 foreach my $module (@check) {
459 0 ▶ $rc ||= need_module($module);
Condition0%0/3
$rc ||= need_module($module)
l!l&&r!l&&!r
000
MC/DC0%0/2
$rc ||= need_module($module)
$rc need_module($module)
Truth table0%0/3
A ||= B
A= $rcB= need_module($module)
ABresult
1X1
011
000
460 }
461 }
462  
463 0 my $reason = join ' or ', @check;
464  
465 0 ▶ push @SkipReasons, "cannot find one of $reason"
Branch: 1 branch
BranchTrueFalseTotal
unless $rc 0 0 0
466 unless $rc;
467  
468 0 return $rc;
469 }
470  
471 0 ▶sub need_apache {
Subroutine need_apache: not called CC=2 SCAR=17.9
Pod documented
472 0 my $version = shift;
473 0 my $cfg = Apache::Test::config();
474 0 my $rev = $cfg->{server}->{rev};
475  
476 0 ▶ if ($rev == $version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rev == $version) { } 0 0 0
477 0 return 1;
478 }
479 else {
480 0 push @SkipReasons,
481 "apache version $version required, this is version $rev";
482 0 return 0;
483 }
484 }
485  
486 0 ▶sub need_min_apache_version {
Subroutine need_min_apache_version: not called CC=2 SCAR=17.9
Pod documented
487 0 my $wanted = shift;
488 0 my $cfg = Apache::Test::config();
489 0 (my $current) = $cfg->{server}->{version} =~ m:^Apache/(\d\.\d+\.\d+):;
490  
491 0 ▶ if (normalize_vstring($current) < normalize_vstring($wanted)) {
Branch: 1 branch
BranchTrueFalseTotal
if (normalize_vstring($current) < normalize_vstring($wanted)) { } 0 0 0
492 0 push @SkipReasons,
493 "apache version $wanted or higher is required," .
494 " this is version $current";
495 0 return 0;
496 }
497 else {
498 0 return 1;
499 }
500 }
501  
502 0 ▶sub need_min_apache_fix {
Subroutine need_min_apache_fix: not called CC=6 SCAR=37.4
Pod documented
503 0 my @wantlevels = @_;
504 0 my $cfg = Apache::Test::config();
505 0 (my $current) = $cfg->{server}->{version} =~ m:^Apache/((\d)\.(\d+)\.(\d+)):;
506 0 my $current_major = $2;
507 0 my $current_minor = $3;
508 0 my $current_micro = $4;
509  
510 0 foreach(@wantlevels) {
511 0 ▶ if ($_ =~ m/(\d)\.(\d+)\.(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /(\d)\.(\d+)\.(\d+)/) 0 0 0
512 0 my $wanted_major = $1;
513 0 my $wanted_minor = $2;
514 0 my $wanted_micro = $3;
515 0 ▶ if ($wanted_major eq $current_major && $wanted_minor eq $current_minor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wanted_major eq $current_major and $wanted_minor eq $current_minor) 0 0 0
Condition0%0/3
$wanted_major eq $current_major and $wanted_minor eq $current_minor
!ll&&!rl&&r
000
MC/DC0%0/2
$wanted_major eq $current_major and $wanted_minor eq $current_minor
$wanted_major eq $current_major $wanted_minor eq $current_minor
Truth table0%0/3
A and B
A= $wanted_major eq $current_majorB= $wanted_minor eq $current_minor
ABresult
0X0
100
111
516 0 ▶ if ($wanted_micro > $current_micro) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wanted_micro > $current_micro) { } 0 0 0
517 0 push @SkipReasons,
518 "apache version $_ or higher is required," .
519 " this is version $current";
520 0 return 0;
521 }
522 else {
523 0 return 1;
524 }
525 }
526 }
527 }
528  
529 # We didn't match major+minor, run the test and let the author sort it out
530 0 return 1;
531 }
532  
533 0 ▶sub need_apache_version {
Subroutine need_apache_version: not called CC=2 SCAR=17.9
Pod documented
534 0 my $wanted = shift;
535 0 my $cfg = Apache::Test::config();
536 0 (my $current) = $cfg->{server}->{version} =~ m:^Apache/(\d\.\d+\.\d+):;
537  
538 0 ▶ if (normalize_vstring($current) != normalize_vstring($wanted)) {
Branch: 1 branch
BranchTrueFalseTotal
if (normalize_vstring($current) != normalize_vstring($wanted)) { } 0 0 0
539 0 push @SkipReasons,
540 "apache version $wanted or higher is required," .
541 " this is version $current";
542 0 return 0;
543 }
544 else {
545 0 return 1;
546 }
547 }
548  
549 0 ▶sub need_apache_mpm {
Subroutine need_apache_mpm: not called CC=2 SCAR=17.9
Pod documented
550 0 my $wanted = shift;
551 0 my $cfg = Apache::Test::config();
552 0 my $current = $cfg->{server}->{mpm};
553  
554 0 ▶ if ($current ne $wanted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current ne $wanted) { } 0 0 0
555 0 push @SkipReasons,
556 "apache $wanted mpm is required," .
557 " this is the $current mpm";
558 0 return 0;
559 }
560 else {
561 0 return 1;
562 }
563 }
564  
565 0 ▶sub config_enabled {
Subroutine config_enabled: not called CC=2 SCAR=17.9
Pod undocumented
566 0 my $key = shift;
567 0 ▶ defined $Config{$key} and $Config{$key} eq 'define';
Branch: 1 branch
BranchTrueFalseTotal
defined $Apache::Test::Config{$key} and $Apache::Test::Config{$key} eq "define" 0 0 0
568 }
569  
570 0 ▶sub need_perl_iolayers {
Subroutine need_perl_iolayers: not called CC=2 SCAR=17.9
Pod undocumented
571 0 ▶ if (my $ext = $Config{extensions}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ext = $Apache::Test::Config{"extensions"}) 0 0 0
572 #XXX: better test? might need to test patchlevel
573 #if support depends bugs fixed in bleedperl
574 0 return $ext =~ m:PerlIO/scalar:;
575 }
576 0 0;
577 }
578  
579 0 ▶sub need_perl {
Subroutine need_perl: not called CC=7 SCAR=40.3
Pod documented
580 0 my $thing = shift;
581 #XXX: $thing could be a version
582 0 my $config;
583  
584 0 my $have = \&{"need_perl_$thing"};
585 0 ▶ if (defined &$have) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &$have) { } 0 0 0
586 0 ▶ return 1 if $have->();
Branch: 1 branch
BranchTrueFalseTotal
if &$have() 0 0 0
587 }
588 else {
589 0 for my $key ($thing, "use$thing") {
590 0 ▶ if (exists $Config{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Apache::Test::Config{$key}) 0 0 0
591 0 $config = $key;
592 0 ▶ return 1 if config_enabled($key);
Branch: 1 branch
BranchTrueFalseTotal
if config_enabled($key) 0 0 0
593 }
594 }
595 }
596  
597 0 ▶ push @SkipReasons, $config ?
Branch: 1 branch
BranchTrueFalseTotal
$config ? : 0 0 0
598 "Perl was not built with $config enabled" :
599 "$thing is not available with this version of Perl";
600  
601 0 return 0;
602 }
603  
604 0 ▶sub need_threads {
Subroutine need_threads: not called CC=5 SCAR=34.0
Pod undocumented
605 0 my $status = 1;
606  
607 # check APR support
608 0 my $build_config = Apache::TestConfig->modperl_build_config;
609  
610 0 ▶ if ($build_config) {
Branch: 1 branch
BranchTrueFalseTotal
if ($build_config) 0 0 0
611 0 my $apr_config = $build_config->get_apr_config();
612 0 ▶ unless ($apr_config->{HAS_THREADS}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($apr_config->{"HAS_THREADS"}) 0 0 0
613 0 $status = 0;
614 0 push @SkipReasons, "Apache/APR was built without threads support";
615 }
616 }
617  
618 # check Perl's useithreads
619 0 my $key = 'useithreads';
620 0 ▶ unless (exists $Config{$key} and config_enabled($key)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Apache::Test::Config{$key} and config_enabled($key)) 0 0 0
Condition0%0/3
exists $Apache::Test::Config{$key} and config_enabled($key)
!ll&&!rl&&r
000
MC/DC0%0/2
exists $Apache::Test::Config{$key} and config_enabled($key)
exists $Apache::Test::Config{$key} config_enabled($key)
Truth table0%0/3
A and B
A= exists $Apache::Test::Config{$key}B= config_enabled($key)
ABresult
0X0
100
111
621 0 $status = 0;
622 0 push @SkipReasons, "Perl was not built with 'ithreads' enabled";
623 }
624  
625 0 return $status;
626 }
627  
628 0 ▶sub need_fork {
Subroutine need_fork: not called CC=7 SCAR=40.3
Pod documented
629 my $have_fork = $Config{d_fork} ||
630 $Config{d_pseudofork} ||
631 (($^O eq 'MSWin32' || $^O eq 'NetWare') &&
632 $Config{useithreads} &&
633 0 ▶ $Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/);
Condition0%0/15
$Apache::Test::Config{'d_fork'} || $Apache::Test::Config{'d_pseudofork'} || ($^O eq 'MSWin32' || $^O eq 'NetWare') && $Apache::Test::Config{'useithreads'} && $Apache::Test::Config{'ccflags'} =~ /-DPERL_IMPLICIT_SYS/
l!l&&r!l&&!r
000
$Apache::Test::Config{"d_fork"} or $Apache::Test::Config{"d_pseudofork"}
l!l&&r!l&&!r
000
$^O eq "MSWin32" || $^O eq "NetWare" and $Apache::Test::Config{"useithreads"} and $Apache::Test::Config{"ccflags"} =~ /-DPERL_IMPLICIT_SYS/
!ll&&!rl&&r
000
$^O eq "MSWin32" || $^O eq "NetWare" and $Apache::Test::Config{"useithreads"}
!ll&&!rl&&r
000
$^O eq "MSWin32" or $^O eq "NetWare"
l!l&&r!l&&!r
000
MC/DC0%0/6
$Apache::Test::Config{'d_fork'} || $Apache::Test::Config{'d_pseudofork'} || ($^O eq 'MSWin32' || $^O eq 'NetWare') && $Apache::Test::Config{'useithreads'} && $Apache::Test::Config{'ccflags'} =~ /-DPERL_IMPLICIT_SYS/
$Apache::Test::Config{"d_fork"} $Apache::Test::Config{"d_pseudofork"} $^O eq "MSWin32" $^O eq "NetWare" $Apache::Test::Config{"useithreads"} $Apache::Test::Config{"ccflags"} =~ /-DPERL_IMPLICIT_SYS/
Truth table0%0/9
A or B || C or D and E and F
A= $Apache::Test::Config{"d_fork"}B= $Apache::Test::Config{"d_pseudofork"}C= $^O eq "MSWin32"D= $^O eq "NetWare"E= $Apache::Test::Config{"useithreads"}F= $Apache::Test::Config{"ccflags"} =~ /-DPERL_IMPLICIT_SYS/
ABCDEFresult
1XXXXX1
01XXXX1
001X111
0001111
0000XX0
001X0X0
00010X0
001X100
0001100
634  
635 0 ▶ if (!$have_fork) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $have_fork) { } 0 0 0
636 0 push @SkipReasons, 'The fork function is unimplemented';
637 0 return 0;
638 }
639 else {
640 0 return 1;
641 }
642 }
643  
644 0 ▶sub under_construction {
Subroutine under_construction: not called CC=1 SCAR=6.9
Pod documented
645 0 push @SkipReasons, "This test is under construction";
646 0 return 0;
647 }
648  
649 0 ▶sub skip_reason {
Subroutine skip_reason: not called CC=2 SCAR=17.9
Pod documented
650 0 ▶ my $reason = shift || 'no reason specified';
Condition0%0/2
shift() || 'no reason specified'
l!l
00
MC/DC0%0/1
shift() || 'no reason specified'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
651 0 push @SkipReasons, $reason;
652 0 return 0;
653 }
654  
655 # normalize Apache-style version strings (2.0.48, 0.9.4)
656 # for easy numeric comparison. note that 2.1 and 2.1.0
657 # are considered equivalent.
658 6 ▶sub normalize_vstring {
Subroutine normalize_vstring: called CC=2 SCAR=6.9
Pod undocumented
659  
660 6 my @digits = shift =~ m/(\d+)\.?(\d*)\.?(\d*)/;
661  
662 6 ▶ return join '', map { sprintf("%03d", $_ || 0) } @digits;
Condition100%2/2
$_ || 0
l!l
135
MC/DC100%1/1
$_ || 0
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
663 }
664  
665 # have_ functions are the same as need_ but they don't populate
666 # @SkipReasons
667 1 for my $func (@have) {
668 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
669 21 (my $real_func = $func) =~ s/^have_/need_/;
670 0 ▶ *$func = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
671 # be nice to poor souls calling functions with $_ argument in
672 # the foreach loop, etc.!
673 0 local $_;
674 0 local @SkipReasons;
675 0 return $real_func->(@_);
676 21 };
677 }
678  
679 package Apache::TestToString;
680  
681 1 ▶Apache::Test->import('!:DEFAULT');
Subroutine BEGIN: called CC=1 SCAR=0.0
682  
683 0 ▶sub TIEHANDLE {
Subroutine TIEHANDLE: not called CC=1 SCAR=6.9
684 0 my $string = "";
685 0 bless \$string;
686 }
687  
688 0 ▶sub PRINT {
Subroutine PRINT: not called CC=1 SCAR=6.9
689 0 my $string = shift;
690 0 $$string .= join '', @_;
691 }
692  
693 0 ▶sub start {
Subroutine start: not called CC=1 SCAR=6.9
694 0 tie *STDOUT, __PACKAGE__;
695 0 Apache::Test::test_pm_refresh();
696 }
697  
698 0 ▶sub finish {
Subroutine finish: not called CC=1 SCAR=6.9
699 0 my $s;
700 {
701 0 my $o = tied *STDOUT;
702 0 $s = $$o;
703 }
704 0 untie *STDOUT;
705 0 $s;
706 }
707  
708 1 1;
709 __END__
« blib/lib/Apache/TestHarnessPHP.pm ↑ Summary lib/Apache/TestRun.pm »