Move Sys-Syslog from ext/ to cpan/
[p5sagit/p5-mst-13.2.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 = $ENV{PERL_CORE} ? File::Spec->catfile(qw(.. ext Sys-Syslog macros.all))
8                                 : 'macros.all';
9 open(MACROS, $macrosall) or plan skip_all => "can't read '$macrosall': $!";
10 my @names = map {chomp;$_} <MACROS>;
11 close(MACROS);
12 plan tests => @names * 2 + 2;
13
14 my $callpack = my $testpack = 'Sys::Syslog';
15 eval "use $callpack";
16
17 eval "${callpack}::This()";
18 like( $@, "/^This is not a valid $testpack macro/", "trying a non-existing macro");
19
20 eval "${callpack}::NOSUCHNAME()";
21 like( $@, "/^NOSUCHNAME is not a valid $testpack macro/", "trying a non-existing macro");
22
23 # Testing all macros
24 if(@names) {
25     for my $name (@names) {
26         SKIP: {
27             $name =~ /^(\w+)$/ or skip "invalid name '$name'", 2;
28             $name = $1;
29             my $v = eval "${callpack}::$name()";
30
31             if(defined $v and $v =~ /^\d+$/) {
32                 is( $@, '', "calling the constant $name as a function" );
33                 like( $v, '/^\d+$/', "checking that $name is a number ($v)" );
34
35             } else {
36                 like( $@, "/^Your vendor has not defined $testpack macro $name/", 
37                     "calling the constant via its name" );
38                 skip "irrelevant test in this case", 1
39             }
40         }
41     }
42 }