File Coverage

test/lib/RandomFileMethodBase.pm
Criterion Covered Total %
statement 48 48 100.0
branch 4 6 66.6
condition 1 3 33.3
subroutine 14 14 100.0
pod 0 5 0.0
total 67 76 88.1


line stmt bran cond sub pod time code
1             package RandomFileMethodBase;
2 1     1   8 use base qw/Test::Class/;
  1         1  
  1         92  
3 1     1   343 use TestConstants;
  1         11  
  1         158  
4              
5 1     1   7 use strict;
  1         2  
  1         40  
6 1     1   6 use warnings;
  1         2  
  1         51  
7              
8 1     1   6 use Test::More;
  1         1  
  1         21  
9 1     1   609 use Test::Exception;
  1         2  
  1         21  
10 1     1   408 use Set::Scalar;
  1         2  
  1         59  
11              
12 1     1   7 use File::Random;
  1         2  
  1         613  
13              
14             sub expected_files_found_ok {
15 122     122 0 6074 my ($self, $exp_files, $args, $testname) = @_;
16 122         514 my $exp = Set::Scalar->new(@$exp_files);
17 122         12942 my $found = Set::Scalar->new( grep defined, $self->sample(@$args) );
18            
19 122         125312 _remove_cvs_files( $found );
20 122 50       1105 is $found, $exp, $testname
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     122   255 my $f = shift;
31 122         591 foreach ($f->members) {
32 728 50 33     4241 $f->delete($_) if defined($_) && ($_ =~ /Repository|CVS|Entries|Root/);
33             }
34             }
35              
36             sub sample {
37 134     134 0 635 my ($self, %arg) = @_;
38 134         204 my @sample;
39 134         740 push @sample, $self->call_random_file(%arg) for (1 .. SAMPLE_SIZE);
40 134         15770 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     18060 0 33959 my ($self, @args) = @_;
47 18060         35830 return File::Random::random_file(@args);
48             }
49              
50             sub content_of_random_file {
51 18560     18560 0 38419 my ($self, @args) = @_;
52 18560         40024 return File::Random::content_of_random_file(@args);
53             }
54              
55             sub call_random_file {
56 33500     33500 0 96968 my ($self, %arg) = @_;
57            
58 33500         62835 my ($path, $home) = @arg{'-path', '-home'};
59 33500         57278 delete @arg{'-path', '-home'};
60              
61             # either we know the directory directly
62 33500 100       109720 return $self->random_file(%arg) if $arg{-dir};
63              
64             # or have to go to the path itself
65 3000         25505 chdir $path;
66 3000         11702 my $rf = $self->random_file(%arg);
67 3000         28857 chdir $home;
68 3000         21964 return $rf;
69             }
70              
71              
72             1;