use strict;
use Test;
BEGIN { plan tests => 9 }
use File::Spec;
use File::Path;
use File::Temp qw/ :mktemp unlink0 /;
use FileHandle;
ok(1);
my $template = File::Spec->catfile(File::Spec->tmpdir, 'wowserXXXX');
(my $fh, $template) = mkstemp($template);
print "# MKSTEMP: FH is $fh File is $template fileno=".fileno($fh)."\n";
ok( (-e $template) );
$fh->autoflush(1) if $] >= 5.006;
my $string = "woohoo\n";
print $fh $string;
ok(seek( $fh, 0, 0));
my $line = <$fh>;
ok($string, $line);
if ($^O eq 'MSWin32') {
sleep 3;
}
my $status = unlink0($fh, $template);
if ($status) {
ok( $status );
} else {
skip("Skip test failed probably due to \$TMPDIR being on NFS",1);
}
$template = "suffixXXXXXX";
my $suffix = ".dat";
($fh, my $fname) = mkstemps($template, $suffix);
print "# MKSTEMPS: File is $template -> $fname fileno=".fileno($fh)."\n";
ok( (-e $fname) );
$status = unlink0($fh, $fname);
if ($status) {
ok($status);
} else {
skip("Skip test failed probably due to cwd being on NFS",1)
}
$template = File::Spec->catdir(File::Spec->tmpdir, 'tmpdirXXXXXX');
my $tmpdir = mkdtemp($template);
print "# MKDTEMP: Name is $tmpdir from template $template\n";
ok( (-d $tmpdir ) );
rmtree($tmpdir);
$template = File::Spec->catfile(File::Spec->tmpdir, 'mytestXXXXXX');
my $tmpfile = mktemp($template);
print "# MKTEMP: Tempfile is $template -> $tmpfile\n";
ok( ($tmpfile !~ /XXXXX$/) );