Commit | Line | Data |
a650b841 |
1 | #!perl -wT |
8168e71f |
2 | use strict; |
04f98b29 |
3 | use File::Spec; |
8168e71f |
4 | use Test::More; |
8168e71f |
5 | |
a8a27574 |
6 | # NB. For PERL_CORE to be set, taint mode must not be enabled |
04f98b29 |
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; |
8168e71f |
13 | |
04f98b29 |
14 | my $callpack = my $testpack = 'Sys::Syslog'; |
15 | eval "use $callpack"; |
8168e71f |
16 | |
04f98b29 |
17 | eval "${callpack}::This()"; |
18 | like( $@, "/^This is not a valid $testpack macro/", "trying a non-existing macro"); |
8168e71f |
19 | |
04f98b29 |
20 | eval "${callpack}::NOSUCHNAME()"; |
21 | like( $@, "/^NOSUCHNAME is not a valid $testpack macro/", "trying a non-existing macro"); |
8168e71f |
22 | |
23 | # Testing all macros |
24 | if(@names) { |
25 | for my $name (@names) { |
04f98b29 |
26 | SKIP: { |
27 | $name =~ /^(\w+)$/ or skip "invalid name '$name'", 2; |
28 | $name = $1; |
29 | my $v = eval "${callpack}::$name()"; |
30 | |
6e4ef777 |
31 | if(defined $v and $v =~ /^\d+$/) { |
04f98b29 |
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 | } |
8168e71f |
41 | } |
42 | } |