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 |
b5ffec61 |
7 | my $macrosall = 'macros.all'; |
04f98b29 |
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; |
8168e71f |
12 | |
04f98b29 |
13 | my $callpack = my $testpack = 'Sys::Syslog'; |
14 | eval "use $callpack"; |
8168e71f |
15 | |
04f98b29 |
16 | eval "${callpack}::This()"; |
17 | like( $@, "/^This is not a valid $testpack macro/", "trying a non-existing macro"); |
8168e71f |
18 | |
04f98b29 |
19 | eval "${callpack}::NOSUCHNAME()"; |
20 | like( $@, "/^NOSUCHNAME is not a valid $testpack macro/", "trying a non-existing macro"); |
8168e71f |
21 | |
22 | # Testing all macros |
23 | if(@names) { |
24 | for my $name (@names) { |
04f98b29 |
25 | SKIP: { |
26 | $name =~ /^(\w+)$/ or skip "invalid name '$name'", 2; |
27 | $name = $1; |
28 | my $v = eval "${callpack}::$name()"; |
29 | |
6e4ef777 |
30 | if(defined $v and $v =~ /^\d+$/) { |
04f98b29 |
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 | } |
8168e71f |
40 | } |
41 | } |