5 unshift @INC, '../lib';
8 # Test for File::Temp - tempfile function
12 BEGIN { plan tests => 10}
14 use File::Temp qw/ tempfile tempdir/;
16 # Will need to check that all files were unlinked correctly
17 # Set up an END block here to do it (since the END blocks
18 # set up by File::Temp will be evaluated in reverse order we
19 # set ours up first....
21 # Loop over an array hoping that the files dont exist
23 eval q{ END { foreach (@files) { ok( !(-e $_) )} } 1; } || die;
25 # And a test for directories
27 eval q{ END { foreach (@dirs) { ok( !(-d $_) )} } 1; } || die;
31 # Open tempfile in some directory, unlink at end
32 my ($fh, $tempfile) = tempfile(
38 push(@files, $tempfile);
41 # Create temp directory in current dir
42 my $template = 'tmpdirXXXXXX';
43 print "# Template: $template\n";
44 my $tempdir = tempdir( $template ,
45 DIR => File::Spec->curdir,
49 print "# TEMPDIR: $tempdir\n";
52 push(@dirs, $tempdir);
54 # Create file in the temp dir
55 ($fh, $tempfile) = tempfile(
61 print "# TEMPFILE: Created $tempfile\n";
64 push(@files, $tempfile);
68 ($fh, $tempfile) = tempfile(
74 push(@files, $tempfile);
76 print "# TEMPFILE: Created $tempfile\n";
78 # and another (with template)
80 ($fh, $tempfile) = tempfile( 'helloXXXXXXX',
86 print "# TEMPFILE: Created $tempfile\n";
89 push(@files, $tempfile);
91 # no tests yet to make sure that the END{} blocks correctly remove