SYN SYN
[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 /;
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
22d4bb9c 28# TMPNAM list context
ee8c7f54 29# Not strict posix behaviour
30(my $fh, $tmpnam) = tmpnam();
31
22d4bb9c 32print "# TMPNAM: in list context: $fh $tmpnam\n";
ee8c7f54 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);