| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Test::Dirs; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
214781
|
use warnings; |
|
|
3
|
|
|
|
|
20
|
|
|
|
3
|
|
|
|
|
91
|
|
|
4
|
3
|
|
|
3
|
|
14
|
use strict; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
101
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
14
|
use base 'Exporter'; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
455
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT = qw( |
|
10
|
|
|
|
|
|
|
temp_copy_ok |
|
11
|
|
|
|
|
|
|
is_dir |
|
12
|
|
|
|
|
|
|
dir_cleanup_ok |
|
13
|
|
|
|
|
|
|
); |
|
14
|
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
2185
|
use File::Temp; |
|
|
3
|
|
|
|
|
60801
|
|
|
|
3
|
|
|
|
|
193
|
|
|
16
|
3
|
|
|
3
|
|
22
|
use Test::Builder; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
61
|
|
|
17
|
3
|
|
|
3
|
|
1456
|
use File::Copy::Recursive 'dircopy'; |
|
|
3
|
|
|
|
|
19428
|
|
|
|
3
|
|
|
|
|
195
|
|
|
18
|
3
|
|
|
3
|
|
28
|
use Carp 'confess'; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
114
|
|
|
19
|
3
|
|
|
3
|
|
1534
|
use File::DirCompare; |
|
|
3
|
|
|
|
|
11064
|
|
|
|
3
|
|
|
|
|
94
|
|
|
20
|
3
|
|
|
3
|
|
1838
|
use List::MoreUtils 'any'; |
|
|
3
|
|
|
|
|
36895
|
|
|
|
3
|
|
|
|
|
18
|
|
|
21
|
3
|
|
|
3
|
|
4899
|
use Text::Diff 'diff'; |
|
|
3
|
|
|
|
|
25082
|
|
|
|
3
|
|
|
|
|
183
|
|
|
22
|
3
|
|
|
3
|
|
1453
|
use Path::Class; |
|
|
3
|
|
|
|
|
54798
|
|
|
|
3
|
|
|
|
|
195
|
|
|
23
|
3
|
|
|
3
|
|
24
|
use File::Path 2.07 'remove_tree'; |
|
|
3
|
|
|
|
|
67
|
|
|
|
3
|
|
|
|
|
2322
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $test = Test::Builder->new; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub temp_copy_ok { |
|
28
|
3
|
50
|
|
3
|
1
|
370
|
my $src_dir = shift or confess 'pass source folder as argument'; |
|
29
|
3
|
|
66
|
|
|
19
|
my $message = shift || 'copy of '.$src_dir; |
|
30
|
|
|
|
|
|
|
|
|
31
|
3
|
50
|
|
|
|
77
|
if (not -d $src_dir) { |
|
32
|
0
|
|
|
|
|
0
|
$test->ok(0, $message); |
|
33
|
0
|
|
|
|
|
0
|
confess($src_dir.' is not a folder'); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
3
|
|
|
|
|
29
|
my $dst_dir = File::Temp->newdir(); |
|
37
|
3
|
50
|
|
|
|
1869
|
dircopy($src_dir, $dst_dir->dirname) |
|
38
|
|
|
|
|
|
|
or die 'failed to copy '.$src_dir.' to temp folder '.$dst_dir.' '.$!; |
|
39
|
3
|
|
|
|
|
8173
|
$test->ok(1, $message); |
|
40
|
|
|
|
|
|
|
|
|
41
|
3
|
|
|
|
|
1458
|
return $dst_dir; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub is_dir { |
|
45
|
11
|
50
|
|
11
|
1
|
22979
|
my $dir1 = shift or confess 'pass folders as argument'; |
|
46
|
11
|
50
|
|
|
|
49
|
my $dir2 = shift or confess 'pass two folders as argument'; |
|
47
|
11
|
|
66
|
|
|
78
|
my $message = shift || 'cmp '.$dir1.' with '.$dir2; |
|
48
|
11
|
|
100
|
|
|
67
|
my $ignore_ref = shift || []; |
|
49
|
11
|
|
|
|
|
18
|
my $verbose = shift; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$verbose = $ENV{TEST_VERBOSE} |
|
52
|
11
|
100
|
|
|
|
36
|
unless defined($verbose); |
|
53
|
|
|
|
|
|
|
|
|
54
|
11
|
50
|
|
|
|
33
|
if ( $ENV{FIXIT} ) { |
|
55
|
0
|
0
|
|
|
|
0
|
dircopy( $dir1, $dir2 ) |
|
56
|
|
|
|
|
|
|
or die 'failed to copy ' |
|
57
|
|
|
|
|
|
|
. $dir1 |
|
58
|
|
|
|
|
|
|
. ' to temp folder ' |
|
59
|
|
|
|
|
|
|
. $dir2 . ' ' |
|
60
|
|
|
|
|
|
|
. $!; |
|
61
|
0
|
|
|
|
|
0
|
$test->ok( 1, 'FIXIT: ' . $message ); |
|
62
|
0
|
|
|
|
|
0
|
return; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
11
|
|
33
|
|
|
261
|
my $have_two_folders = -d $dir1 && -d $dir2; |
|
66
|
11
|
50
|
|
|
|
199
|
unless ($have_two_folders) { |
|
67
|
0
|
|
|
|
|
0
|
$test->ok( -d $dir2, 'expected-param "' . $dir2 . '" is directory' ); |
|
68
|
0
|
|
|
|
|
0
|
$test->ok( -d $dir1, 'is-param "' . $dir1 . '" is directory' ); |
|
69
|
0
|
|
|
|
|
0
|
return; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
11
|
|
|
|
|
18
|
my @ignore_files = @{$ignore_ref}; |
|
|
11
|
|
|
|
|
35
|
|
|
73
|
11
|
|
|
|
|
15
|
my @differences; |
|
74
|
|
|
|
|
|
|
File::DirCompare->compare($dir1, $dir2, sub { |
|
75
|
23
|
|
|
23
|
|
8935
|
my ($a, $b) = @_; |
|
76
|
23
|
|
|
|
|
40
|
my ($a_short, $b_short); |
|
77
|
|
|
|
|
|
|
|
|
78
|
23
|
100
|
|
|
|
54
|
if ($a) { |
|
79
|
16
|
|
|
|
|
36
|
$a_short = substr($a, length($dir1)+1); |
|
80
|
16
|
100
|
|
|
|
87
|
return if any { $_ eq $a_short } @ignore_files; |
|
|
36
|
|
|
|
|
93
|
|
|
81
|
|
|
|
|
|
|
} |
|
82
|
14
|
100
|
|
|
|
37
|
if ($b) { |
|
83
|
13
|
|
|
|
|
28
|
$b_short = substr($b, length($dir2)+1); |
|
84
|
13
|
100
|
|
|
|
79
|
return if any { $_ eq $b_short } @ignore_files; |
|
|
17
|
|
|
|
|
47
|
|
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
9
|
100
|
|
|
|
33
|
if (not $b) { |
|
|
|
100
|
|
|
|
|
|
|
88
|
1
|
|
|
|
|
5
|
push @differences, 'Only in '.$dir1.': '.$a_short; |
|
89
|
|
|
|
|
|
|
} elsif (not $a) { |
|
90
|
2
|
|
|
|
|
9
|
push @differences, 'Only in '.$dir2.': '.$b_short; |
|
91
|
|
|
|
|
|
|
} else { |
|
92
|
6
|
|
|
|
|
19
|
push @differences, 'File "'.$a_short.'" differ'; |
|
93
|
6
|
100
|
|
|
|
18
|
if ($verbose) { |
|
94
|
2
|
50
|
66
|
|
|
87
|
if (-f $a and -d $b) { |
|
|
|
100
|
66
|
|
|
|
|
|
95
|
0
|
|
|
|
|
0
|
push @differences, 'in '.$dir1.' is a regular file while in '.$dir2.' is a directory'; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
elsif (-d $a and -f $b) { |
|
98
|
1
|
|
|
|
|
8
|
push @differences, 'in '.$dir1.' is a directory while in '.$dir2.' is a regular file'; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
else { |
|
101
|
1
|
|
|
|
|
8
|
push @differences, diff($b, $a); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
} |
|
105
|
11
|
|
|
|
|
136
|
}); |
|
106
|
|
|
|
|
|
|
|
|
107
|
11
|
100
|
|
|
|
11811
|
if (not @differences) { |
|
108
|
7
|
|
|
|
|
50
|
$test->ok(1, $message); |
|
109
|
7
|
|
|
|
|
2510
|
return; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
4
|
|
|
|
|
31
|
$test->ok(0, $message); |
|
113
|
4
|
|
|
|
|
2619
|
foreach my $difference (@differences) { |
|
114
|
11
|
|
|
|
|
1035
|
$test->diag($difference); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub dir_cleanup_ok { |
|
119
|
2
|
50
|
|
2
|
1
|
172
|
my $filename = shift or confess 'pass filename as argument'; |
|
120
|
2
|
|
|
|
|
3
|
my $message = shift; |
|
121
|
|
|
|
|
|
|
|
|
122
|
2
|
50
|
|
|
|
6
|
$filename = File::Spec->catfile(@{$filename}) |
|
|
2
|
|
|
|
|
9
|
|
|
123
|
|
|
|
|
|
|
if (ref $filename eq 'ARRAY'); |
|
124
|
2
|
100
|
|
|
|
51
|
if (-f $filename) { |
|
125
|
1
|
|
|
|
|
5
|
$filename = file($filename)->dir->stringify; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
2
|
|
33
|
|
|
221
|
$message ||= 'cleaning up '.$filename.' folder and all empty folders up'; |
|
129
|
|
|
|
|
|
|
|
|
130
|
2
|
|
|
|
|
3
|
my $removed_filenames; |
|
131
|
|
|
|
|
|
|
my $rm_err; |
|
132
|
2
|
|
|
|
|
603
|
remove_tree($filename, {result => \$removed_filenames, keep_root => 1, error => \$rm_err}); |
|
133
|
2
|
50
|
|
|
|
10
|
if (@{$rm_err}) { |
|
|
2
|
|
|
|
|
5
|
|
|
134
|
0
|
|
|
|
|
0
|
$test->ok(0, $message); |
|
135
|
0
|
|
|
|
|
0
|
$test->diag("Error:\n", @{$rm_err}); |
|
|
0
|
|
|
|
|
0
|
|
|
136
|
0
|
|
|
|
|
0
|
return; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
2
|
|
|
|
|
4
|
@{$removed_filenames} = map { File::Spec->catfile($filename, $_)."\n" } @{$removed_filenames}; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
21
|
|
|
|
2
|
|
|
|
|
3
|
|
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# remove the file folder and all empty folders upwards |
|
141
|
2
|
|
|
|
|
89
|
while (rmdir $filename) { |
|
142
|
3
|
|
|
|
|
136
|
push @{$removed_filenames}, $filename."\n"; |
|
|
3
|
|
|
|
|
13
|
|
|
143
|
3
|
|
|
|
|
11
|
$filename = file($filename)->parent->stringify; |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
2
|
|
|
|
|
266
|
$test->ok(1, $message); |
|
147
|
2
|
|
|
|
|
729
|
$test->diag("Removed:\n", @{$removed_filenames}); |
|
|
2
|
|
|
|
|
11
|
|
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
'A car is not merely a faster horse.'; |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
__END__ |