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