This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Devel::PPPort 3.09
[perl5.git] / ext / POSIX / t / sysconf.t
CommitLineData
6e32c255
AT
1#!perl -T
2
3BEGIN {
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
14use strict;
15use File::Spec;
16use POSIX;
17use Scalar::Util qw(looks_like_number);
18
19my @path_consts = qw(
220f811a
JH
20 _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_NAME_MAX
21 _PC_NO_TRUNC _PC_PATH_MAX
22);
23
24my @path_consts_terminal = qw(
25 _PC_MAX_CANON _PC_MAX_INPUT _PC_VDISABLE
26);
27
28my @path_consts_fifo = qw(
29 _PC_PIPE_BUF
6e32c255
AT
30);
31
32my @sys_consts = qw(
33 _SC_ARG_MAX _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
34 _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_PAGESIZE _SC_SAVED_IDS
35 _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
36);
37
220f811a
JH
38plan tests => 2 * 3 * @path_consts +
39 3 * @path_consts_terminal +
40 2 * 3 * @path_consts_fifo +
41 3 * @sys_consts;
42
43my $curdir = File::Spec->curdir;
6e32c255
AT
44
45my $r;
46
220f811a 47# testing fpathconf() on a non-terminal file
6e32c255 48SKIP: {
220f811a
JH
49 my $fd = POSIX::open($curdir, O_RDONLY)
50 or skip "could not open current directory ($!)", 3 * @path_consts;
6e32c255
AT
51
52 for my $constant (@path_consts) {
220f811a
JH
53 $r = eval { fpathconf( $fd, eval "$constant()" ) };
54 is( $@, '', "calling fpathconf($fd, $constant) " );
6e32c255
AT
55 ok( defined $r, "\tchecking that the returned value is defined: $r" );
56 ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
57 }
220f811a
JH
58
59 POSIX::close($fd);
6e32c255
AT
60}
61
220f811a 62# testing pathconf() on a non-terminal file
6e32c255 63for my $constant (@path_consts) {
220f811a
JH
64 $r = eval { pathconf( $curdir, eval "$constant()" ) };
65 is( $@, '', qq[calling pathconf("$curdir", $constant)] );
6e32c255
AT
66 ok( defined $r, "\tchecking that the returned value is defined: $r" );
67 ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
68}
69
220f811a
JH
70SKIP: {
71 -c "/dev/tty"
72 or skip("/dev/tty not a character file", 3 * @path_consts_terminal);
73
74 # testing pathconf() on a terminal file
75 for my $constant (@path_consts_terminal) {
76 $r = eval { pathconf( "/dev/tty", eval "$constant()" ) };
77 is( $@, '', qq[calling pathconf("/dev/tty", $constant)] );
78 ok( defined $r, "\tchecking that the returned value is defined: $r" );
79 ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
80 }
81}
82
83my $fifo = "fifo$$";
84
85SKIP: {
86 mkfifo($fifo, 0666)
87 or skip("could not create fifo $fifo ($!)", 2 * 3 * @path_consts_fifo);
88
89 SKIP: {
90 my $fd = POSIX::open($fifo, O_RDWR)
91 or skip("could not open $fifo ($!)", 3 * @path_consts_fifo);
92
93 for my $constant (@path_consts_fifo) {
94 $r = eval { fpathconf( $fd, eval "$constant()" ) };
95 is( $@, '', "calling fpathconf($fd, $constant) " );
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 POSIX::close($fd);
101 }
102
103 SKIP: {
104 # testing pathconf() on a fifo file
105 for my $constant (@path_consts_fifo) {
106 $r = eval { pathconf( $fifo, eval "$constant()" ) };
107 is( $@, '', qq[calling pathconf($fifo, $constant)] );
108 ok( defined $r, "\tchecking that the returned value is defined: $r" );
109 ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
110 }
111 }
112}
113
114unlink($fifo);
115
6e32c255
AT
116# testing sysconf()
117for my $constant (@sys_consts) {
118 $r = eval { sysconf( eval "$constant()" ) };
119 is( $@, '', "calling sysconf($constant)" );
120 ok( defined $r, "\tchecking that the returned value is defined: $r" );
121 ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
122}
123