From 313e09e70abdc9a57e7f4b1a814b5bddc652fcf4 Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Tue, 25 Feb 2014 11:36:26 +0100 Subject: [PATCH] Use a temporary file instead of $^X when testing stat. Otherwise there's a subtle race condition on the last access time, which can cause the test to spuriously fail. I'm surprised that we've not seen this failure until today. --- ext/POSIX/t/wrappers.t | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ext/POSIX/t/wrappers.t b/ext/POSIX/t/wrappers.t index f443ed8..5b9f6d6 100644 --- a/ext/POSIX/t/wrappers.t +++ b/ext/POSIX/t/wrappers.t @@ -9,9 +9,14 @@ plan(skip_all => "POSIX is unavailable") require POSIX; require Symbol; +require File::Temp; use constant NOT_HERE => 'this-file-should-not-exist'; +# Object destruction causes the file to be deleted. +my $temp_fh = File::Temp->new(); +my $temp_file = $temp_fh->filename; + # localtime and gmtime in time.t. # exit, fork, waitpid, sleep in waitpid.t # errno in posix.t @@ -36,7 +41,7 @@ is(do {local $^W; SKIP: { # Win32 doesn't like me trying to fstat STDIN. Bothersome thing. - skip("Can't open $^X: $!", 1) unless open my $fh, '<', $^X; + skip("Can't open $temp_file: $!", 1) unless open my $fh, '<', $temp_file; is_deeply([POSIX::fstat(fileno $fh)], [stat $fh], 'fstat'); } @@ -108,7 +113,7 @@ is(POSIX::sin(0), 0, 'sin'); is(POSIX::sleep(0), 0, 'sleep'); is(POSIX::sprintf('%o', 42), '52', 'sprintf'); is(POSIX::sqrt(256), 16, 'sqrt'); -is_deeply([POSIX::stat($^X)], [stat $^X], 'stat'); +is_deeply([POSIX::stat($temp_file)], [stat $temp_file], 'stat'); { local $! = 2; my $error = "$!"; -- 2.7.4