6 # We will shortly chdir .., so '../lib' will be wrong at that time, and
7 # 'lib' will be correct
8 @INC = ('../lib', 'lib');
11 use Test::More tests => 23;
18 use File::Spec; # used to get absolute paths
20 # We assume that we start from the perl "t" directory.
21 # Will move up one level to make it easier to generate
22 # reliable pathnames for testing File::CheckTree
24 chdir(File::Spec->updir) or die "cannot change to parent of t/ directory: $!";
27 #### TEST 1 -- No warnings ####
28 # usings both relative and full paths, indented comments
31 my ($num_warnings, $path_to_README);
32 $path_to_README = File::Spec->rel2abs('README');
35 local $SIG{__WARN__} = sub { push @warnings, "@_" };
38 $num_warnings = validate qq{
40 # comment, followed "blank" line (w/ whitespace):
42 # indented comment, followed blank line (w/o whitespace):
45 '$path_to_README' -e || warn
49 diag($_) for @warnings;
51 is( scalar @warnings, 0 );
52 is( $num_warnings, 0 );
56 #### TEST 2 -- One warning ####
59 my ($num_warnings, @warnings);
61 local $SIG{__WARN__} = sub { push @warnings, "@_" };
64 $num_warnings = validate qq{
71 is( scalar @warnings, 1 );
72 like( $warnings[0], qr/lib is not a plain file/);
73 is( $num_warnings, 1 );
77 #### TEST 3 -- Multiple warnings ####
78 # including first warning only from a bundle of tests,
79 # generic "|| warn", default "|| warn" and "|| warn '...' "
82 my ($num_warnings, @warnings);
84 local $SIG{__WARN__} = sub { push @warnings, "@_" };
87 $num_warnings = validate q{
91 lib -f || warn "my warning: $file\n"
96 is( scalar @warnings, 3 );
97 like( $warnings[0], qr/lib is not a plain file/);
98 like( $warnings[1], qr/README is not a directory/);
99 like( $warnings[2], qr/my warning: lib/);
100 is( $num_warnings, 3 );
104 #### TEST 4 -- cd directive ####
105 # cd directive followed by relative paths, followed by full paths
107 my ($num_warnings, @warnings, $path_to_libFile, $path_to_dist);
108 $path_to_libFile = File::Spec->rel2abs(File::Spec->catdir('lib','File'));
109 $path_to_dist = File::Spec->rel2abs(File::Spec->curdir);
111 local $SIG{__WARN__} = sub { push @warnings, "@_" };
114 $num_warnings = validate qq{
116 '$path_to_libFile' cd
122 '$path_to_libFile' -d || die
127 is( scalar @warnings, 2 );
128 like( $warnings[0], qr/Spec is not a plain file/);
129 like( $warnings[1], qr/INSTALL is not a directory/);
130 is( $num_warnings, 2 );
134 #### TEST 5 -- Exception ####
135 # test with generic "|| die"
140 $num_warnings = validate q{
146 like($@, qr/lib is not a plain file/);
150 #### TEST 6 -- Exception ####
151 # test with "|| die 'my error message'"
156 $num_warnings = validate q{
157 lib -ef || die "yadda $file yadda...\n"
162 like($@, qr/yadda lib yadda/);
163 is( $num_warnings, undef );
166 #### TEST 7 -- Quoted file names ####
170 $num_warnings = validate q{
171 "a file with whitespace" !-ef
172 'a file with whitespace' !-ef
176 is ( $@, '', 'No errors mean we compile correctly');
179 #### TEST 8 -- Malformed query ####
183 $num_warnings = validate q{
184 a file with whitespace !-ef
188 like( $@, qr/syntax error/,
189 'We got a syntax error for a malformed file query' );