Integrate perlio:
[p5sagit/p5-mst-13.2.git] / t / lib / ftmp-mktemp.t
index c660475..4e31d01 100755 (executable)
@@ -1,20 +1,21 @@
-#!./perl
-
-BEGIN {
-    chdir 't' if -d 't';
-    unshift @INC, '../lib';
-}
+#!/usr/bin/perl -w
 
 # Test for mktemp family of commands in File::Temp
 # Use STANDARD safe level for these tests
 
+BEGIN {
+       chdir 't' if -d 't';
+       @INC = '../lib';
+       require Test; import Test;
+       plan(tests => 9);
+}
+
 use strict;
-use Test;
-BEGIN { plan tests => 9 }
 
 use File::Spec;
 use File::Path;
 use File::Temp qw/ :mktemp unlink0 /;
+use FileHandle;
 
 ok(1);
 
@@ -30,7 +31,7 @@ print "# MKSTEMP: FH is $fh File is $template fileno=".fileno($fh)."\n";
 ok( (-e $template) );
 
 # Autoflush
-$fh->autoflush(1) if $] >= 5.006; 
+$fh->autoflush(1) if $] >= 5.006;
 
 # Try printing something to the file
 my $string = "woohoo\n";
@@ -50,15 +51,21 @@ 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;
 }
-ok( unlink0($fh, $template) );
-
+my $status = unlink0($fh, $template);
+if ($status) {
+  ok( $status );
+} else {
+  skip("Skip test failed probably due to \$TMPDIR being on NFS",1);
+}
 
 # MKSTEMPS
-# File with suffix. This is created in the current directory
+# File with suffix. This is created in the current directory so
+# may be problematic on NFS
 
 $template = "suffixXXXXXX";
 my $suffix = ".dat";
@@ -69,8 +76,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
+$status = unlink0($fh, $fname);
 
+if ($status) {
+  ok($status);
+} else {
+  skip("Skip test failed probably due to cwd being on NFS",1)
+}
 
 # MKDTEMP
 # Temp directory