LOGONLY mark 1408fb as NODOC since it appears to be a useful but minor warning cleanup
[p5sagit/p5-mst-13.2.git] / lib / File / CheckTree.t
CommitLineData
849d5e34 1#!./perl -w
1a3850a5 2
3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
1a3850a5 6}
7
3d47529a 8use Test::More tests => 23;
849d5e34 9
10use strict;
1a3850a5 11
7cda84c2 12BEGIN {
cf2f24a4 13# Cwd::cwd does an implicit "require Win32", but
14# the ../lib directory in @INC will no longer work once
15# we chdir() out of the "t" directory.
7cda84c2 16 if ($^O eq 'MSWin32') {
17 require Win32;
18 Win32->import();
19 }
3d47529a 20 require overload;
7cda84c2 21}
cf2f24a4 22
1a3850a5 23use File::CheckTree;
849d5e34 24use File::Spec; # used to get absolute paths
25
26# We assume that we start from the perl "t" directory.
27# Will move up one level to make it easier to generate
28# reliable pathnames for testing File::CheckTree
29
86dc4f03 30chdir(File::Spec->updir) or die "cannot change to parent of t/ directory: $!";
849d5e34 31
32
33#### TEST 1 -- No warnings ####
34# usings both relative and full paths, indented comments
35
36{
37 my ($num_warnings, $path_to_README);
38 $path_to_README = File::Spec->rel2abs('README');
39
40 my @warnings;
41 local $SIG{__WARN__} = sub { push @warnings, "@_" };
42
43 eval {
44 $num_warnings = validate qq{
45 lib -d
46# comment, followed "blank" line (w/ whitespace):
47
48 # indented comment, followed blank line (w/o whitespace):
49
50 README -f
96dbb1e1 51 '$path_to_README' -e || warn
849d5e34 52 };
53 };
54
3d47529a 55 diag($_) for @warnings;
56 is( $@, '' );
57 is( scalar @warnings, 0 );
58 is( $num_warnings, 0 );
849d5e34 59}
60
61
62#### TEST 2 -- One warning ####
63
64{
65 my ($num_warnings, @warnings);
66
67 local $SIG{__WARN__} = sub { push @warnings, "@_" };
68
69 eval {
70 $num_warnings = validate qq{
71 lib -f
72 README -f
73 };
74 };
75
3d47529a 76 is( $@, '' );
77 is( scalar @warnings, 1 );
78 like( $warnings[0], qr/lib is not a plain file/);
79 is( $num_warnings, 1 );
849d5e34 80}
81
1a3850a5 82
849d5e34 83#### TEST 3 -- Multiple warnings ####
84# including first warning only from a bundle of tests,
85# generic "|| warn", default "|| warn" and "|| warn '...' "
1a3850a5 86
849d5e34 87{
88 my ($num_warnings, @warnings);
1a3850a5 89
849d5e34 90 local $SIG{__WARN__} = sub { push @warnings, "@_" };
91
92 eval {
93 $num_warnings = validate q{
94 lib -effd
95 README -f || die
96 README -d || warn
97 lib -f || warn "my warning: $file\n"
98 };
99 };
100
3d47529a 101 is( $@, '' );
102 is( scalar @warnings, 3 );
103 like( $warnings[0], qr/lib is not a plain file/);
104 like( $warnings[1], qr/README is not a directory/);
105 like( $warnings[2], qr/my warning: lib/);
106 is( $num_warnings, 3 );
849d5e34 107}
108
109
110#### TEST 4 -- cd directive ####
111# cd directive followed by relative paths, followed by full paths
112{
113 my ($num_warnings, @warnings, $path_to_libFile, $path_to_dist);
026a9d8a 114 $path_to_libFile = File::Spec->rel2abs(File::Spec->catdir('lib','File'));
849d5e34 115 $path_to_dist = File::Spec->rel2abs(File::Spec->curdir);
116
117 local $SIG{__WARN__} = sub { push @warnings, "@_" };
118
119 eval {
120 $num_warnings = validate qq{
121 lib -d || die
1f0bbb56 122 '$path_to_libFile' cd
849d5e34 123 Spec -e
124 Spec -f
1f0bbb56 125 '$path_to_dist' cd
849d5e34 126 README -ef
127 INSTALL -d || warn
1f0bbb56 128 '$path_to_libFile' -d || die
849d5e34 129 };
130 };
131
3d47529a 132 is( $@, '' );
133 is( scalar @warnings, 2 );
134 like( $warnings[0], qr/Spec is not a plain file/);
135 like( $warnings[1], qr/INSTALL is not a directory/);
136 is( $num_warnings, 2 );
849d5e34 137}
138
139
140#### TEST 5 -- Exception ####
141# test with generic "|| die"
142{
143 my $num_warnings;
144
145 eval {
146 $num_warnings = validate q{
147 lib -ef || die
148 README -d
149 };
150 };
151
3d47529a 152 like($@, qr/lib is not a plain file/);
849d5e34 153}
154
155
156#### TEST 6 -- Exception ####
157# test with "|| die 'my error message'"
158{
159 my $num_warnings;
160
161 eval {
162 $num_warnings = validate q{
163 lib -ef || die "yadda $file yadda...\n"
164 README -d
165 };
166 };
167
3d47529a 168 like($@, qr/yadda lib yadda/);
169 is( $num_warnings, undef );
849d5e34 170}
96dbb1e1 171
172#### TEST 7 -- Quoted file names ####
173{
174 my $num_warnings;
175 eval {
176 $num_warnings = validate q{
177 "a file with whitespace" !-ef
178 'a file with whitespace' !-ef
179 };
180 };
181
3d47529a 182 is ( $@, '', 'No errors mean we compile correctly');
96dbb1e1 183}
184
185#### TEST 8 -- Malformed query ####
186{
187 my $num_warnings;
188 eval {
189 $num_warnings = validate q{
190 a file with whitespace !-ef
191 };
192 };
193
3d47529a 194 like( $@, qr/syntax error/,
195 'We got a syntax error for a malformed file query' );
96dbb1e1 196}