Retract #8552.
[p5sagit/p5-mst-13.2.git] / t / lib / ftmp-posix.t
CommitLineData
e2cf2bdb 1#!/usr/bin/perl -w
262eb13a 2# Test for File::Temp - POSIX functions
3
e2cf2bdb 4BEGIN {
5 chdir 't' if -d 't';
20822f61 6 @INC = '../lib';
e2cf2bdb 7 require Test; import Test;
8 plan(tests => 7);
9}
10
262eb13a 11use strict;
262eb13a 12
13use File::Temp qw/ :POSIX unlink0 /;
f5cf745e 14use FileHandle;
15
262eb13a 16ok(1);
17
18# TMPNAM - scalar
19
20print "# TMPNAM: in a scalar context: \n";
21my $tmpnam = tmpnam();
22
23# simply check that the file does not exist
24# Not a 100% water tight test though if another program
25# has managed to create one in the meantime.
26ok( !(-e $tmpnam ));
27
28print "# TMPNAM file name: $tmpnam\n";
29
91e74348 30# TMPNAM list context
262eb13a 31# Not strict posix behaviour
32(my $fh, $tmpnam) = tmpnam();
33
91e74348 34print "# TMPNAM: in list context: $fh $tmpnam\n";
262eb13a 35
36# File is opened - make sure it exists
37ok( (-e $tmpnam ));
38
39# Unlink it
40ok( unlink0($fh, $tmpnam) );
41
42# TMPFILE
43
44$fh = tmpfile();
45
46ok( $fh );
47print "# TMPFILE: tmpfile got FH $fh\n";
48
49$fh->autoflush(1) if $] >= 5.006;
50
51# print something to it
52my $original = "Hello a test\n";
53print "# TMPFILE: Wrote line: $original";
54print $fh $original
55 or die "Error printing to tempfile\n";
56
57# rewind it
58ok( seek($fh,0,0) );
59
60
61# Read from it
62my $line = <$fh>;
63
64print "# TMPFILE: Read line: $line";
65ok( $original, $line);
66
67close($fh);