test/lib/RandomFileMethodBase.pm

filter: Statementstmt 100% 49 / 49 Branchbran 66.6% 4 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 5 totaltotal 86.0% 68 / 79 SCAR 19.5
CC
7
Cov
93%
_remove_cvs_files
4.8
expected_files_found_ok
2.0
sample
2.0
CRAP 7.0
« test/lib/RandomLine.pm ↑ Summary test/lib/RandomFileMethodAllTests.pm »
1 package
2 RandomFileMethodBase;
3 1 ▶use base qw/Test::Class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use TestConstants;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Test::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Set::Scalar;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use File::Random;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub expected_files_found_ok {
16 122 ▶ my ($self, $exp_files, $args, $testname) = @_;
Subroutine expected_files_found_ok: called CC=2 SCAR=7.0
Pod undocumented
17 122 my $exp = Set::Scalar->new(@$exp_files);
18 122 my $found = Set::Scalar->new( grep defined, $self->sample(@$args) );
19
20 122 _remove_cvs_files( $found );
21 122 ▶ is $found, $exp, $testname
Branch: 1 branch
BranchTrueFalseTotal
&is($found, $exp, $testname) or diag("found: $found", "expected $exp", 'called with ' . join(", ", @$args)) 0 122 122
22 or diag "found: $found",
23 "expected $exp",
24 "called with " . join (", " => @$args);
25 }
26  
27 # I use a CVS System at home,
28 # so there are always some files more than needed
29 # that's why I delete them from the found files
30 sub _remove_cvs_files($) {
31 122 ▶ my $f = shift;
Subroutine _remove_cvs_files: called CC=4 SCAR=15.8
32 122 foreach ($f->members) {
33 728 ▶ $f->delete($_) if defined($_) && ($_ =~ /Repository|CVS|Entries|Root/);
Branch: 1 branch
BranchTrueFalseTotal
if defined $_ and $_ =~ /Repository|CVS|Entries|Root/ 0 728 728
Condition33%1/3
defined $_ and $_ =~ /Repository|CVS|Entries|Root/
!ll&&!rl&&r
07280
MC/DC0%0/2
defined $_ and $_ =~ /Repository|CVS|Entries|Root/
defined $_ $_ =~ /Repository|CVS|Entries|Root/
Truth table33%1/3
A and B
A= defined $_B= $_ =~ /Repository|CVS|Entries|Root/
ABresult
0X0
100
111
34 }
35 }
36  
37 sub sample {
38 134 ▶ my ($self, %arg) = @_;
Subroutine sample: called CC=2 SCAR=6.9
Pod undocumented
39 134 my @sample;
40 134 push @sample, $self->call_random_file(%arg) for (1 .. SAMPLE_SIZE);
41 134 return @sample;
42 }
43  
44 # Methods for overwriting -
45 # from practical reasons I didn't want to use the underscore _random_file
46 sub random_file {
47 18060 ▶ my ($self, @args) = @_;
Subroutine random_file: called CC=1 SCAR=0.0
Pod undocumented
48 18060 return File::Random::random_file(@args);
49 }
50  
51 sub content_of_random_file {
52 18560 ▶ my ($self, @args) = @_;
Subroutine content_of_random_file: called CC=1 SCAR=0.0
Pod undocumented
53 18560 return File::Random::content_of_random_file(@args);
54 }
55  
56 sub call_random_file {
57 33500 ▶ my ($self, %arg) = @_;
Subroutine call_random_file: called CC=2 SCAR=6.9
Pod undocumented
58
59 33500 my ($path, $home) = @arg{'-path', '-home'};
60 33500 delete @arg{'-path', '-home'};
61  
62 # either we know the directory directly
63 33500 ▶ return $self->random_file(%arg) if $arg{-dir};
Branch: 1 branch
BranchTrueFalseTotal
if $arg{"-dir"} 30500 3000 33500
64  
65 # or have to go to the path itself
66 3000 chdir $path;
67 3000 my $rf = $self->random_file(%arg);
68 3000 chdir $home;
69 3000 return $rf;
70 }
71  
72  
73 1 1;
« test/lib/RandomLine.pm ↑ Summary test/lib/RandomFileMethodAllTests.pm »