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