10 BEGIN { plan tests => 8 }
15 # Cwd::cwd does an implicit "require Win32", but
16 # the ../lib directory in @INC will no longer work once
17 # we chdir() out of the "t" directory.
18 if ($^O eq 'MSWin32') {
25 use File::Spec; # used to get absolute paths
27 # We assume that we start from the perl "t" directory.
28 # Will move up one level to make it easier to generate
29 # reliable pathnames for testing File::CheckTree
31 chdir(File::Spec->updir) or die "cannot change to parent of t/ directory: $!";
34 #### TEST 1 -- No warnings ####
35 # usings both relative and full paths, indented comments
38 my ($num_warnings, $path_to_README);
39 $path_to_README = File::Spec->rel2abs('README');
42 local $SIG{__WARN__} = sub { push @warnings, "@_" };
45 $num_warnings = validate qq{
47 # comment, followed "blank" line (w/ whitespace):
49 # indented comment, followed blank line (w/o whitespace):
52 '$path_to_README' -e || warn
56 print STDERR $_ for @warnings;
57 if ( !$@ && !@warnings && defined($num_warnings) && $num_warnings == 0 ) {
66 #### TEST 2 -- One warning ####
69 my ($num_warnings, @warnings);
71 local $SIG{__WARN__} = sub { push @warnings, "@_" };
74 $num_warnings = validate qq{
80 if ( !$@ && @warnings == 1
81 && $warnings[0] =~ /lib is not a plain file/
82 && defined($num_warnings)
83 && $num_warnings == 1 )
93 #### TEST 3 -- Multiple warnings ####
94 # including first warning only from a bundle of tests,
95 # generic "|| warn", default "|| warn" and "|| warn '...' "
98 my ($num_warnings, @warnings);
100 local $SIG{__WARN__} = sub { push @warnings, "@_" };
103 $num_warnings = validate q{
107 lib -f || warn "my warning: $file\n"
111 if ( !$@ && @warnings == 3
112 && $warnings[0] =~ /lib is not a plain file/
113 && $warnings[1] =~ /README is not a directory/
114 && $warnings[2] =~ /my warning: lib/
115 && defined($num_warnings)
116 && $num_warnings == 3 )
126 #### TEST 4 -- cd directive ####
127 # cd directive followed by relative paths, followed by full paths
129 my ($num_warnings, @warnings, $path_to_libFile, $path_to_dist);
130 $path_to_libFile = File::Spec->rel2abs(File::Spec->catdir('lib','File'));
131 $path_to_dist = File::Spec->rel2abs(File::Spec->curdir);
133 local $SIG{__WARN__} = sub { push @warnings, "@_" };
136 $num_warnings = validate qq{
138 '$path_to_libFile' cd
144 '$path_to_libFile' -d || die
148 if ( !$@ && @warnings == 2
149 && $warnings[0] =~ /Spec is not a plain file/
150 && $warnings[1] =~ /INSTALL is not a directory/
151 && defined($num_warnings)
152 && $num_warnings == 2 )
162 #### TEST 5 -- Exception ####
163 # test with generic "|| die"
168 $num_warnings = validate q{
174 if ( $@ && $@ =~ /lib is not a plain file/
175 && not defined $num_warnings )
185 #### TEST 6 -- Exception ####
186 # test with "|| die 'my error message'"
191 $num_warnings = validate q{
192 lib -ef || die "yadda $file yadda...\n"
197 if ( $@ && $@ =~ /yadda lib yadda/
198 && not defined $num_warnings )
207 #### TEST 7 -- Quoted file names ####
211 $num_warnings = validate q{
212 "a file with whitespace" !-ef
213 'a file with whitespace' !-ef
218 # No errors mean we compile correctly
226 #### TEST 8 -- Malformed query ####
230 $num_warnings = validate q{
231 a file with whitespace !-ef
235 if ( $@ =~ /syntax error/) {
236 # We got a syntax error for a malformed file query