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