5 unshift @INC, '../lib';
8 # Test for mktemp family of commands in File::Temp
9 # Use STANDARD safe level for these tests
13 BEGIN { plan tests => 9 }
17 use File::Temp qw/ :mktemp unlink0 /;
23 # Create file in temp directory
24 my $template = File::Spec->catfile(File::Spec->tmpdir, 'wowserXXXX');
26 (my $fh, $template) = mkstemp($template);
28 print "# MKSTEMP: FH is $fh File is $template fileno=".fileno($fh)."\n";
29 # Check if the file exists
33 $fh->autoflush(1) if $] >= 5.006;
35 # Try printing something to the file
36 my $string = "woohoo\n";
45 # compare with previous string
49 # This test fails on Windows NT since it seems that the size returned by
50 # stat(filehandle) does not always equal the size of the stat(filename)
51 # This must be due to caching. In particular this test writes 7 bytes
52 # to the file which are not recognised by stat(filename)
54 if ($^O eq 'MSWin32') {
57 ok( unlink0($fh, $template) );
61 # File with suffix. This is created in the current directory
63 $template = "suffixXXXXXX";
66 ($fh, my $fname) = mkstemps($template, $suffix);
68 print "# MKSTEMPS: File is $template -> $fname fileno=".fileno($fh)."\n";
69 # Check if the file exists
72 ok( unlink0($fh, $fname) );
78 $template = File::Spec->catdir(File::Spec->tmpdir, 'tmpdirXXXXXX');
80 my $tmpdir = mkdtemp($template);
82 print "# MKDTEMP: Name is $tmpdir from template $template\n";
86 # Need to tidy up after myself
90 # Just a filename, not opened
92 $template = File::Spec->catfile(File::Spec->tmpdir, 'mytestXXXXXX');
94 my $tmpfile = mktemp($template);
96 print "# MKTEMP: Tempfile is $template -> $tmpfile\n";
98 # Okay if template no longer has XXXXX in
101 ok( ($tmpfile !~ /XXXXX$/) );