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