summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-01-13 20:28:46 -0800
committerFather Chrysostomos <sprout@cpan.org>2012-01-13 21:24:55 -0800
commit7b7309aff53f13fbc885bbe035da3e4ef8b481f4 (patch)
treec172c1561629c3769e044b32ece0445a94789167
parentbd5f6c0160a24cc91f91e8fe5180efde0d7fb8af (diff)
downloadperl-7b7309aff53f13fbc885bbe035da3e4ef8b481f4.tar.gz
Make failed filetests consistent with & w/out fatal warnings
The result of stat(_) after a failed -r HANDLE would differ depending on whether fatal warnings are on. This corrects that, by setting the internal status before warning about an unopened filehandle.
-rw-r--r--doio.c6
-rw-r--r--t/op/filetest.t29
2 files changed, 32 insertions, 3 deletions
diff --git a/doio.c b/doio.c
index 6f55e0338d..7f3160d96c 100644
--- a/doio.c
+++ b/doio.c
@@ -1286,12 +1286,14 @@ Perl_my_stat_flags(pTHX_ const U32 flags)
} else if (IoDIRP(io)) {
return (PL_laststatval = PerlLIO_fstat(my_dirfd(IoDIRP(io)), &PL_statcache));
} else {
+ PL_laststatval = -1;
report_evil_fh(gv);
- return (PL_laststatval = -1);
+ return -1;
}
} else {
+ PL_laststatval = -1;
report_evil_fh(gv);
- return (PL_laststatval = -1);
+ return -1;
}
}
else if (PL_op->op_private & OPpFT_STACKED) {
diff --git a/t/op/filetest.t b/t/op/filetest.t
index 9e46823244..cf7a02dae4 100644
--- a/t/op/filetest.t
+++ b/t/op/filetest.t
@@ -10,7 +10,7 @@ BEGIN {
}
use Config;
-plan(tests => 40 + 27*14);
+plan(tests => 42 + 27*14);
ok( -d 'op' );
ok( -f 'TEST' );
@@ -291,3 +291,30 @@ SKIP: {
is runperl(prog => '-T _', switches => ['-w'], stderr => 1), "",
'no uninit warnings from -T with no preceding stat';
+
+# Unsuccessful filetests on filehandles should leave stat buffers in the
+# same state whether fatal warnings are on or off.
+{
+ stat "test.pl";
+ # This GV has no IO
+ -r *phlon;
+ my $failed_stat1 = stat _;
+
+ stat "test.pl";
+ eval { use warnings FATAL => unopened; -r *phlon };
+ my $failed_stat2 = stat _;
+
+ is $failed_stat2, $failed_stat1,
+ 'failed -r($gv_without_io) with and w/out fatal warnings';
+
+ stat "test.pl";
+ -r cength; # at compile time autovivifies IO, but with no fp
+ $failed_stat1 = stat _;
+
+ stat "test.pl";
+ eval { use warnings FATAL => unopened; -r cength };
+ $failed_stat2 = stat _;
+
+ is $failed_stat2, $failed_stat1,
+ 'failed -r($gv_with_io_but_no_fp) with and w/out fatal warnings';
+}