use strict;
use Test;
BEGIN { plan tests => 22}
use File::Spec;
my (@files, @dirs, @still_there);
END {
foreach (@still_there) {
ok( -f $_ );
ok( unlink( $_ ) );
ok( !(-f $_) );
}
}
END { foreach (@files) { ok( !(-e $_) )} }
END { foreach (@dirs) { ok( !(-d $_) )} }
use File::Temp qw/ tempfile tempdir/;
ok(1);
my ($fh, $tempfile) = tempfile(
UNLINK => 1,
SUFFIX => '.txt',
);
ok( (-f $tempfile) );
ok( close( $fh ) );
ok( (-f $tempfile) );
push(@files, $tempfile);
my $template = 'tmpdirXXXXXX';
print "# Template: $template\n";
my $tempdir = tempdir( $template ,
DIR => File::Spec->curdir,
CLEANUP => 1,
);
print "# TEMPDIR: $tempdir\n";
ok( (-d $tempdir) );
push(@dirs, $tempdir);
($fh, $tempfile) = tempfile(
DIR => $tempdir,
UNLINK => 1,
SUFFIX => '.dat',
);
print "# TEMPFILE: Created $tempfile\n";
ok( (-f $tempfile));
push(@files, $tempfile);
($fh, $tempfile) = tempfile(
DIR => $tempdir,
);
ok( (-f $tempfile ));
push(@files, $tempfile);
($fh, $tempfile) = tempfile(
DIR => $tempdir,
);
chmod 0444, $tempfile;
ok( (-f $tempfile ));
push(@files, $tempfile);
print "# TEMPFILE: Created $tempfile\n";
($fh, $tempfile) = tempfile( 'helloXXXXXXX',
DIR => $tempdir,
UNLINK => 1,
SUFFIX => '.dat',
);
print "# TEMPFILE: Created $tempfile\n";
ok( (-f $tempfile) );
push(@files, $tempfile);
($fh, $tempfile) = tempfile( 'permXXXXXXX', UNLINK => 0 );
print "# TEMPFILE: Created $tempfile\n";
ok( -f $tempfile );
ok( close( $fh ) );
push( @still_there, $tempfile);
$fh = eval { tempfile( 'ftmpXXXXX', DIR => File::Spec->tmpdir ) };
if ($fh) {
ok( print $fh "Test\n" );
ok( close($fh) );
} else {
skip "Skip Failed probably due to NFS", 1;
skip "Skip Failed probably due to NFS", 1;
}
print "# End of tests. Execute END blocks\n";