This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Updated Filter-Util-Call to CPAN version 1.39
[perl5.git] / cpan / Sys-Syslog / t / constants.t
1 #!perl -wT
2 use strict;
3 use File::Spec;
4 use Test::More;
5
6 # NB. For PERL_CORE to be set, taint mode must not be enabled
7 my $macrosall = 'macros.all';
8 open(MACROS, $macrosall) or plan skip_all => "can't read '$macrosall': $!";
9 my @names = map {chomp;$_} <MACROS>;
10 close(MACROS);
11 plan tests => @names * 2 + 2;
12
13 my $callpack = my $testpack = 'Sys::Syslog';
14 eval "use $callpack";
15
16 eval "${callpack}::This()";
17 like( $@, "/^This is not a valid $testpack macro/", "trying a non-existing macro");
18
19 eval "${callpack}::NOSUCHNAME()";
20 like( $@, "/^NOSUCHNAME is not a valid $testpack macro/", "trying a non-existing macro");
21
22 # Testing all macros
23 if(@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 }