lib/Apache/TestSort.pm

filter: Statementstmt 27.7% 10 / 36 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 3 / 6 Podpod 0.0% 0 / 3 totaltotal 21.3% 13 / 61 CC 8 SCAR 28.9
CC
8
Cov
20%
random
30.0
run
20.0
repeat
2.0
CRAP 18.1
« blib/lib/Apache/TestRunPerl.pm ↑ Summary blib/lib/Apache/TestRunPHP.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::TestSort;
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 1 ▶use Apache::TestTrace;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 0 ▶sub repeat {
Subroutine repeat: not called CC=1 SCAR=6.9
Pod undocumented
23 0 my($list) = @_;
24 0 return @{$list};
25 }
26  
27 0 ▶sub random {
Subroutine random: not called CC=5 SCAR=34.0
Pod undocumented
28 0 my($list) = @_;
29  
30 0 ▶ my $seed = $ENV{APACHE_TEST_SEED} || '';
Condition0%0/2
$ENV{'APACHE_TEST_SEED'} || ''
l!l
00
MC/DC0%0/1
$ENV{'APACHE_TEST_SEED'} || ''
$ENV{'APACHE_TEST_SEED'}
Truth table0%0/2
A
A= $ENV{'APACHE_TEST_SEED'}
Aresult
11
00
31 0 my $info = "";
32  
33 0 ▶ if ($seed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seed) { } 0 0 0
34 0 $info = " (user defined)";
35 # so we could reproduce the order
36 }
37 else {
38 0 $info = " (autogenerated)";
39 0 $seed = time ^ ($$ + ($$ << 15));
40 }
41  
42 0 warning "Using random number seed: $seed" . $info;
43  
44 0 srand($seed);
45  
46 #from perlfaq4.pod
47 0 ▶ for (my $i = @$list; --$i; ) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$i) 0 0 0
48 0 my $j = int rand($i+1);
49 0 ▶ next if $i == $j;
Branch: 1 branch
BranchTrueFalseTotal
if $i == $j 0 0 0
50 0 @$list[$i,$j] = @$list[$j,$i];
51 }
52 }
53  
54 0 ▶sub run {
Subroutine run: not called CC=4 SCAR=30.0
Pod undocumented
55 0 my($self, $list, $args) = @_;
56  
57 0 ▶ my $order = $args->{order} || 'repeat';
Condition0%0/2
$args->{'order'} || 'repeat'
l!l
00
MC/DC0%0/1
$args->{'order'} || 'repeat'
$args->{'order'}
Truth table0%0/2
A
A= $args->{'order'}
Aresult
11
00
58 0 ▶ if ($order =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($order =~ /^\d+$/) 0 0 0
59 #dont want an explicit -seed option but env var can be a pain
60 #so if -order is number assume it is the random seed
61 0 $ENV{APACHE_TEST_SEED} = $order;
62 0 $order = 'random';
63 }
64 0 my $sort = \&{$order};
65  
66 # re-shuffle the list according to the requested order
67 0 ▶ if (defined &$sort) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &$sort) { } 0 0 0
68 0 $sort->($list);
69 }
70 else {
71 0 error "unknown order '$order'";
72 }
73  
74 }
75  
76 1 1;
« blib/lib/Apache/TestRunPerl.pm ↑ Summary blib/lib/Apache/TestRunPHP.pm »