lib/Apache/TestHarness.pm

filter: Statementstmt 25.2% 30 / 119 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 56.2% 9 / 16 Podpod 0.0% 0 / 6 totaltotal 18.6% 39 / 209 CC 34 SCAR 38.5
CC
34
Cov
17%
get_tests
110.0
run_t
56.0
prune
50.4
CRAP 47.0
« blib/lib/Apache/TestClient.pm ↑ Summary blib/lib/Apache/TestUtil.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::TestHarness;
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 Test::Harness ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Apache::Test ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Apache::TestSort ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Apache::TestTrace;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use File::Spec::Functions qw(catfile catdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use File::Find qw(finddepth);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use File::Basename qw(dirname);
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 0 ▶sub inc_fixup {
Subroutine inc_fixup: not called CC=3 SCAR=24.8
Pod undocumented
30 # use blib
31 0 unshift @INC, map "blib/$_", qw(lib arch);
32  
33 # fix all relative library locations
34 0 for (@INC) {
35 0 ▶ $_ = "../$_" unless m,^(/)|([a-f]:),i;
Branch: 1 branch
BranchTrueFalseTotal
unless m[^(/)|([a-f]:)]i 0 0 0
36 }
37 }
38  
39 #skip tests listed in t/SKIP
40 0 ▶sub skip {
Subroutine skip: not called CC=6 SCAR=37.4
Pod undocumented
41 0 my($self, $file) = @_;
42 0 ▶ $file ||= catfile Apache::Test::vars('serverroot'), 'SKIP';
Condition0%0/3
$file ||= catfile(Apache::Test::vars("serverroot"), "SKIP")
l!l&&r!l&&!r
000
MC/DC0%0/2
$file ||= catfile(Apache::Test::vars("serverroot"), "SKIP")
$file catfile(Apache::Test::vars("serverroot"), "SKIP")
Truth table0%0/3
A ||= B
A= $fileB= catfile(Apache::Test::vars("serverroot"), "SKIP")
ABresult
1X1
011
000
43  
44 0 ▶ return unless -e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 0 0 0
45  
46 0 my $fh = Symbol::gensym();
47 0 ▶ open $fh, $file or die "open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, $file or die "open ${file}: $!" 0 0 0
48 0 my @skip;
49 0 local $_;
50  
51 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
52 0 chomp;
53 0 s/^\s+//; s/\s+$//; s/^\#.*//;
54 0 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 0 0
55 0 s/\*/.*/g;
56 0 push @skip, $_;
57 }
58  
59 0 close $fh;
60 0 return join '|', @skip;
61 }
62  
63 #test if all.t would skip tests or not
64 {
65 1 my $source_lib = '';
66  
67 0 ▶ sub run_t {
Subroutine run_t: not called CC=7 SCAR=40.3
Pod undocumented
68 0 my($self, $file) = @_;
69 0 my $ran = 0;
70  
71 0 ▶ if (Apache::TestConfig::IS_APACHE_TEST_BUILD and !length $source_lib) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $source_lib) 0 0 0
72 # so we can find Apache/Test.pm from both the perl-framework/
73 # and Apache-Test/
74  
75 0 my $top_dir = Apache::Test::vars('top_dir');
76 0 foreach my $lib (catfile($top_dir, qw(Apache-Test lib)),
77 catfile($top_dir, qw(.. Apache-Test lib)),
78 catfile($top_dir, 'lib')) {
79  
80 0 ▶ if (-d $lib) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $lib) 0 0 0
81 0 info "adding source lib $lib to \@INC";
82 0 $source_lib = qq[-Mlib="$lib"];
83 0 last;
84 }
85 }
86 }
87  
88 0 my $cmd = qq[$^X $source_lib $file];
89  
90 0 my $h = Symbol::gensym();
91 0 ▶ open $h, "$cmd|" or die "open $cmd: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $h, "$cmd|" or die "open ${cmd}: $!" 0 0 0
92  
93 0 local $_;
94 0 ▶ while (<$h>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $h)) 0 0 0
95 0 ▶ if (/^1\.\.(\d)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^1\.\.(\d)/) 0 0 0
96 0 $ran = $1;
97 0 last;
98 }
99 }
100  
101 0 close $h;
102  
103 0 $ran;
104 }
105 }
106  
107 #if a directory has an all.t test
108 #skip all tests in that directory if all.t prints "1..0\n"
109 1 ▶sub prune {
Subroutine prune: not called CC=7 SCAR=39.2
Pod undocumented
110 0 my($self, @tests) = @_;
111 0 my(@new_tests, %skip_dirs);
112  
113 0 foreach my $test (@tests) {
114 0 ▶ next if $test =~ /\.#/; # skip temp emacs files
Branch: 1 branch
BranchTrueFalseTotal
if $test =~ /\.#/ 0 0 0
115 0 my $dir = dirname $test;
116 0 ▶ if ($test =~ m:\Wall\.t$:) {
Branch: 2 branches
BranchTrueFalseTotal
if ($test =~ /\Wall\.t$/) { } 0 0 0
elsif (not $skip_dirs{$dir}) { } 0 0 0
117 0 ▶ unless (__PACKAGE__->run_t($test)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (__PACKAGE__->run_t($test)) 0 0 0
118 0 $skip_dirs{$dir} = 1;
119 0 @new_tests = grep { m:\Wall\.t$: ||
120 0 ▶ not $skip_dirs{dirname $_} } @new_tests;
Condition0%0/3
/\Wall\.t$/ || !$skip_dirs{dirname($_)}
l!l&&r!l&&!r
000
MC/DC0%0/2
/\Wall\.t$/ || !$skip_dirs{dirname($_)}
/\Wall\.t$/ !$skip_dirs{dirname($_)}
Truth table0%0/3
A || not(B)
A= /\Wall\.t$/B= !$skip_dirs{dirname($_)}
ABresult
1X1
011
000
121 0 push @new_tests, $test;
122 }
123 }
124 elsif (!$skip_dirs{$dir}) {
125 0 push @new_tests, $test;
126 }
127 }
128  
129 0 @new_tests;
130 }
131  
132 0 ▶sub get_tests {
Subroutine get_tests: not called CC=10 SCAR=47.0
Pod undocumented
133 0 my $self = shift;
134 0 my $args = shift;
135 0 my @tests = ();
136  
137 0 ▶ my $base = -d 't' ? catdir('t', '.') : '.';
Branch: 1 branch
BranchTrueFalseTotal
-d 't' ? : 0 0 0
138  
139 0 ▶ my $ts = $args->{tests} || [];
Condition0%0/2
$args->{'tests'} || []
l!l
00
MC/DC0%0/1
$args->{'tests'} || []
$args->{'tests'}
Truth table0%0/2
A
A= $args->{'tests'}
Aresult
11
00
140  
141 0 ▶ if (@$ts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$ts) { } 0 0 0
142 0 for (@$ts) {
143 0 ▶ if (-d $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $_) { } 0 0 0
144 0 push(@tests, sort <$base/$_/*.t>);
145 }
146 else {
147 0 ▶ $_ .= ".t" unless /\.t$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\.t$/ 0 0 0
148 0 push(@tests, $_);
149 }
150 }
151 }
152 else {
153 0 ▶ if ($args->{tdirs}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'tdirs'}) { } 0 0 0
154 0 push @tests, map { sort <$base/$_/*.t> } @{ $args->{tdirs} };
155 }
156 else {
157 0 ▶ finddepth(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
158 0 ▶ return unless /\.t$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\.t$/ 0 0 0
159 0 my $t = catfile $File::Find::dir, $_;
160 0 my $dotslash = catfile '.', "";
161 0 $t =~ s:^\Q$dotslash::;
162 0 push @tests, $t
163 0 }, $base);
164 0 @tests = sort @tests;
165 }
166 }
167  
168 0 @tests = $self->prune(@tests);
169  
170 0 ▶ if (my $skip = $self->skip) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $skip = $self->skip) 0 0 0
171 # Allow / \ and \\ path delimiters in SKIP file
172 0 $skip =~ s![/\\\\]+![/\\\\]!g;
173  
174 0 @tests = grep { not /(?:$skip)/ } @tests;
175 }
176  
177 0 Apache::TestSort->run(\@tests, $args);
178  
179 #when running 't/TEST t/dir' shell tab completion adds a /
180 #dir//foo output is annoying, fix that.
181 0 s:/+:/:g for @tests;
182  
183 0 return @tests;
184 }
185  
186 0 ▶sub run {
Subroutine run: not called CC=5 SCAR=34.0
Pod undocumented
187 0 my $self = shift;
188 0 ▶ my $args = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
189  
190 0 ▶ $Test::Harness::verbose ||= $args->{verbose};
Condition0%0/3
$Test::Harness::verbose ||= $args->{"verbose"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$Test::Harness::verbose ||= $args->{"verbose"}
$Test::Harness::verbose $args->{"verbose"}
Truth table0%0/3
A ||= B
A= $Test::Harness::verboseB= $args->{"verbose"}
ABresult
1X1
011
000
191  
192 0 ▶ if (my(@subtests) = @{ $args->{subtests} || [] }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@subtests) = @{$args->{"subtests"} or [];}) 0 0 0
Condition0%0/2
$args->{'subtests'} || []
l!l
00
MC/DC0%0/1
$args->{'subtests'} || []
$args->{'subtests'}
Truth table0%0/2
A
A= $args->{'subtests'}
Aresult
11
00
193 0 $ENV{HTTPD_TEST_SUBTESTS} = "@subtests";
194 }
195  
196 0 Test::Harness::runtests($self->get_tests($args, @_));
197 }
198  
199 1 1;
« blib/lib/Apache/TestClient.pm ↑ Summary blib/lib/Apache/TestUtil.pm »