| [3181] | 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 | {
|
|---|
| |
|---|