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