Upgrade to File::Temp 0.08 from Tim Jenness via CPAN.
[p5sagit/p5-mst-13.2.git] / t / lib / ftmp-posix.t
CommitLineData
1c19c868 1#!/usr/local/bin/perl -w
262eb13a 2# Test for File::Temp - POSIX functions
3
4use strict;
5use Test;
6BEGIN { plan tests => 7}
7
8use File::Temp qw/ :POSIX unlink0 /;
9ok(1);
10
11# TMPNAM - scalar
12
13print "# TMPNAM: in a scalar context: \n";
14my $tmpnam = tmpnam();
15
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.
19ok( !(-e $tmpnam ));
20
21print "# TMPNAM file name: $tmpnam\n";
22
23# TMPNAM array context
24# Not strict posix behaviour
25(my $fh, $tmpnam) = tmpnam();
26
27print "# TMPNAM: in array context: $fh $tmpnam\n";
28
29# File is opened - make sure it exists
30ok( (-e $tmpnam ));
31
32# Unlink it
33ok( unlink0($fh, $tmpnam) );
34
35# TMPFILE
36
37$fh = tmpfile();
38
39ok( $fh );
40print "# TMPFILE: tmpfile got FH $fh\n";
41
42$fh->autoflush(1) if $] >= 5.006;
43
44# print something to it
45my $original = "Hello a test\n";
46print "# TMPFILE: Wrote line: $original";
47print $fh $original
48 or die "Error printing to tempfile\n";
49
50# rewind it
51ok( seek($fh,0,0) );
52
53
54# Read from it
55my $line = <$fh>;
56
57print "# TMPFILE: Read line: $line";
58ok( $original, $line);
59
60close($fh);