summaryrefslogtreecommitdiff
path: root/ext/POSIX/t/usage.t
blob: 24e6a7e9163d5961208b7947a5fa782e7d9187b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!./perl -w

use strict;
use Test::More;
use Config;

plan(skip_all => "POSIX is unavailable")
    unless $Config{extensions} =~ /\bPOSIX\b/;

require POSIX;

my %valid;
my @all;

my $argc = 0;
for my $list ([qw(errno fork getchar getegid geteuid getgid getgroups getlogin
		  getpgrp getpid getppid gets getuid time wait)],
	      [qw(abs alarm assert chdir closedir cos exit exp fabs fstat getc
		  getenv getgrgid getgrnam getpwnam getpwuid gmtime isatty
		  localtime log opendir raise readdir remove rewind rewinddir
		  rmdir sin sleep sqrt stat strerror system tolower toupper
		  umask unlink)],
	      [qw(atan2 chmod creat kill link mkdir pow rename strstr waitpid)],
	      [qw(chown fcntl utime)]) {
    $valid{$_} = $argc foreach @$list;
    push @all, @$list;
    ++$argc;
}

my @try = 0 .. $argc - 1;
foreach my $func (sort @all) {
    my $arg_pat = join ', ', ('[a-z]+') x $valid{$func};
    my $expect = qr/\AUsage: POSIX::$func\($arg_pat\) at \(eval/;
    foreach my $try (@try) {
	next if $valid{$func} == $try;
	my $call = "POSIX::$func(" . join(', ', 1 .. $try) . ')';
	is(eval "$call; 1", undef, "$call fails");
	like($@, $expect, "POSIX::$func for $try arguments gives expected error")
    }
}

foreach my $func (qw(printf sprintf)) {
    is(eval "POSIX::$func(); 1", undef, "POSIX::$func() fails");
    like($@, qr/\AUsage: POSIX::$func\(pattern, args\.\.\.\) at \(eval/,
	 "POSIX::$func for 0 arguments gives expected error");
}

done_testing();