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