10 BEGIN { plan tests => 6 }
15 use File::Spec; # used to get absolute paths
17 # We assume that we start from the perl "t" directory.
18 # Will move up one level to make it easier to generate
19 # reliable pathnames for testing File::CheckTree
21 chdir(File::Spec->updir) or die "cannot change to parent of t/ directory: $!";
24 #### TEST 1 -- No warnings ####
25 # usings both relative and full paths, indented comments
28 my ($num_warnings, $path_to_README);
29 $path_to_README = File::Spec->rel2abs('README');
32 local $SIG{__WARN__} = sub { push @warnings, "@_" };
35 $num_warnings = validate qq{
37 # comment, followed "blank" line (w/ whitespace):
39 # indented comment, followed blank line (w/o whitespace):
42 $path_to_README -e || warn
46 if ( !$@ && !@warnings && defined($num_warnings) && $num_warnings == 0 ) {
55 #### TEST 2 -- One warning ####
58 my ($num_warnings, @warnings);
60 local $SIG{__WARN__} = sub { push @warnings, "@_" };
63 $num_warnings = validate qq{
69 if ( !$@ && @warnings == 1
70 && $warnings[0] =~ /lib is not a plain file/
71 && defined($num_warnings)
72 && $num_warnings == 1 )
82 #### TEST 3 -- Multiple warnings ####
83 # including first warning only from a bundle of tests,
84 # generic "|| warn", default "|| warn" and "|| warn '...' "
87 my ($num_warnings, @warnings);
89 local $SIG{__WARN__} = sub { push @warnings, "@_" };
92 $num_warnings = validate q{
96 lib -f || warn "my warning: $file\n"
100 if ( !$@ && @warnings == 3
101 && $warnings[0] =~ /lib is not a plain file/
102 && $warnings[1] =~ /README is not a directory/
103 && $warnings[2] =~ /my warning: lib/
104 && defined($num_warnings)
105 && $num_warnings == 3 )
115 #### TEST 4 -- cd directive ####
116 # cd directive followed by relative paths, followed by full paths
118 my ($num_warnings, @warnings, $path_to_libFile, $path_to_dist);
119 $path_to_libFile = File::Spec->rel2abs(File::Spec->catdir('lib','File'));
120 $path_to_dist = File::Spec->rel2abs(File::Spec->curdir);
122 local $SIG{__WARN__} = sub { push @warnings, "@_" };
125 $num_warnings = validate qq{
133 $path_to_libFile -d || die
137 if ( !$@ && @warnings == 2
138 && $warnings[0] =~ /Spec is not a plain file/
139 && $warnings[1] =~ /INSTALL is not a directory/
140 && defined($num_warnings)
141 && $num_warnings == 2 )
151 #### TEST 5 -- Exception ####
152 # test with generic "|| die"
157 $num_warnings = validate q{
163 if ( $@ && $@ =~ /lib is not a plain file/
164 && not defined $num_warnings )
174 #### TEST 6 -- Exception ####
175 # test with "|| die 'my error message'"
180 $num_warnings = validate q{
181 lib -ef || die "yadda $file yadda...\n"
186 if ( $@ && $@ =~ /yadda lib yadda/
187 && not defined $num_warnings )