Add test for Net::protoent.
[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 - a possible NFS issue again if TMPDIR is not a local disk
40 my $status = unlink0($fh, $tmpnam);
41 if ($status) {
42   ok( $status );
43 } else {
44   skip("Skip test failed probably due to \$TMPDIR being on NFS",1);
45 }
46
47 # TMPFILE
48
49 $fh = tmpfile();
50
51 if (defined $fh) {
52   ok( $fh );
53   print "# TMPFILE: tmpfile got FH $fh\n";
54
55   $fh->autoflush(1) if $] >= 5.006;
56
57   # print something to it
58   my $original = "Hello a test\n";
59   print "# TMPFILE: Wrote line: $original";
60   print $fh $original
61     or die "Error printing to tempfile\n";
62
63   # rewind it
64   ok( seek($fh,0,0) );
65
66   # Read from it
67   my $line = <$fh>;
68
69   print "# TMPFILE: Read line: $line";
70   ok( $original, $line);
71
72   close($fh);
73
74 } else {
75   # Skip all the remaining tests
76   foreach (1..3) {
77     skip("Skip test failed probably due to \$TMPDIR being on NFS",1);
78   }
79 }
80
81
82
83