Commit | Line | Data |
6e32c255 |
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 | my @path_consts = qw( |
220f811a |
20 | _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_NAME_MAX |
21 | _PC_NO_TRUNC _PC_PATH_MAX |
22 | ); |
23 | |
24 | my @path_consts_terminal = qw( |
25 | _PC_MAX_CANON _PC_MAX_INPUT _PC_VDISABLE |
26 | ); |
27 | |
28 | my @path_consts_fifo = qw( |
29 | _PC_PIPE_BUF |
6e32c255 |
30 | ); |
31 | |
32 | my @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 |
38 | plan tests => 2 * 3 * @path_consts + |
39 | 3 * @path_consts_terminal + |
40 | 2 * 3 * @path_consts_fifo + |
41 | 3 * @sys_consts; |
42 | |
43 | my $curdir = File::Spec->curdir; |
6e32c255 |
44 | |
45 | my $r; |
46 | |
220f811a |
47 | # testing fpathconf() on a non-terminal file |
6e32c255 |
48 | SKIP: { |
220f811a |
49 | my $fd = POSIX::open($curdir, O_RDONLY) |
50 | or skip "could not open current directory ($!)", 3 * @path_consts; |
6e32c255 |
51 | |
52 | for my $constant (@path_consts) { |
220f811a |
53 | $r = eval { fpathconf( $fd, eval "$constant()" ) }; |
54 | is( $@, '', "calling fpathconf($fd, $constant) " ); |
6e32c255 |
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 |
58 | |
59 | POSIX::close($fd); |
6e32c255 |
60 | } |
61 | |
220f811a |
62 | # testing pathconf() on a non-terminal file |
6e32c255 |
63 | for my $constant (@path_consts) { |
220f811a |
64 | $r = eval { pathconf( $curdir, eval "$constant()" ) }; |
65 | is( $@, '', qq[calling pathconf("$curdir", $constant)] ); |
6e32c255 |
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 |
70 | SKIP: { |
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 | |
83 | my $fifo = "fifo$$"; |
84 | |
85 | SKIP: { |
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 | |
114 | unlink($fifo); |
115 | |
6e32c255 |
116 | # testing sysconf() |
117 | for 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 | |