In DEC OSF aka Digital UNIX aka Tru64 add the version
[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';
6 unshift @INC, '../lib';
7 require Test; import Test;
8 plan(tests => 7);
9}
10
262eb13a 11use strict;
262eb13a 12
13use File::Temp qw/ :POSIX unlink0 /;
14ok(1);
15
16# TMPNAM - scalar
17
18print "# TMPNAM: in a scalar context: \n";
19my $tmpnam = tmpnam();
20
21# simply check that the file does not exist
22# Not a 100% water tight test though if another program
23# has managed to create one in the meantime.
24ok( !(-e $tmpnam ));
25
26print "# TMPNAM file name: $tmpnam\n";
27
28# TMPNAM array context
29# Not strict posix behaviour
30(my $fh, $tmpnam) = tmpnam();
31
32print "# TMPNAM: in array context: $fh $tmpnam\n";
33
34# File is opened - make sure it exists
35ok( (-e $tmpnam ));
36
37# Unlink it
38ok( unlink0($fh, $tmpnam) );
39
40# TMPFILE
41
42$fh = tmpfile();
43
44ok( $fh );
45print "# TMPFILE: tmpfile got FH $fh\n";
46
47$fh->autoflush(1) if $] >= 5.006;
48
49# print something to it
50my $original = "Hello a test\n";
51print "# TMPFILE: Wrote line: $original";
52print $fh $original
53 or die "Error printing to tempfile\n";
54
55# rewind it
56ok( seek($fh,0,0) );
57
58
59# Read from it
60my $line = <$fh>;
61
62print "# TMPFILE: Read line: $line";
63ok( $original, $line);
64
65close($fh);