xref: /openbsd-src/gnu/usr.bin/perl/cpan/Sys-Syslog/t/constants.t (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1#!perl -wT
2use strict;
3use File::Spec;
4use Test::More;
5
6# NB. For PERL_CORE to be set, taint mode must not be enabled
7my $macrosall = 'macros.all';
8open(MACROS, $macrosall) or plan skip_all => "can't read '$macrosall': $!";
9my @names = map {chomp;$_} <MACROS>;
10close(MACROS);
11plan tests => @names * 2 + 2;
12
13my $callpack = my $testpack = 'Sys::Syslog';
14eval "use $callpack";
15
16eval "${callpack}::This()";
17like( $@, "/^This is not a valid $testpack macro/", "trying a non-existing macro");
18
19eval "${callpack}::NOSUCHNAME()";
20like( $@, "/^NOSUCHNAME is not a valid $testpack macro/", "trying a non-existing macro");
21
22# Testing all macros
23if(@names) {
24    for my $name (@names) {
25        SKIP: {
26            $name =~ /^(\w+)$/ or skip "invalid name '$name'", 2;
27            $name = $1;
28            my $v = eval "${callpack}::$name()";
29
30            if(defined $v and $v =~ /^\d+$/) {
31                is( $@, '', "calling the constant $name as a function" );
32                like( $v, '/^\d+$/', "checking that $name is a number ($v)" );
33
34            } else {
35                like( $@, "/^Your vendor has not defined $testpack macro $name/",
36                    "calling the constant via its name" );
37                skip "irrelevant test in this case", 1
38            }
39        }
40    }
41}
42