2 # Test for File::Temp - tempfile function
6 unshift @INC, '../lib';
7 require Test; import Test;
14 # Will need to check that all files were unlinked correctly
15 # Set up an END block here to do it
17 my (@files, @dirs); # Array containing list of dirs/files to test
19 # Loop over an array hoping that the files dont exist
20 END { foreach (@files) { ok( !(-e $_) )} }
22 # And a test for directories
23 END { foreach (@dirs) { ok( !(-d $_) )} }
25 # Need to make sure that the END blocks are setup before
26 # the ones that File::Temp configures since END blocks are evaluated
27 # in revers order and we need to check the files *after* File::Temp
29 use File::Temp qw/ tempfile tempdir/;
31 # Now we start the tests properly
36 # Open tempfile in some directory, unlink at end
37 my ($fh, $tempfile) = tempfile(
43 push(@files, $tempfile);
46 # Create temp directory in current dir
47 my $template = 'tmpdirXXXXXX';
48 print "# Template: $template\n";
49 my $tempdir = tempdir( $template ,
50 DIR => File::Spec->curdir,
54 print "# TEMPDIR: $tempdir\n";
57 push(@dirs, $tempdir);
59 # Create file in the temp dir
60 ($fh, $tempfile) = tempfile(
66 print "# TEMPFILE: Created $tempfile\n";
69 push(@files, $tempfile);
73 ($fh, $tempfile) = tempfile(
79 push(@files, $tempfile);
81 print "# TEMPFILE: Created $tempfile\n";
83 # and another (with template)
85 ($fh, $tempfile) = tempfile( 'helloXXXXXXX',
91 print "# TEMPFILE: Created $tempfile\n";
94 push(@files, $tempfile);
96 # Now END block will execute to test the removal of directories