In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/c69df70ff62392023ac4d1f5d9278c8e64b06369?hp=a6485a247941d126734ee4585a7e19bf7e31097e>

- Log -----------------------------------------------------------------
commit c69df70ff62392023ac4d1f5d9278c8e64b06369
Author: Tony Cook <t...@develop-help.com>
Date:   Wed Sep 22 14:28:36 2010 +1000

    make sure perl doesn't touch stat.t between stats
    
    ebcfa0534 changed stat.t to avoid using TEST as the stat target, since
    it is read by other test scripts.  But with the initial stat() in the
    BEGIN block perl is still reading the script for compilation, which
    will update the access time.  Since the system clock usually didn't
    tick another second between the first and second stats, the test
    usually succeeded, but occasionally the clock would tick, and the test
    would fail.
    
    Moved the stat() out of the BEGIN block to avoid that.
    
    As a check I temporarily added a 2 second sleep after the initial
    stat to ensure we didn't have a similar problem to that will
    allowed this to pass most of the time.
-----------------------------------------------------------------------

Summary of changes:
 lib/File/stat.t |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/lib/File/stat.t b/lib/File/stat.t
index 11858ab..afeb446 100644
--- a/lib/File/stat.t
+++ b/lib/File/stat.t
@@ -14,7 +14,10 @@ BEGIN {
         grep { /^config_arg\d+$/ && $Config{$_} eq '-Dmksymlinks' }
         keys %Config;
 
-    # Resolve symlink to ./TEST if this build is configured with -Dmksymlinks
+    # Resolve symlink to ./lib/File/stat.t if this build is configured
+    # with -Dmksymlinks
+    # Originally we worked with ./TEST, but other test scripts read from
+    # that file and modify its access time.
     our $file = '../lib/File/stat.t';
     if ( $Dmksymlinks ) {
         $file = readlink $file;
@@ -28,10 +31,17 @@ BEGIN {
     use Config;
     $hasst = 0 unless $Config{'i_sysstat'} eq 'define';
     unless ($hasst) { plan skip_all => "no sys/stat.h"; exit 0 }
-    our @stat = stat $file; # This is the function stat.
-    unless (@stat) { plan skip_all => "1..0 # Skip: no file $file"; exit 0 }
 }
 
+# Originally this was done in the BEGIN block, but perl is still
+# compiling (and hence reading) the script at that point, which can
+# change the file's access time, causing a different in the comparison
+# tests if the clock ticked over the second between the stat() and the
+# final read.
+# At this point all of the reading is done.
+our @stat = stat $file; # This is the function stat.
+unless (@stat) { plan skip_all => "1..0 # Skip: no file $file"; exit 0 }
+
 plan tests => 19 + 24*2 + 3;
 
 use_ok( 'File::stat' );

--
Perl5 Master Repository

Reply via email to