summaryrefslogtreecommitdiff
path: root/lib/File/Temp/t/object.t
diff options
context:
space:
mode:
Diffstat (limited to 'lib/File/Temp/t/object.t')
-rw-r--r--lib/File/Temp/t/object.t18
1 files changed, 17 insertions, 1 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";