Once again syncing after too long an absence
[p5sagit/p5-mst-13.2.git] / t / lib / ftmp-posix.t
CommitLineData
4b19af01 1#!/usr/bin/perl -w
2# Test for File::Temp - POSIX functions
ee8c7f54 3
4BEGIN {
4b19af01 5 chdir 't' if -d 't';
22d4bb9c 6 @INC = '../lib';
4b19af01 7 require Test; import Test;
8 plan(tests => 7);
ee8c7f54 9}
10
ee8c7f54 11use strict;
ee8c7f54 12
13use File::Temp qw/ :POSIX unlink0 /;
0e06870b 14use FileHandle;
15
ee8c7f54 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
22d4bb9c 30# TMPNAM list context
ee8c7f54 31# Not strict posix behaviour
32(my $fh, $tmpnam) = tmpnam();
33
22d4bb9c 34print "# TMPNAM: in list context: $fh $tmpnam\n";
ee8c7f54 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);