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