1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
#!./perl -w
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
}
use Test;
BEGIN { plan tests => 6 }
use strict;
use File::CheckTree;
use File::Spec; # used to get absolute paths
# We assume that we start from the perl "t" directory.
# Will move up one level to make it easier to generate
# reliable pathnames for testing File::CheckTree
chdir(File::Spec->updir) or die "cannot change to parent of t/ directory: $!";
#### TEST 1 -- No warnings ####
# usings both relative and full paths, indented comments
{
my ($num_warnings, $path_to_README);
$path_to_README = File::Spec->rel2abs('README');
my @warnings;
local $SIG{__WARN__} = sub { push @warnings, "@_" };
eval {
$num_warnings = validate qq{
lib -d
# comment, followed "blank" line (w/ whitespace):
# indented comment, followed blank line (w/o whitespace):
README -f
$path_to_README -e || warn
};
};
if ( !$@ && !@warnings && defined($num_warnings) && $num_warnings == 0 ) {
ok(1);
}
else {
ok(0);
}
}
#### TEST 2 -- One warning ####
{
my ($num_warnings, @warnings);
local $SIG{__WARN__} = sub { push @warnings, "@_" };
eval {
$num_warnings = validate qq{
lib -f
README -f
};
};
if ( !$@ && @warnings == 1
&& $warnings[0] =~ /lib is not a plain file/
&& defined($num_warnings)
&& $num_warnings == 1 )
{
ok(1);
}
else {
ok(0);
}
}
#### TEST 3 -- Multiple warnings ####
# including first warning only from a bundle of tests,
# generic "|| warn", default "|| warn" and "|| warn '...' "
{
my ($num_warnings, @warnings);
local $SIG{__WARN__} = sub { push @warnings, "@_" };
eval {
$num_warnings = validate q{
lib -effd
README -f || die
README -d || warn
lib -f || warn "my warning: $file\n"
};
};
if ( !$@ && @warnings == 3
&& $warnings[0] =~ /lib is not a plain file/
&& $warnings[1] =~ /README is not a directory/
&& $warnings[2] =~ /my warning: lib/
&& defined($num_warnings)
&& $num_warnings == 3 )
{
ok(1);
}
else {
ok(0);
}
}
#### TEST 4 -- cd directive ####
# cd directive followed by relative paths, followed by full paths
{
my ($num_warnings, @warnings, $path_to_libFile, $path_to_dist);
$path_to_libFile = File::Spec->rel2abs(File::Spec->catdir('lib','File'));
$path_to_dist = File::Spec->rel2abs(File::Spec->curdir);
local $SIG{__WARN__} = sub { push @warnings, "@_" };
eval {
$num_warnings = validate qq{
lib -d || die
$path_to_libFile cd
Spec -e
Spec -f
$path_to_dist cd
README -ef
INSTALL -d || warn
$path_to_libFile -d || die
};
};
if ( !$@ && @warnings == 2
&& $warnings[0] =~ /Spec is not a plain file/
&& $warnings[1] =~ /INSTALL is not a directory/
&& defined($num_warnings)
&& $num_warnings == 2 )
{
ok(1);
}
else {
ok(0);
}
}
#### TEST 5 -- Exception ####
# test with generic "|| die"
{
my $num_warnings;
eval {
$num_warnings = validate q{
lib -ef || die
README -d
};
};
if ( $@ && $@ =~ /lib is not a plain file/
&& not defined $num_warnings )
{
ok(1);
}
else {
ok(0);
}
}
#### TEST 6 -- Exception ####
# test with "|| die 'my error message'"
{
my $num_warnings;
eval {
$num_warnings = validate q{
lib -ef || die "yadda $file yadda...\n"
README -d
};
};
if ( $@ && $@ =~ /yadda lib yadda/
&& not defined $num_warnings )
{
ok(1);
}
else {
ok(0);
}
}
|