Move ExtUtils::Manifest from ext/ to cpan/
[p5sagit/p5-mst-13.2.git] / cpan / File-Temp / t / posix.t
1 #!/usr/local/bin/perl -w
2 # Test for File::Temp - POSIX functions
3
4 use strict;
5 use Test;
6 BEGIN { plan tests => 7}
7
8 use File::Temp qw/ :POSIX unlink0 /;
9 use FileHandle;
10 ok(1);
11
12 # TMPNAM - scalar
13
14 print "# TMPNAM: in a scalar context: \n";
15 my $tmpnam = tmpnam();
16
17 # simply check that the file does not exist
18 # Not a 100% water tight test though if another program 
19 # has managed to create one in the meantime.
20 ok( !(-e $tmpnam ));
21
22 print "# TMPNAM file name: $tmpnam\n";
23
24 # TMPNAM list context
25 # Not strict posix behaviour
26 (my $fh, $tmpnam) = tmpnam();
27
28 print "# TMPNAM: in list context: $fh $tmpnam\n";
29
30 # File is opened - make sure it exists
31 ok( (-e $tmpnam ));
32
33 # Unlink it - a possible NFS issue again if TMPDIR is not a local disk
34 my $status = unlink0($fh, $tmpnam);
35 if ($status) {
36   ok( $status );
37 } else {
38   skip("Skip test failed probably due to \$TMPDIR being on NFS",1);
39 }
40
41 # TMPFILE
42
43 $fh = tmpfile();
44
45 if (defined $fh) {
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   # Read from it
61   my $line = <$fh>;
62
63   print "# TMPFILE: Read line: $line";
64   ok( $original, $line);
65
66   close($fh);
67
68 } else {
69   # Skip all the remaining tests
70   foreach (1..3) {
71     skip("Skip test failed probably due to \$TMPDIR being on NFS",1);
72   }
73 }
74
75
76
77