summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2012-06-03 13:26:31 +0200
committerNicholas Clark <nick@ccl4.org>2012-06-21 08:59:00 +0200
commit17c017a51cc9557d7d50c5113b67db8442762c56 (patch)
treef662058cafbe5fe2cf14ca7a798e27412bb06b2c /lib
parent2ca571f439610d1ce38c8fbcb4bb638b2d881be1 (diff)
downloadperl-17c017a51cc9557d7d50c5113b67db8442762c56.tar.gz
Simplify lib/File/stat.t by using a tempfile as the test victim.
The previous code had got very gnarly trying to use a file from the distribution for the test file, attempting to cope with 1) Other programs reading the file and hence the atime updating 2) The perl interpreter reading the file and hence the atime updating :-) 3) Building with -Dmksymlinks meaning that the file is a symlink All these problems and work arounds simply *vanish* if we use a tempfile. This will also enable us to change its mode in the future for better testing.
Diffstat (limited to 'lib')
-rw-r--r--lib/File/stat.t31
1 files changed, 3 insertions, 28 deletions
diff --git a/lib/File/stat.t b/lib/File/stat.t
index c3ecc09c62..437078269c 100644
--- a/lib/File/stat.t
+++ b/lib/File/stat.t
@@ -9,37 +9,12 @@ use strict;
use warnings;
use Test::More;
use Config qw( %Config );
-
-my $file;
-
-BEGIN {
- # Check whether the build is configured with -Dmksymlinks
- our $Dmksymlinks =
- grep { /^config_arg\d+$/ && $Config{$_} eq '-Dmksymlinks' }
- keys %Config;
-
- # 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.
- $file = '../lib/File/stat.t';
- if ( $Dmksymlinks ) {
- $file = readlink $file;
- die "Can't readlink(../lib/File/stat.t): $!" if ! defined $file;
- }
-}
-
-# 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 }
+use File::Temp 'tempfile';
require File::stat;
+my (undef, $file) = tempfile();
+my @stat = stat $file; # This is the function stat.
my $stat = File::stat::stat( $file ); # This is the OO stat.
isa_ok($stat, 'File::stat', 'should build a stat object' );