1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
#!./perl -w
use Test::More tests => 23;
use strict;
require overload;
use File::CheckTree;
use File::Spec; # used to get absolute paths
# We assume that we start from the dist/File-CheckTree in the perl repository,
# or the dist root directory for the CPAN version.
#### TEST 1 -- No warnings ####
# usings both relative and full paths, indented comments
{
my ($num_warnings, $path_to_libFileCheckTree);
$path_to_libFileCheckTree = File::Spec->rel2abs(
File::Spec->catfile('lib', 'File', 'CheckTree.pm'),
);
my @warnings;
local $SIG{__WARN__} = sub { push @warnings, "@_" };
eval {
$num_warnings = validate qq{
lib -d
# comment, followed "blank" line (w/ whitespace):
# indented comment, followed blank line (w/o whitespace):
lib/File/CheckTree.pm -f
'$path_to_libFileCheckTree' -e || warn
};
};
diag($_) for @warnings;
is( $@, '' );
is( scalar @warnings, 0 );
is( $num_warnings, 0 );
}
#### TEST 2 -- One warning ####
{
my ($num_warnings, @warnings);
local $SIG{__WARN__} = sub { push @warnings, "@_" };
eval {
$num_warnings = validate qq{
lib -f
lib/File/CheckTree.pm -f
};
};
is( $@, '' );
is( scalar @warnings, 1 );
like( $warnings[0], qr/lib is not a plain file/);
is( $num_warnings, 1 );
}
#### TEST 3 -- Multiple warnings ####
# including first warning only from a bundle of tests,
# generic "|| warn", default "|| warn" and "|| warn '...' "
{
my ($num_warnings, @warnings);
local $SIG{__WARN__} = sub { push @warnings, "@_" };
eval {
$num_warnings = validate q{
lib -effd
lib/File/CheckTree.pm -f || die
lib/File/CheckTree.pm -d || warn
lib -f || warn "my warning: $file\n"
};
};
is( $@, '' );
is( scalar @warnings, 3 );
like( $warnings[0], qr/lib is not a plain file/);
like( $warnings[1], qr{lib/File/CheckTree.pm is not a directory});
like( $warnings[2], qr/my warning: lib/);
is( $num_warnings, 3 );
}
#### TEST 4 -- cd directive ####
# cd directive followed by relative paths, followed by full paths
{
my ($num_warnings, @warnings, $path_to_lib, $path_to_dist);
$path_to_lib = File::Spec->rel2abs(File::Spec->catdir('lib'));
$path_to_dist = File::Spec->rel2abs(File::Spec->curdir);
local $SIG{__WARN__} = sub { push @warnings, "@_" };
eval {
$num_warnings = validate qq{
lib -d || die
'$path_to_lib' cd
File -e
File -f
'$path_to_dist' cd
lib/File/CheckTree.pm -ef
lib/File/CheckTree.pm -d || warn
'$path_to_lib' -d || die
};
};
is( $@, '' );
is( scalar @warnings, 2 );
like( $warnings[0], qr/File is not a plain file/);
like( $warnings[1], qr/CheckTree\.pm is not a directory/);
is( $num_warnings, 2 );
}
#### TEST 5 -- Exception ####
# test with generic "|| die"
{
my $num_warnings;
eval {
$num_warnings = validate q{
lib -ef || die
lib/File/CheckTree.pm -d
};
};
like($@, qr/lib is not a plain file/);
}
#### TEST 6 -- Exception ####
# test with "|| die 'my error message'"
{
my $num_warnings;
eval {
$num_warnings = validate q{
lib -ef || die "yadda $file yadda...\n"
lib/File/CheckTree.pm -d
};
};
like($@, qr/yadda lib yadda/);
is( $num_warnings, undef );
}
#### TEST 7 -- Quoted file names ####
{
my $num_warnings;
eval {
$num_warnings = validate q{
"a file with whitespace" !-ef
'a file with whitespace' !-ef
};
};
is ( $@, '', 'No errors mean we compile correctly');
}
#### TEST 8 -- Malformed query ####
{
my $num_warnings;
eval {
$num_warnings = validate q{
a file with whitespace !-ef
};
};
like( $@, qr/syntax error/,
'We got a syntax error for a malformed file query' );
}
|