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
|
|
13
|
use Test::Builder; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
1991
|
|
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
|
|
42
|
my $iOK = shift || 0; |
36
|
19
|
|
50
|
|
|
32
|
my $sName = shift || q{}; |
37
|
19
|
|
50
|
|
|
28
|
my $sDiag = shift || q{}; |
38
|
19
|
50
|
|
|
|
30
|
if ($iOK) |
39
|
|
|
|
|
|
|
{ |
40
|
19
|
|
|
|
|
48
|
$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
|
|
7
|
my $sDir = shift; |
52
|
4
|
|
33
|
|
|
19
|
my $sName = shift || "$dir $sDir exists"; |
53
|
4
|
|
|
|
|
56
|
my $iOK = -d $sDir; |
54
|
4
|
|
|
|
|
14
|
_declare($iOK, $sName, qq{$directory [$sDir] does not exist}); |
55
|
|
|
|
|
|
|
} # _dir_exists_ok |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _dir_not_exists_ok |
58
|
|
|
|
|
|
|
{ |
59
|
2
|
|
|
2
|
|
4
|
my $sDir = shift; |
60
|
2
|
|
33
|
|
|
9
|
my $sName = shift || "$dir $sDir does not exist"; |
61
|
2
|
|
|
|
|
12
|
my $iOK = ! -d $sDir; |
62
|
2
|
|
|
|
|
6
|
_declare($iOK, $sName, qq{$directory [$sDir] does not exist}); |
63
|
|
|
|
|
|
|
} # _dir_not_exists_ok |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _dir_empty_ok |
66
|
|
|
|
|
|
|
{ |
67
|
2
|
|
|
2
|
|
3
|
my $sDir = shift; |
68
|
2
|
|
33
|
|
|
10
|
my $sName = shift || "$dir $sDir is empty"; |
69
|
2
|
|
33
|
|
|
27
|
my $iOK = -d $sDir && _dir_is_empty($sDir); |
70
|
2
|
|
|
|
|
26
|
_declare($iOK, $sName, qq{$directory [$sDir] is not empty}); |
71
|
|
|
|
|
|
|
} # _dir_empty_ok |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _dir_not_empty_ok |
74
|
|
|
|
|
|
|
{ |
75
|
2
|
|
|
2
|
|
3
|
my $sDir = shift; |
76
|
2
|
|
33
|
|
|
11
|
my $sName = shift || "$dir $sDir is not empty"; |
77
|
2
|
|
33
|
|
|
35
|
my $iOK = -d $sDir && ! _dir_is_empty($sDir); |
78
|
2
|
|
|
|
|
8
|
_declare($iOK, $sName, qq{$directory [$sDir] is empty}); |
79
|
|
|
|
|
|
|
} # _dir_empty_ok |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _dir_is_empty |
82
|
|
|
|
|
|
|
{ |
83
|
4
|
|
50
|
4
|
|
11
|
my $path = shift || return; |
84
|
4
|
|
|
|
|
5
|
my $iRet = 1; |
85
|
4
|
50
|
|
|
|
59
|
opendir DIR, $path or die; |
86
|
|
|
|
|
|
|
READDIR: |
87
|
4
|
|
|
|
|
22
|
while (my $entry = readdir DIR) |
88
|
|
|
|
|
|
|
{ |
89
|
10
|
100
|
|
|
|
45
|
next READDIR if ($entry =~ m/\A\.\.?\z/); |
90
|
2
|
|
|
|
|
2
|
$iRet = 0; |
91
|
2
|
|
|
|
|
3
|
last READDIR; |
92
|
|
|
|
|
|
|
} # while |
93
|
4
|
|
|
|
|
17
|
closedir DIR; |
94
|
4
|
|
|
|
|
15
|
return $iRet; |
95
|
|
|
|
|
|
|
} # _dir_is_empty |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _dir_readable_ok |
98
|
|
|
|
|
|
|
{ |
99
|
2
|
|
|
2
|
|
4
|
my $sDir = shift; |
100
|
2
|
|
33
|
|
|
12
|
my $sName = shift || "$dir $sDir is readable"; |
101
|
2
|
|
33
|
|
|
47
|
my $iOK = -d $sDir && -r $sDir; |
102
|
2
|
|
|
|
|
9
|
_declare($iOK, $sName, qq{$directory [$sDir] is not readable}); |
103
|
|
|
|
|
|
|
} # _dir_readable_ok |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _dir_not_readable_ok |
106
|
|
|
|
|
|
|
{ |
107
|
1
|
|
|
1
|
|
2
|
my $sDir = shift; |
108
|
1
|
|
33
|
|
|
6
|
my $sName = shift || "$dir $sDir is not readable"; |
109
|
1
|
|
33
|
|
|
19
|
my $iOK = -d $sDir && ! -r $sDir; |
110
|
1
|
|
|
|
|
3
|
_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
|
|
|
14
|
my $sName = shift || "$dir $sDir is writable"; |
117
|
2
|
|
33
|
|
|
48
|
my $iOK = -d $sDir && -w $sDir; |
118
|
2
|
|
|
|
|
12
|
_declare($iOK, $sName, qq{$directory [$sDir] is not writable}); |
119
|
|
|
|
|
|
|
} # _dir_writable_ok |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _dir_not_writable_ok |
122
|
|
|
|
|
|
|
{ |
123
|
1
|
|
|
1
|
|
2
|
my $sDir = shift; |
124
|
1
|
|
33
|
|
|
7
|
my $sName = shift || "$dir $sDir is not writable"; |
125
|
1
|
|
33
|
|
|
24
|
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
|
|
4
|
my $sDir = shift; |
132
|
2
|
|
33
|
|
|
14
|
my $sName = shift || "$dir $sDir is executable"; |
133
|
2
|
|
33
|
|
|
62
|
my $iOK = -d $sDir && -x $sDir; |
134
|
2
|
|
|
|
|
9
|
_declare($iOK, $sName, qq{$directory [$sDir] is not executable}); |
135
|
|
|
|
|
|
|
} # _dir_executable_ok |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub _dir_not_executable_ok |
138
|
|
|
|
|
|
|
{ |
139
|
1
|
|
|
1
|
|
2
|
my $sDir = shift; |
140
|
1
|
|
33
|
|
|
13
|
my $sName = shift || "$dir $sDir is not executable"; |
141
|
1
|
|
33
|
|
|
15
|
my $iOK = -d $sDir && ! -x $sDir; |
142
|
1
|
|
|
|
|
4
|
_declare($iOK, $sName, qq{$directory [$sDir] is executable}); |
143
|
|
|
|
|
|
|
} # _dir_not_executable_ok |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__END__ |