From: Josh ben Jore <jjore@cpan.org>
Date: Sat, 1 Aug 2009 05:36:17 +0000 (-0700)
Subject: Pre-resolve symlink for File::Stat test under -Dmksymlinks
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=61a7d4fdb04e98c5b2c76e1a5b406b5395fae945;p=p5sagit%2Fp5-mst-13.2.git

Pre-resolve symlink for File::Stat test under -Dmksymlinks
---

diff --git a/lib/File/stat.t b/lib/File/stat.t
index b53c9e9..f104b74 100644
--- a/lib/File/stat.t
+++ b/lib/File/stat.t
@@ -6,24 +6,37 @@ BEGIN {
 }
 
 use Test::More;
+use Config qw( %Config );
 
 BEGIN {
+    # Check whether the build is configured with -Dmksymlinks
+    our $Dmksymlinks =
+        grep { /^config_arg\d+$/ && $Config{$_} eq '-Dmksymlinks' }
+        keys %Config;
+
+    # Resolve symlink to ./TEST if this build is configured with -Dmksymlinks
+    our $file = 'TEST';
+    if ( $Dmksymlinks ) {
+        $file = readlink $file;
+        die "Can't readlink(TEST): $!" if ! defined $file;
+    }
+
     our $hasst;
-    eval { my @n = stat "TEST" };
+    eval { my @n = stat $file };
     $hasst = 1 unless $@ && $@ =~ /unimplemented/;
     unless ($hasst) { plan skip_all => "no stat"; exit 0 }
     use Config;
     $hasst = 0 unless $Config{'i_sysstat'} eq 'define';
     unless ($hasst) { plan skip_all => "no sys/stat.h"; exit 0 }
-    our @stat = stat "TEST"; # This is the function stat.
-    unless (@stat) { plan skip_all => "1..0 # Skip: no file TEST"; exit 0 }
+    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' );
 
-my $stat = File::stat::stat( "TEST" ); # This is the OO stat.
+my $stat = File::stat::stat( $file ); # This is the OO stat.
 ok( ref($stat), 'should build a stat object' );
 
 is( $stat->dev, $stat[0], "device number in position 0" );
@@ -64,7 +77,7 @@ for (split //, "rwxoRWXOezsfdlpSbcugkMCA") {
         my $rv = eval "-$_ \$stat";
         ok( !$@,                            "-$_ overload succeeds" )
             or diag( $@ );
-        is( $rv, eval "-$_ 'TEST'",         "correct -$_ overload" );
+        is( $rv, eval "-$_ \$file",         "correct -$_ overload" );
     }
 }
 
@@ -75,7 +88,7 @@ for (split //, "tTB") {
 
 SKIP: {
 	local *STAT;
-	skip("Could not open file: $!", 2) unless open(STAT, 'TEST');
+	skip("Could not open file: $!", 2) unless open(STAT, $file);
 	ok( File::stat::stat('STAT'), '... should be able to find filehandle' );
 
 	package foo;