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 = $ENV{PERL_CORE} ? File::Spec->catfile(qw(.. ext Sys Syslog macros.all)) 8 : 'macros.all'; 9open(MACROS, $macrosall) or plan skip_all => "can't read '$macrosall': $!"; 10my @names = map {chomp;$_} <MACROS>; 11close(MACROS); 12plan tests => @names * 2 + 2; 13 14my $callpack = my $testpack = 'Sys::Syslog'; 15eval "use $callpack"; 16 17eval "${callpack}::This()"; 18like( $@, "/^This is not a valid $testpack macro/", "trying a non-existing macro"); 19 20eval "${callpack}::NOSUCHNAME()"; 21like( $@, "/^NOSUCHNAME is not a valid $testpack macro/", "trying a non-existing macro"); 22 23# Testing all macros 24if(@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} 43