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