This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
*Actually* test that bug 20011110.104 is fixed.
authorNicholas Clark <nick@ccl4.org>
Wed, 13 Jun 2012 14:45:40 +0000 (16:45 +0200)
committerNicholas Clark <nick@ccl4.org>
Thu, 21 Jun 2012 06:59:00 +0000 (08:59 +0200)
Bug ID 20011110.104 (RT #7896) was fixed by commit 2f173a711df6278f in Nov
2001, but the test that commit added never actually tested this.

The initial problem was that the new code, as written, used C<stat>,
intending that to call File::stat::stat(). However the refactoring of the
test script (all part of the same commit) from C<use File::stat;> to
C<use_ok( 'File::stat' );> (not in a BEGIN block) intentionally eliminated
the export of &File::stat::stat. This means that plain C<stat> is the
core builtin.

Fixing this as-is to File::stat::stat() won't help, as tests have
subsequently been added earlier in the script that trigger the autoloading
of Symbol by File::stat (commit 83716b1ec25b41f2 in Feb 2002). Moving the
tests earlier won't help now that the test uses File::Temp, as that uses
IO::Seekable which uses IO::Handle, which unconditionally loads Symbol.

The simplest solution seems to be to move the test to its own file.

MANIFEST
Porting/Maintainers.pl
lib/File/stat-7896.t [new file with mode: 0644]
lib/File/stat.t

index 86da43e..f9cb161 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -4237,6 +4237,7 @@ lib/File/Find/t/find.t            See if File::Find works
 lib/File/Find/t/taint.t                See if File::Find works with taint
 lib/FileHandle.pm              Backward-compatible front end to IO extension
 lib/FileHandle.t               See if FileHandle works
+lib/File/stat-7896.t           A test for ID 20011110.104
 lib/File/stat.pm               By-name interface to Perl's builtin stat
 lib/File/stat.t                        See if File::stat works
 lib/filetest.pm                        For "use filetest"
index be145ca..d858c7a 100755 (executable)
@@ -842,7 +842,7 @@ use File::Glob qw(:case);
 
     'File::stat' => {
         'MAINTAINER' => 'p5p',
-        'FILES'      => q[lib/File/stat.{pm,t}],
+        'FILES'      => q[lib/File/stat{.pm,*.t}],
         'UPSTREAM'   => 'blead',
     },
 
diff --git a/lib/File/stat-7896.t b/lib/File/stat-7896.t
new file mode 100644 (file)
index 0000000..57b2685
--- /dev/null
@@ -0,0 +1,28 @@
+#!./perl -w
+use strict;
+
+use Test::More;
+use File::stat;
+
+# This is possibly a bit black-box, but for now it works.
+# If (either) File::stat stops lazy loading Symbol, or Test::More starts, it
+# should be revisited
+is($INC{'Symbol.pm'}, undef, "Symbol isn't loaded yet");
+
+# ID 20011110.104 (RT #7896)
+$! = 0;
+is($!, '', '$! is empty');
+is(File::stat::stat('/notafile'), undef, 'invalid file should fail');
+isnt($!, '', 'should populate $!, given invalid file');
+my $e = $!;
+
+isnt($INC{'Symbol.pm'}, undef, "Symbol has been loaded");
+
+# Repeat twice
+is(File::stat::stat('/notafile'), undef, 'invalid file should fail again');
+is($!, $e, '$! should be consistent for an invalid file');
+$e = $!;
+is(File::stat::stat('/notafile'), undef, 'invalid file should fail again');
+is($!, $e, '$! should be consistent for an invalid file');
+
+done_testing();
index 4370782..105115b 100644 (file)
@@ -142,10 +142,6 @@ SKIP:
     ok(-p($pstat), "check -p detects a pipe");
 }
 
-local $!;
-$stat = stat '/notafile';
-isnt( $!, '', 'should populate $!, given invalid file' );
-
 # Testing pretty much anything else is unportable.
 
 done_testing;