X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2Fftmp-tempfile.t;h=48a52b3c92e9292adbdcee261c4430b8d23f1632;hb=22d4bb9ccb8701e68f9243547d7e3a3c55f70908;hp=3cb73c20e0c8647bd4262e7d052c924c49fe4efc;hpb=4b19af017623bfa3bb72bb164598a517f586e0d3;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/lib/ftmp-tempfile.t b/t/lib/ftmp-tempfile.t index 3cb73c2..48a52b3 100755 --- a/t/lib/ftmp-tempfile.t +++ b/t/lib/ftmp-tempfile.t @@ -1,26 +1,37 @@ -#!/usr/bin/perl -w +#!/usr/local/bin/perl -w # Test for File::Temp - tempfile function BEGIN { chdir 't' if -d 't'; - unshift @INC, '../lib'; + @INC = '../lib'; require Test; import Test; - plan(tests => 11); + plan(tests => 16); } use strict; use File::Spec; # Will need to check that all files were unlinked correctly -# Set up an END block here to do it - -my (@files, @dirs); # Array containing list of dirs/files to test +# Set up an END block here to do it + +# Arrays containing list of dirs/files to test +my (@files, @dirs, @still_there); + +# And a test for files that should still be around +# These are tidied up +END { + foreach (@still_there) { + ok( -f $_ ); + ok( unlink( $_ ) ); + ok( !(-f $_) ); + } +} # Loop over an array hoping that the files dont exist END { foreach (@files) { ok( !(-e $_) )} } # And a test for directories -END { foreach (@dirs) { ok( !(-d $_) )} } +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 @@ -93,5 +104,14 @@ print "# TEMPFILE: Created $tempfile\n"; ok( (-f $tempfile) ); push(@files, $tempfile); + +# Create a temporary file that should stay around after +# it has been closed +($fh, $tempfile) = tempfile( 'permXXXXXXX', UNLINK => 0 ); +print "# TEMPFILE: Created $tempfile\n"; +ok( -f $tempfile ); +ok( close( $fh ) ); +push( @still_there, $tempfile); # check at END + # Now END block will execute to test the removal of directories