Test scripts for I18N::Langinfo and POSIX
[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 my @path_consts = qw(
20     _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON _PC_MAX_INPUT
21     _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX _PC_PIPE_BUF _PC_VDISABLE
22 );
23
24 my @sys_consts = qw(
25     _SC_ARG_MAX _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
26     _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_PAGESIZE _SC_SAVED_IDS
27     _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
28 );
29
30 plan tests => 2 * 3 * @path_consts + 3 * @sys_consts;
31
32 my $r;
33
34 # testing fpathconf()
35 SKIP: {
36     my $fd = POSIX::open(File::Spec->curdir, O_RDONLY)
37         or skip "can't open current directory", 3 * @path_consts;
38
39     for my $constant (@path_consts) {
40         $r = eval { pathconf( File::Spec->curdir, eval "$constant()" ) };
41         is( $@, '', "calling pathconf($constant)" );
42         ok( defined $r, "\tchecking that the returned value is defined: $r" );
43         ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
44     }
45 }
46
47 # testing pathconf()
48 for my $constant (@path_consts) {
49     $r = eval { pathconf( File::Spec->rootdir, eval "$constant()" ) };
50     is( $@, '', "calling pathconf($constant)" );
51     ok( defined $r, "\tchecking that the returned value is defined: $r" );
52     ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
53 }
54
55 # testing sysconf()
56 for my $constant (@sys_consts) {
57     $r = eval { sysconf( eval "$constant()" ) };
58     is( $@, '', "calling sysconf($constant)" );
59     ok( defined $r, "\tchecking that the returned value is defined: $r" );
60     ok( looks_like_number($r), "\tchecking that the returned value looks like a number" );
61 }
62