10 BEGIN { plan tests => 6 }
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 if ( !$@ && !@warnings && defined($num_warnings) && $num_warnings == 0 ) {
65 #### TEST 2 -- One warning ####
68 my ($num_warnings, @warnings);
70 local $SIG{__WARN__} = sub { push @warnings, "@_" };
73 $num_warnings = validate qq{
79 if ( !$@ && @warnings == 1
80 && $warnings[0] =~ /lib is not a plain file/
81 && defined($num_warnings)
82 && $num_warnings == 1 )
92 #### TEST 3 -- Multiple warnings ####
93 # including first warning only from a bundle of tests,
94 # generic "|| warn", default "|| warn" and "|| warn '...' "
97 my ($num_warnings, @warnings);
99 local $SIG{__WARN__} = sub { push @warnings, "@_" };
102 $num_warnings = validate q{
106 lib -f || warn "my warning: $file\n"
110 if ( !$@ && @warnings == 3
111 && $warnings[0] =~ /lib is not a plain file/
112 && $warnings[1] =~ /README is not a directory/
113 && $warnings[2] =~ /my warning: lib/
114 && defined($num_warnings)
115 && $num_warnings == 3 )
125 #### TEST 4 -- cd directive ####
126 # cd directive followed by relative paths, followed by full paths
128 my ($num_warnings, @warnings, $path_to_libFile, $path_to_dist);
129 $path_to_libFile = File::Spec->rel2abs(File::Spec->catdir('lib','File'));
130 $path_to_dist = File::Spec->rel2abs(File::Spec->curdir);
132 local $SIG{__WARN__} = sub { push @warnings, "@_" };
135 $num_warnings = validate qq{
143 $path_to_libFile -d || die
147 if ( !$@ && @warnings == 2
148 && $warnings[0] =~ /Spec is not a plain file/
149 && $warnings[1] =~ /INSTALL is not a directory/
150 && defined($num_warnings)
151 && $num_warnings == 2 )
161 #### TEST 5 -- Exception ####
162 # test with generic "|| die"
167 $num_warnings = validate q{
173 if ( $@ && $@ =~ /lib is not a plain file/
174 && not defined $num_warnings )
184 #### TEST 6 -- Exception ####
185 # test with "|| die 'my error message'"
190 $num_warnings = validate q{
191 lib -ef || die "yadda $file yadda...\n"
196 if ( $@ && $@ =~ /yadda lib yadda/
197 && not defined $num_warnings )