Integrate perlio:
[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
0e939f40 39# Unlink it - a possible NFS issue again if TMPDIR is not a local disk
40my $status = unlink0($fh, $tmpnam);
41if ($status) {
42 ok( $status );
43} else {
44 skip("Skip test failed probably due to \$TMPDIR being on NFS",1);
45}
262eb13a 46
47# TMPFILE
48
49$fh = tmpfile();
50
0e939f40 51if (defined $fh) {
52 ok( $fh );
53 print "# TMPFILE: tmpfile got FH $fh\n";
54
55 $fh->autoflush(1) if $] >= 5.006;
56
57 # print something to it
58 my $original = "Hello a test\n";
59 print "# TMPFILE: Wrote line: $original";
60 print $fh $original
61 or die "Error printing to tempfile\n";
262eb13a 62
0e939f40 63 # rewind it
64 ok( seek($fh,0,0) );
262eb13a 65
0e939f40 66 # Read from it
67 my $line = <$fh>;
262eb13a 68
0e939f40 69 print "# TMPFILE: Read line: $line";
70 ok( $original, $line);
71
72 close($fh);
73
74} else {
75 # Skip all the remaining tests
76 foreach (1..3) {
77 skip("Skip test failed probably due to \$TMPDIR being on NFS",1);
78 }
79}
262eb13a 80
81
262eb13a 82
262eb13a 83