line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Test::Dir::Base - support functions for Test::Dir and Test::Folder |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 DESCRIPTION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
This module is not meant to be human-readable. |
9
|
|
|
|
|
|
|
Use Test::Dir or Test::Folder. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 AUTHOR |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Martin 'Kingpin' Thurn, C, L. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package Test::Dir::Base; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our |
20
|
|
|
|
|
|
|
$VERSION = do { my @r = (q$Revision: 1.5 $ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r }; |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
3
|
|
21
|
use Test::Builder; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
2106
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $Test = new Test::Builder; |
25
|
|
|
|
|
|
|
our $directory = q{directory}; |
26
|
|
|
|
|
|
|
our $dir = q{dir}; |
27
|
|
|
|
|
|
|
our $Directory = q{Directory}; |
28
|
|
|
|
|
|
|
our $Dir = q{Dir}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# All functions start with underscore so that Test::Pod::Coverage does |
31
|
|
|
|
|
|
|
# not complain about lack of pod. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _declare |
34
|
|
|
|
|
|
|
{ |
35
|
19
|
|
50
|
19
|
|
57
|
my $iOK = shift || 0; |
36
|
19
|
|
50
|
|
|
46
|
my $sName = shift || q{}; |
37
|
19
|
|
50
|
|
|
43
|
my $sDiag = shift || q{}; |
38
|
19
|
50
|
|
|
|
40
|
if ($iOK) |
39
|
|
|
|
|
|
|
{ |
40
|
19
|
|
|
|
|
59
|
$Test->ok(1, $sName); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else |
43
|
|
|
|
|
|
|
{ |
44
|
0
|
|
|
|
|
0
|
$Test->diag($sDiag); |
45
|
0
|
|
|
|
|
0
|
$Test->ok(0, $sName); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} # _declare |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _dir_exists_ok |
50
|
|
|
|
|
|
|
{ |
51
|
4
|
|
|
4
|
|
8
|
my $sDir = shift; |
52
|
4
|
|
33
|
|
|
20
|
my $sName = shift || "$dir $sDir exists"; |
53
|
4
|
|
|
|
|
46
|
my $iOK = -d $sDir; |
54
|
4
|
|
|
|
|
21
|
_declare($iOK, $sName, qq{$directory [$sDir] does not exist}); |
55
|
|
|
|
|
|
|
} # _dir_exists_ok |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _dir_not_exists_ok |
58
|
|
|
|
|
|
|
{ |
59
|
2
|
|
|
2
|
|
5
|
my $sDir = shift; |
60
|
2
|
|
33
|
|
|
107
|
my $sName = shift || "$dir $sDir does not exist"; |
61
|
2
|
|
|
|
|
15
|
my $iOK = ! -d $sDir; |
62
|
2
|
|
|
|
|
11
|
_declare($iOK, $sName, qq{$directory [$sDir] does not exist}); |
63
|
|
|
|
|
|
|
} # _dir_not_exists_ok |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _dir_empty_ok |
66
|
|
|
|
|
|
|
{ |
67
|
2
|
|
|
2
|
|
6
|
my $sDir = shift; |
68
|
2
|
|
33
|
|
|
11
|
my $sName = shift || "$dir $sDir is empty"; |
69
|
2
|
|
33
|
|
|
30
|
my $iOK = -d $sDir && _dir_is_empty($sDir); |
70
|
2
|
|
|
|
|
18
|
_declare($iOK, $sName, qq{$directory [$sDir] is not empty}); |
71
|
|
|
|
|
|
|
} # _dir_empty_ok |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _dir_not_empty_ok |
74
|
|
|
|
|
|
|
{ |
75
|
2
|
|
|
2
|
|
5
|
my $sDir = shift; |
76
|
2
|
|
33
|
|
|
13
|
my $sName = shift || "$dir $sDir is not empty"; |
77
|
2
|
|
33
|
|
|
37
|
my $iOK = -d $sDir && ! _dir_is_empty($sDir); |
78
|
2
|
|
|
|
|
9
|
_declare($iOK, $sName, qq{$directory [$sDir] is empty}); |
79
|
|
|
|
|
|
|
} # _dir_empty_ok |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _dir_is_empty |
82
|
|
|
|
|
|
|
{ |
83
|
4
|
|
50
|
4
|
|
20
|
my $path = shift || return; |
84
|
4
|
|
|
|
|
7
|
my $iRet = 1; |
85
|
4
|
50
|
|
|
|
59
|
opendir DIR, $path or die; |
86
|
|
|
|
|
|
|
READDIR: |
87
|
4
|
|
|
|
|
28
|
while (my $entry = readdir DIR) |
88
|
|
|
|
|
|
|
{ |
89
|
10
|
100
|
|
|
|
53
|
next READDIR if ($entry =~ m/\A\.\.?\z/); |
90
|
2
|
|
|
|
|
4
|
$iRet = 0; |
91
|
2
|
|
|
|
|
5
|
last READDIR; |
92
|
|
|
|
|
|
|
} # while |
93
|
4
|
|
|
|
|
21
|
closedir DIR; |
94
|
4
|
|
|
|
|
18
|
return $iRet; |
95
|
|
|
|
|
|
|
} # _dir_is_empty |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _dir_readable_ok |
98
|
|
|
|
|
|
|
{ |
99
|
2
|
|
|
2
|
|
6
|
my $sDir = shift; |
100
|
2
|
|
33
|
|
|
19
|
my $sName = shift || "$dir $sDir is readable"; |
101
|
2
|
|
33
|
|
|
43
|
my $iOK = -d $sDir && -r $sDir; |
102
|
2
|
|
|
|
|
13
|
_declare($iOK, $sName, qq{$directory [$sDir] is not readable}); |
103
|
|
|
|
|
|
|
} # _dir_readable_ok |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _dir_not_readable_ok |
106
|
|
|
|
|
|
|
{ |
107
|
1
|
|
|
1
|
|
3
|
my $sDir = shift; |
108
|
1
|
|
33
|
|
|
6
|
my $sName = shift || "$dir $sDir is not readable"; |
109
|
1
|
|
33
|
|
|
21
|
my $iOK = -d $sDir && ! -r $sDir; |
110
|
1
|
|
|
|
|
5
|
_declare($iOK, $sName, qq{$directory [$sDir] is readable}); |
111
|
|
|
|
|
|
|
} # _dir_not_readable_ok |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _dir_writable_ok |
114
|
|
|
|
|
|
|
{ |
115
|
2
|
|
|
2
|
|
5
|
my $sDir = shift; |
116
|
2
|
|
33
|
|
|
12
|
my $sName = shift || "$dir $sDir is writable"; |
117
|
2
|
|
33
|
|
|
37
|
my $iOK = -d $sDir && -w $sDir; |
118
|
2
|
|
|
|
|
10
|
_declare($iOK, $sName, qq{$directory [$sDir] is not writable}); |
119
|
|
|
|
|
|
|
} # _dir_writable_ok |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _dir_not_writable_ok |
122
|
|
|
|
|
|
|
{ |
123
|
1
|
|
|
1
|
|
3
|
my $sDir = shift; |
124
|
1
|
|
33
|
|
|
9
|
my $sName = shift || "$dir $sDir is not writable"; |
125
|
1
|
|
33
|
|
|
26
|
my $iOK = -d $sDir && ! -w $sDir; |
126
|
1
|
|
|
|
|
5
|
_declare($iOK, $sName, qq{$directory [$sDir] is writable}); |
127
|
|
|
|
|
|
|
} # _dir_not_writable_ok |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub _dir_executable_ok |
130
|
|
|
|
|
|
|
{ |
131
|
2
|
|
|
2
|
|
6
|
my $sDir = shift; |
132
|
2
|
|
33
|
|
|
15
|
my $sName = shift || "$dir $sDir is executable"; |
133
|
2
|
|
33
|
|
|
51
|
my $iOK = -d $sDir && -x $sDir; |
134
|
2
|
|
|
|
|
14
|
_declare($iOK, $sName, qq{$directory [$sDir] is not executable}); |
135
|
|
|
|
|
|
|
} # _dir_executable_ok |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub _dir_not_executable_ok |
138
|
|
|
|
|
|
|
{ |
139
|
1
|
|
|
1
|
|
3
|
my $sDir = shift; |
140
|
1
|
|
33
|
|
|
9
|
my $sName = shift || "$dir $sDir is not executable"; |
141
|
1
|
|
33
|
|
|
19
|
my $iOK = -d $sDir && ! -x $sDir; |
142
|
1
|
|
|
|
|
5
|
_declare($iOK, $sName, qq{$directory [$sDir] is executable}); |
143
|
|
|
|
|
|
|
} # _dir_not_executable_ok |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__END__ |