1 #!/usr/local/bin/perl -w
2 # Test for File::Temp - POSIX functions
6 BEGIN { plan tests => 7}
8 use File::Temp qw/ :POSIX unlink0 /;
13 print "# TMPNAM: in a scalar context: \n";
14 my $tmpnam = tmpnam();
16 # simply check that the file does not exist
17 # Not a 100% water tight test though if another program
18 # has managed to create one in the meantime.
21 print "# TMPNAM file name: $tmpnam\n";
23 # TMPNAM array context
24 # Not strict posix behaviour
25 (my $fh, $tmpnam) = tmpnam();
27 print "# TMPNAM: in array context: $fh $tmpnam\n";
29 # File is opened - make sure it exists
33 ok( unlink0($fh, $tmpnam) );
40 print "# TMPFILE: tmpfile got FH $fh\n";
42 $fh->autoflush(1) if $] >= 5.006;
44 # print something to it
45 my $original = "Hello a test\n";
46 print "# TMPFILE: Wrote line: $original";
48 or die "Error printing to tempfile\n";
57 print "# TMPFILE: Read line: $line";
58 ok( $original, $line);