8 use Test::More tests => 23;
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.
16 if ($^O eq 'MSWin32') {
24 use File::Spec; # used to get absolute paths
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
30 chdir(File::Spec->updir) or die "cannot change to parent of t/ directory: $!";
33 #### TEST 1 -- No warnings ####
34 # usings both relative and full paths, indented comments
37 my ($num_warnings, $path_to_README);
38 $path_to_README = File::Spec->rel2abs('README');
41 local $SIG{__WARN__} = sub { push @warnings, "@_" };
44 $num_warnings = validate qq{
46 # comment, followed "blank" line (w/ whitespace):
48 # indented comment, followed blank line (w/o whitespace):
51 '$path_to_README' -e || warn
55 diag($_) for @warnings;
57 is( scalar @warnings, 0 );
58 is( $num_warnings, 0 );
62 #### TEST 2 -- One warning ####
65 my ($num_warnings, @warnings);
67 local $SIG{__WARN__} = sub { push @warnings, "@_" };
70 $num_warnings = validate qq{
77 is( scalar @warnings, 1 );
78 like( $warnings[0], qr/lib is not a plain file/);
79 is( $num_warnings, 1 );
83 #### TEST 3 -- Multiple warnings ####
84 # including first warning only from a bundle of tests,
85 # generic "|| warn", default "|| warn" and "|| warn '...' "
88 my ($num_warnings, @warnings);
90 local $SIG{__WARN__} = sub { push @warnings, "@_" };
93 $num_warnings = validate q{
97 lib -f || warn "my warning: $file\n"
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 );
110 #### TEST 4 -- cd directive ####
111 # cd directive followed by relative paths, followed by full paths
113 my ($num_warnings, @warnings, $path_to_libFile, $path_to_dist);
114 $path_to_libFile = File::Spec->rel2abs(File::Spec->catdir('lib','File'));
115 $path_to_dist = File::Spec->rel2abs(File::Spec->curdir);
117 local $SIG{__WARN__} = sub { push @warnings, "@_" };
120 $num_warnings = validate qq{
122 '$path_to_libFile' cd
128 '$path_to_libFile' -d || die
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 );
140 #### TEST 5 -- Exception ####
141 # test with generic "|| die"
146 $num_warnings = validate q{
152 like($@, qr/lib is not a plain file/);
156 #### TEST 6 -- Exception ####
157 # test with "|| die 'my error message'"
162 $num_warnings = validate q{
163 lib -ef || die "yadda $file yadda...\n"
168 like($@, qr/yadda lib yadda/);
169 is( $num_warnings, undef );
172 #### TEST 7 -- Quoted file names ####
176 $num_warnings = validate q{
177 "a file with whitespace" !-ef
178 'a file with whitespace' !-ef
182 is ( $@, '', 'No errors mean we compile correctly');
185 #### TEST 8 -- Malformed query ####
189 $num_warnings = validate q{
190 a file with whitespace !-ef
194 like( $@, qr/syntax error/,
195 'We got a syntax error for a malformed file query' );