summaryrefslogtreecommitdiff
path: root/t/lib
diff options
context:
space:
mode:
Diffstat (limited to 't/lib')
-rwxr-xr-xt/lib/ftmp-mktemp.t17
-rwxr-xr-xt/lib/ftmp-posix.t8
-rwxr-xr-xt/lib/ftmp-security.t27
-rwxr-xr-xt/lib/ftmp-tempfile.t36
4 files changed, 38 insertions, 50 deletions
diff --git a/t/lib/ftmp-mktemp.t b/t/lib/ftmp-mktemp.t
index c660475709..2f41d5d252 100755
--- a/t/lib/ftmp-mktemp.t
+++ b/t/lib/ftmp-mktemp.t
@@ -1,9 +1,4 @@
-#!./perl
-
-BEGIN {
- chdir 't' if -d 't';
- unshift @INC, '../lib';
-}
+#!/usr/local/bin/perl -w
# Test for mktemp family of commands in File::Temp
# Use STANDARD safe level for these tests
@@ -50,6 +45,7 @@ ok($string, $line);
# stat(filehandle) does not always equal the size of the stat(filename)
# This must be due to caching. In particular this test writes 7 bytes
# to the file which are not recognised by stat(filename)
+# Simply waiting 3 seconds seems to be enough for the system to update
if ($^O eq 'MSWin32') {
sleep 3;
@@ -69,8 +65,15 @@ print "# MKSTEMPS: File is $template -> $fname fileno=".fileno($fh)."\n";
# Check if the file exists
ok( (-e $fname) );
-ok( unlink0($fh, $fname) );
+# This fails if you are running on NFS
+# If this test fails simply skip it rather than doing a hard failure
+my $status = unlink0($fh, $fname);
+if ($status) {
+ ok($status);
+} else {
+ skip("Skip test failed probably due to NFS",1)
+}
# MKDTEMP
# Temp directory
diff --git a/t/lib/ftmp-posix.t b/t/lib/ftmp-posix.t
index f28785e87a..149ac9a56b 100755
--- a/t/lib/ftmp-posix.t
+++ b/t/lib/ftmp-posix.t
@@ -1,10 +1,4 @@
-#!./perl
-
-BEGIN {
- chdir 't' if -d 't';
- unshift @INC, '../lib';
-}
-
+#!/usr/local/bin/perl -w
# Test for File::Temp - POSIX functions
use strict;
diff --git a/t/lib/ftmp-security.t b/t/lib/ftmp-security.t
index 50e177958a..a3849bdbbd 100755
--- a/t/lib/ftmp-security.t
+++ b/t/lib/ftmp-security.t
@@ -1,10 +1,4 @@
-#!./perl
-
-BEGIN {
- chdir 't' if -d 't';
- unshift @INC, '../lib';
-}
-
+#!/usr/local/bin/perl -w
# Test for File::Temp - Security levels
# Some of the security checking will not work on all platforms
@@ -16,6 +10,13 @@ use Test;
BEGIN { plan tests => 13}
use File::Spec;
+
+# Set up END block - this needs to happen before we load
+# File::Temp since this END block must be evaluated after the
+# END block configured by File::Temp
+my @files; # list of files to remove
+END { foreach (@files) { ok( !(-e $_) )} }
+
use File::Temp qw/ tempfile unlink0 /;
ok(1);
@@ -87,17 +88,7 @@ sub test_security {
return;
}
-
- # End blocks are evaluated in reverse order
- # If I want to check that the file was unlinked by the autmoatic
- # feature of the module I have to set up the end block before
- # creating the file.
- # Use quoted end block to retain access to lexicals
- my @files;
-
- eval q{ END { foreach (@files) { ok( !(-e $_) )} } 1; } || die;
-
-
+ # Create the tempfile
my $template = "temptestXXXXXXXX";
my ($fh1, $fname1) = tempfile ( $template,
DIR => File::Spec->curdir,
diff --git a/t/lib/ftmp-tempfile.t b/t/lib/ftmp-tempfile.t
index 9c0de8b955..517151a3b8 100755
--- a/t/lib/ftmp-tempfile.t
+++ b/t/lib/ftmp-tempfile.t
@@ -1,30 +1,30 @@
-#!./perl
-
-BEGIN {
- chdir 't' if -d 't';
- unshift @INC, '../lib';
-}
-
+#!/usr/local/bin/perl -w
# Test for File::Temp - tempfile function
use strict;
use Test;
-BEGIN { plan tests => 10}
+BEGIN { plan tests => 11}
use File::Spec;
-use File::Temp qw/ tempfile tempdir/;
# Will need to check that all files were unlinked correctly
-# Set up an END block here to do it (since the END blocks
-# set up by File::Temp will be evaluated in reverse order we
-# set ours up first....
+# Set up an END block here to do it
+
+my (@files, @dirs); # Array containing list of dirs/files to test
# Loop over an array hoping that the files dont exist
-my @files;
-eval q{ END { foreach (@files) { ok( !(-e $_) )} } 1; } || die;
+END { foreach (@files) { ok( !(-e $_) )} }
# And a test for directories
-my @dirs;
-eval q{ END { foreach (@dirs) { ok( !(-d $_) )} } 1; } || die;
+END { foreach (@dirs) { ok( !(-d $_) )} }
+
+# Need to make sure that the END blocks are setup before
+# the ones that File::Temp configures since END blocks are evaluated
+# in revers order and we need to check the files *after* File::Temp
+# removes them
+use File::Temp qw/ tempfile tempdir/;
+
+# Now we start the tests properly
+ok(1);
# Tempfile
@@ -88,5 +88,5 @@ print "# TEMPFILE: Created $tempfile\n";
ok( (-f $tempfile) );
push(@files, $tempfile);
-# no tests yet to make sure that the END{} blocks correctly remove
-# the files
+# Now END block will execute to test the removal of directories
+