line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Dirs; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
238513
|
use warnings; |
|
3
|
|
|
|
|
29
|
|
|
3
|
|
|
|
|
114
|
|
4
|
3
|
|
|
3
|
|
19
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
128
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
16
|
use base 'Exporter'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
551
|
|
9
|
|
|
|
|
|
|
our @EXPORT = qw( |
10
|
|
|
|
|
|
|
temp_copy_ok |
11
|
|
|
|
|
|
|
is_dir |
12
|
|
|
|
|
|
|
dir_cleanup_ok |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
2410
|
use File::Temp; |
|
3
|
|
|
|
|
70338
|
|
|
3
|
|
|
|
|
247
|
|
16
|
3
|
|
|
3
|
|
29
|
use Test::Builder; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
77
|
|
17
|
3
|
|
|
3
|
|
1756
|
use File::Copy::Recursive 'dircopy'; |
|
3
|
|
|
|
|
21837
|
|
|
3
|
|
|
|
|
313
|
|
18
|
3
|
|
|
3
|
|
34
|
use Carp 'confess'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
157
|
|
19
|
3
|
|
|
3
|
|
1829
|
use File::DirCompare; |
|
3
|
|
|
|
|
12285
|
|
|
3
|
|
|
|
|
122
|
|
20
|
3
|
|
|
3
|
|
1988
|
use List::MoreUtils 'any'; |
|
3
|
|
|
|
|
42487
|
|
|
3
|
|
|
|
|
24
|
|
21
|
3
|
|
|
3
|
|
5472
|
use Text::Diff 'diff'; |
|
3
|
|
|
|
|
27746
|
|
|
3
|
|
|
|
|
277
|
|
22
|
3
|
|
|
3
|
|
1864
|
use Path::Class; |
|
3
|
|
|
|
|
62877
|
|
|
3
|
|
|
|
|
248
|
|
23
|
3
|
|
|
3
|
|
33
|
use File::Path 2.07 'remove_tree'; |
|
3
|
|
|
|
|
87
|
|
|
3
|
|
|
|
|
2897
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $test = Test::Builder->new; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub temp_copy_ok { |
28
|
3
|
50
|
|
3
|
1
|
462
|
my $src_dir = shift or confess 'pass source folder as argument'; |
29
|
3
|
|
66
|
|
|
21
|
my $message = shift || 'copy of '.$src_dir; |
30
|
|
|
|
|
|
|
|
31
|
3
|
50
|
|
|
|
82
|
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
|
|
|
|
|
38
|
my $dst_dir = File::Temp->newdir(); |
37
|
3
|
50
|
|
|
|
2071
|
dircopy($src_dir, $dst_dir->dirname) |
38
|
|
|
|
|
|
|
or die 'failed to copy '.$src_dir.' to temp folder '.$dst_dir.' '.$!; |
39
|
3
|
|
|
|
|
9041
|
$test->ok(1, $message); |
40
|
|
|
|
|
|
|
|
41
|
3
|
|
|
|
|
1741
|
return $dst_dir; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub is_dir { |
45
|
11
|
50
|
|
11
|
1
|
25467
|
my $dir1 = shift or confess 'pass folders as argument'; |
46
|
11
|
50
|
|
|
|
65
|
my $dir2 = shift or confess 'pass two folders as argument'; |
47
|
11
|
|
66
|
|
|
82
|
my $message = shift || 'cmp '.$dir1.' with '.$dir2; |
48
|
11
|
|
100
|
|
|
74
|
my $ignore_ref = shift || []; |
49
|
11
|
|
|
|
|
22
|
my $verbose = shift; |
50
|
|
|
|
|
|
|
|
51
|
11
|
50
|
|
|
|
51
|
if ( $ENV{FIXIT} ) { |
52
|
0
|
0
|
|
|
|
0
|
dircopy( $dir1, $dir2 ) |
53
|
|
|
|
|
|
|
or die 'failed to copy ' |
54
|
|
|
|
|
|
|
. $dir1 |
55
|
|
|
|
|
|
|
. ' to temp folder ' |
56
|
|
|
|
|
|
|
. $dir2 . ' ' |
57
|
|
|
|
|
|
|
. $!; |
58
|
0
|
|
|
|
|
0
|
$test->ok( 1, 'FIXIT: ' . $message ); |
59
|
0
|
|
|
|
|
0
|
return; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
11
|
|
|
|
|
28
|
my @ignore_files = @{$ignore_ref}; |
|
11
|
|
|
|
|
30
|
|
63
|
11
|
|
|
|
|
23
|
my @differences; |
64
|
|
|
|
|
|
|
File::DirCompare->compare($dir1, $dir2, sub { |
65
|
23
|
|
|
23
|
|
9817
|
my ($a, $b) = @_; |
66
|
23
|
|
|
|
|
42
|
my ($a_short, $b_short); |
67
|
|
|
|
|
|
|
|
68
|
23
|
100
|
|
|
|
96
|
if ($a) { |
69
|
16
|
|
|
|
|
39
|
$a_short = substr($a, length($dir1)+1); |
70
|
16
|
100
|
|
|
|
104
|
return if any { $_ eq $a_short } @ignore_files; |
|
36
|
|
|
|
|
87
|
|
71
|
|
|
|
|
|
|
} |
72
|
14
|
100
|
|
|
|
51
|
if ($b) { |
73
|
13
|
|
|
|
|
31
|
$b_short = substr($b, length($dir2)+1); |
74
|
13
|
100
|
|
|
|
95
|
return if any { $_ eq $b_short } @ignore_files; |
|
17
|
|
|
|
|
53
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
9
|
100
|
|
|
|
37
|
if (not $b) { |
|
|
100
|
|
|
|
|
|
78
|
1
|
|
|
|
|
8
|
push @differences, 'Only in '.$dir1.': '.$a_short; |
79
|
|
|
|
|
|
|
} elsif (not $a) { |
80
|
2
|
|
|
|
|
9
|
push @differences, 'Only in '.$dir2.': '.$b_short; |
81
|
|
|
|
|
|
|
} else { |
82
|
6
|
|
|
|
|
24
|
push @differences, 'File "'.$a_short.'" differ'; |
83
|
6
|
100
|
|
|
|
21
|
if ($verbose) { |
84
|
2
|
50
|
66
|
|
|
84
|
if (-f $a and -d $b) { |
|
|
100
|
66
|
|
|
|
|
85
|
0
|
|
|
|
|
0
|
push @differences, 'in '.$dir1.' is a regular file while in '.$dir2.' is a directory'; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
elsif (-d $a and -f $b) { |
88
|
1
|
|
|
|
|
10
|
push @differences, 'in '.$dir1.' is a directory while in '.$dir2.' is a regular file'; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else { |
91
|
1
|
|
|
|
|
11
|
push @differences, diff($b, $a); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
11
|
|
|
|
|
164
|
}); |
96
|
|
|
|
|
|
|
|
97
|
11
|
100
|
|
|
|
13400
|
if (not @differences) { |
98
|
7
|
|
|
|
|
59
|
$test->ok(1, $message); |
99
|
7
|
|
|
|
|
2824
|
return; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
4
|
|
|
|
|
63
|
$test->ok(0, $message); |
103
|
4
|
|
|
|
|
3296
|
foreach my $difference (@differences) { |
104
|
11
|
|
|
|
|
1016
|
$test->diag($difference); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub dir_cleanup_ok { |
109
|
2
|
50
|
|
2
|
1
|
211
|
my $filename = shift or confess 'pass filename as argument'; |
110
|
2
|
|
|
|
|
4
|
my $message = shift; |
111
|
|
|
|
|
|
|
|
112
|
2
|
50
|
|
|
|
7
|
$filename = File::Spec->catfile(@{$filename}) |
|
2
|
|
|
|
|
13
|
|
113
|
|
|
|
|
|
|
if (ref $filename eq 'ARRAY'); |
114
|
2
|
100
|
|
|
|
58
|
if (-f $filename) { |
115
|
1
|
|
|
|
|
7
|
$filename = file($filename)->dir->stringify; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
2
|
|
33
|
|
|
269
|
$message ||= 'cleaning up '.$filename.' folder and all empty folders up'; |
119
|
|
|
|
|
|
|
|
120
|
2
|
|
|
|
|
4
|
my $removed_filenames; |
121
|
|
|
|
|
|
|
my $rm_err; |
122
|
2
|
|
|
|
|
712
|
remove_tree($filename, {result => \$removed_filenames, keep_root => 1, error => \$rm_err}); |
123
|
2
|
50
|
|
|
|
13
|
if (@{$rm_err}) { |
|
2
|
|
|
|
|
7
|
|
124
|
0
|
|
|
|
|
0
|
$test->ok(0, $message); |
125
|
0
|
|
|
|
|
0
|
$test->diag("Error:\n", @{$rm_err}); |
|
0
|
|
|
|
|
0
|
|
126
|
0
|
|
|
|
|
0
|
return; |
127
|
|
|
|
|
|
|
} |
128
|
2
|
|
|
|
|
3
|
@{$removed_filenames} = map { File::Spec->catfile($filename, $_)."\n" } @{$removed_filenames}; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
38
|
|
|
2
|
|
|
|
|
4
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# remove the file folder and all empty folders upwards |
131
|
2
|
|
|
|
|
102
|
while (rmdir $filename) { |
132
|
3
|
|
|
|
|
166
|
push @{$removed_filenames}, $filename."\n"; |
|
3
|
|
|
|
|
14
|
|
133
|
3
|
|
|
|
|
14
|
$filename = file($filename)->parent->stringify; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
2
|
|
|
|
|
281
|
$test->ok(1, $message); |
137
|
2
|
|
|
|
|
921
|
$test->diag("Removed:\n", @{$removed_filenames}); |
|
2
|
|
|
|
|
15
|
|
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
'A car is not merely a faster horse.'; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
__END__ |