| 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
| |||||||||||||||||||||
| 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")
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")
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | ▶ | return unless -e $file; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 0 | my $fh = Symbol::gensym(); | |||||||||||||||||||
| 47 | 0 | ▶ | open $fh, $file or die "open $file: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 0 | my @skip; | |||||||||||||||||||
| 49 | 0 | local $_; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 0 | ▶ | while (<$fh>) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 0 | chomp; | |||||||||||||||||||
| 53 | 0 | s/^\s+//; s/\s+$//; s/^\#.*//; | |||||||||||||||||||
| 54 | 0 | ▶ | next unless $_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | local $_; | |||||||||||||||||||
| 94 | 0 | ▶ | while (<$h>) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 95 | 0 | ▶ | if (/^1\.\.(\d)/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 115 | 0 | my $dir = dirname $test; | |||||||||||||||||||
| 116 | 0 | ▶ | if ($test =~ m:\Wall\.t$:) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 117 | 0 | ▶ | unless (__PACKAGE__->run_t($test)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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($_)}
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($_)}
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 0 | ▶ | my $ts = $args->{tests} || []; | ||||||||||||||||||
|
Condition0%0/2
$args->{'tests'} || []
MC/DC0%0/1
$args->{'tests'} || []
$args->{'tests'}
Truth table0%0/2
A
A= $args->{'tests'}
| |||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | 0 | ▶ | if (@$ts) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 142 | 0 | for (@$ts) { | |||||||||||||||||||
| 143 | 0 | ▶ | if (-d $_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 144 | 0 | push(@tests, sort <$base/$_/*.t>); | |||||||||||||||||||
| 145 | } | ||||||||||||||||||||
| 146 | else { | ||||||||||||||||||||
| 147 | 0 | ▶ | $_ .= ".t" unless /\.t$/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 148 | 0 | push(@tests, $_); | |||||||||||||||||||
| 149 | } | ||||||||||||||||||||
| 150 | } | ||||||||||||||||||||
| 151 | } | ||||||||||||||||||||
| 152 | else { | ||||||||||||||||||||
| 153 | 0 | ▶ | if ($args->{tdirs}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | 0 | ▶ | $Test::Harness::verbose ||= $args->{verbose}; | ||||||||||||||||||
|
Condition0%0/3
$Test::Harness::verbose ||= $args->{"verbose"}
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"}
| |||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | 0 | ▶ | if (my(@subtests) = @{ $args->{subtests} || [] }) { | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$args->{'subtests'} || []
MC/DC0%0/1
$args->{'subtests'} || []
$args->{'subtests'}
Truth table0%0/2
A
A= $args->{'subtests'}
| |||||||||||||||||||||
| 193 | 0 | $ENV{HTTPD_TEST_SUBTESTS} = "@subtests"; | |||||||||||||||||||
| 194 | } | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | 0 | Test::Harness::runtests($self->get_tests($args, @_)); | |||||||||||||||||||
| 197 | } | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | 1 | 1; | |||||||||||||||||||