10 BEGIN { plan tests => 6 }
14 # Cwd::cwd does an implicit "require Win32", but
15 # the ../lib directory in @INC will no longer work once
16 # we chdir() out of the "t" directory.
20 use File::Spec; # used to get absolute paths
22 # We assume that we start from the perl "t" directory.
23 # Will move up one level to make it easier to generate
24 # reliable pathnames for testing File::CheckTree
26 chdir(File::Spec->updir) or die "cannot change to parent of t/ directory: $!";
29 #### TEST 1 -- No warnings ####
30 # usings both relative and full paths, indented comments
33 my ($num_warnings, $path_to_README);
34 $path_to_README = File::Spec->rel2abs('README');
37 local $SIG{__WARN__} = sub { push @warnings, "@_" };
40 $num_warnings = validate qq{
42 # comment, followed "blank" line (w/ whitespace):
44 # indented comment, followed blank line (w/o whitespace):
47 $path_to_README -e || warn
51 if ( !$@ && !@warnings && defined($num_warnings) && $num_warnings == 0 ) {
60 #### TEST 2 -- One warning ####
63 my ($num_warnings, @warnings);
65 local $SIG{__WARN__} = sub { push @warnings, "@_" };
68 $num_warnings = validate qq{
74 if ( !$@ && @warnings == 1
75 && $warnings[0] =~ /lib is not a plain file/
76 && defined($num_warnings)
77 && $num_warnings == 1 )
87 #### TEST 3 -- Multiple warnings ####
88 # including first warning only from a bundle of tests,
89 # generic "|| warn", default "|| warn" and "|| warn '...' "
92 my ($num_warnings, @warnings);
94 local $SIG{__WARN__} = sub { push @warnings, "@_" };
97 $num_warnings = validate q{
101 lib -f || warn "my warning: $file\n"
105 if ( !$@ && @warnings == 3
106 && $warnings[0] =~ /lib is not a plain file/
107 && $warnings[1] =~ /README is not a directory/
108 && $warnings[2] =~ /my warning: lib/
109 && defined($num_warnings)
110 && $num_warnings == 3 )
120 #### TEST 4 -- cd directive ####
121 # cd directive followed by relative paths, followed by full paths
123 my ($num_warnings, @warnings, $path_to_libFile, $path_to_dist);
124 $path_to_libFile = File::Spec->rel2abs(File::Spec->catdir('lib','File'));
125 $path_to_dist = File::Spec->rel2abs(File::Spec->curdir);
127 local $SIG{__WARN__} = sub { push @warnings, "@_" };
130 $num_warnings = validate qq{
138 $path_to_libFile -d || die
142 if ( !$@ && @warnings == 2
143 && $warnings[0] =~ /Spec is not a plain file/
144 && $warnings[1] =~ /INSTALL is not a directory/
145 && defined($num_warnings)
146 && $num_warnings == 2 )
156 #### TEST 5 -- Exception ####
157 # test with generic "|| die"
162 $num_warnings = validate q{
168 if ( $@ && $@ =~ /lib is not a plain file/
169 && not defined $num_warnings )
179 #### TEST 6 -- Exception ####
180 # test with "|| die 'my error message'"
185 $num_warnings = validate q{
186 lib -ef || die "yadda $file yadda...\n"
191 if ( $@ && $@ =~ /yadda lib yadda/
192 && not defined $num_warnings )