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