summaryrefslogtreecommitdiff
path: root/lib/File/Temp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/File/Temp')
-rw-r--r--lib/File/Temp/t/object.t18
-rwxr-xr-xlib/File/Temp/t/tempfile.t4
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/File/Temp/t/object.t b/lib/File/Temp/t/object.t
index 5828866f0f..c485d634ed 100644
--- a/lib/File/Temp/t/object.t
+++ b/lib/File/Temp/t/object.t
@@ -2,7 +2,7 @@
# Test for File::Temp - OO interface
use strict;
-use Test::More tests => 18;
+use Test::More tests => 26;
use File::Spec;
# Will need to check that all files were unlinked correctly
@@ -64,6 +64,7 @@ $fh = new File::Temp(
SUFFIX => '.dat',
);
+ok( $fh->unlink_on_destroy, "should unlink");
print "# TEMPFILE: Created $fh\n";
ok( (-f "$fh"), "File $fh exists in tempdir?");
@@ -97,11 +98,26 @@ $fh = new File::Temp( TEMPLATE => 'permXXXXXXX', UNLINK => 0);
print "# TEMPFILE: Created $fh\n";
ok( -f "$fh", "File $fh exists?" );
ok( close( $fh ), "Close file $fh" );
+ok( ! $fh->unlink_on_destroy, "should not unlink");
push( @still_there, "$fh"); # check at END
+# Now create a temp file that will remain when the object
+# goes out of scope because of $KEEP_ALL
+$fh = new File::Temp( TEMPLATE => 'permXXXXXXX', UNLINK => 1);
+
+print "# TEMPFILE: Created $fh\n";
+ok( -f "$fh", "File $fh exists?" );
+ok( close( $fh ), "Close file $fh" );
+ok( $fh->unlink_on_destroy, "should unlink (in principal)");
+push( @still_there, "$fh"); # check at END
+$File::Temp::KEEP_ALL = 1;
+
# Make sure destructors run
undef $fh;
+# allow end blocks to run
+$File::Temp::KEEP_ALL = 0;
+
# Now END block will execute to test the removal of directories
print "# End of tests. Execute END blocks\n";
diff --git a/lib/File/Temp/t/tempfile.t b/lib/File/Temp/t/tempfile.t
index c8739bf531..7021645704 100755
--- a/lib/File/Temp/t/tempfile.t
+++ b/lib/File/Temp/t/tempfile.t
@@ -91,8 +91,8 @@ push(@files, $tempfile);
# Test tempfile
# ..and another with changed permissions (read-only)
($fh, $tempfile) = tempfile(
- DIR => $tempdir,
- );
+ DIR => $tempdir,
+ );
chmod 0444, $tempfile;
ok( (-f $tempfile ));