sysconf.t: still failing in tru64, try harder to skip
[p5sagit/p5-mst-13.2.git] / ext / POSIX / t / sysconf.t
1 #!perl -T
2
3 BEGIN {
4     if ($ENV{PERL_CORE}) {
5         chdir 't';
6         @INC = '../lib';
7     }
8
9     use Config;
10     use Test::More;
11     plan skip_all => "POSIX is unavailable" if $Config{'extensions'} !~ m!\bPOSIX\b!;
12 }
13
14 use strict;
15 use File::Spec;
16 use POSIX;
17 use Scalar::Util qw(looks_like_number);
18
19 sub check(@) {
20     grep { eval "&$_;1" or $@!~/vendor has not defined POSIX macro/ } @_
21 }       
22
23 my @path_consts = check qw(
24     _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_NAME_MAX
25     _PC_NO_TRUNC _PC_PATH_MAX
26 );
27
28 my @path_consts_terminal = check qw(
29     _PC_MAX_CANON _PC_MAX_INPUT _PC_VDISABLE
30 );
31
32 my @path_consts_fifo = check qw(
33     _PC_PIPE_BUF
34 );
35
36 my @sys_consts = check qw(
37     _SC_ARG_MAX _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
38     _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_PAGESIZE _SC_SAVED_IDS
39     _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
40 );
41
42 my $tests = 2 * 3 * @path_consts +
43             2 * 3 * @path_consts_terminal +
44             2 * 3 * @path_consts_fifo +
45                 3 * @sys_consts;
46 plan $tests 
47      ? (tests => $tests) 
48      : (skip_all => "No tests to run on this OS")
49 ;
50
51 my $curdir = File::Spec->curdir;
52
53 my $r;
54
55 # testing fpathconf() on a non-terminal file
56 SKIP: {
57     my $fd = POSIX::open($curdir, O_RDONLY)
58         or skip "could not open current directory ($!)", 3 * @path_consts;
59
60     for my $constant (@path_consts) {
61         $r = eval { fpathconf( $fd, eval "$constant()" ) };
62         is( $@, '', "calling fpathconf($fd, $constant) " );
63         ok( defined $r, "\tchecking that the returned value is defined: $r" );
64         ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
65     }
66     
67     POSIX::close($fd);
68 }
69
70 # testing pathconf() on a non-terminal file
71 for my $constant (@path_consts) {
72     $r = eval { pathconf( $curdir, eval "$constant()" ) };
73     is( $@, '', qq[calling pathconf("$curdir", $constant)] );
74     ok( defined $r, "\tchecking that the returned value is defined: $r" );
75     ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
76 }
77
78 SKIP: {
79     my $TTY = "/dev/tty";
80
81     my $n = 2 * 3 * @path_consts_terminal;
82
83     -c $TTY
84         or skip("$TTY not a character file", $n);
85     open(TTY, $TTY)
86         or skip("failed to open $TTY: $!", $n);
87     -t TTY
88         or skip("TTY ($TTY) not a terminal file", $n);
89
90     my $fd = fileno(TTY);
91
92     # testing fpathconf() on a terminal file
93     for my $constant (@path_consts_terminal) {
94         $r = eval { fpathconf( $fd, eval "$constant()" ) };
95         is( $@, '', qq[calling fpathconf($fd, $constant) ($TTY)] );
96         ok( defined $r, "\tchecking that the returned value is defined: $r" );
97         ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
98     }
99     
100     close($fd);
101     # testing pathconf() on a terminal file
102     for my $constant (@path_consts_terminal) {
103         $r = eval { pathconf( $TTY, eval "$constant()" ) };
104         is( $@, '', qq[calling pathconf($TTY, $constant)] );
105         ok( defined $r, "\tchecking that the returned value is defined: $r" );
106         ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
107     }
108 }
109
110 my $fifo = "fifo$$";
111
112 SKIP: {
113     eval { mkfifo($fifo, 0666) }
114         or skip("could not create fifo $fifo ($!)", 2 * 3 * @path_consts_fifo);
115
116   SKIP: {
117       my $fd = POSIX::open($fifo, O_RDWR)
118           or skip("could not open $fifo ($!)", 3 * @path_consts_fifo);
119
120       for my $constant (@path_consts_fifo) {
121           $r = eval { fpathconf( $fd, eval "$constant()" ) };
122           is( $@, '', "calling fpathconf($fd, $constant) ($fifo)" );
123           ok( defined $r, "\tchecking that the returned value is defined: $r" );
124           ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
125       }
126     
127       POSIX::close($fd);
128   }
129
130   SKIP: {
131       # testing pathconf() on a fifo file
132       for my $constant (@path_consts_fifo) {
133           $r = eval { pathconf( $fifo, eval "$constant()" ) };
134           is( $@, '', qq[calling pathconf($fifo, $constant)] );
135           ok( defined $r, "\tchecking that the returned value is defined: $r" );
136           ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
137       }
138   }
139 }
140
141 END {
142     1 while unlink($fifo);
143 }
144
145 # testing sysconf()
146 for my $constant (@sys_consts) {
147  SKIP: {
148         skip "Saved IDs broken on Mac OS X (Perl #24122)", 3
149             if $^O eq 'darwin' && $constant eq '_SC_SAVED_IDS';
150         $r = eval { sysconf( eval "$constant()" ) };
151         is( $@, '', "calling sysconf($constant)" );
152         ok( defined $r, "\tchecking that the returned value is defined: $r" );
153         ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
154     }
155 }
156