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