File: 20-constants.t

package info (click to toggle)
libnet-pcap-perl 0.21-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 636 kB
  • sloc: perl: 2,155; pascal: 830; ansic: 5; makefile: 3
file content (41 lines) | stat: -rw-r--r-- 1,225 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!perl -T
use strict;
use File::Spec;
use Test::More;

my $macrosall = 'macros.all';
open(MACROS, $macrosall) or plan skip_all => "can't read '$macrosall': $!";
my @names = map {chomp;$_} <MACROS>;
close(MACROS);
plan tests => @names * 2 + 2;

my $callpack = 'Net::Pcap';
my $testpack = 'pcap';
eval "use $callpack";

eval "${callpack}::This()";
like( $@, "/^This is not a valid $testpack macro/", "trying a non-existing macro");

eval "${callpack}::NOSUCHNAME()";
like( $@, "/^NOSUCHNAME is not a valid $testpack macro/", "trying a non-existing macro");

# Testing all macros
if(@names) {
    for my $name (@names) {
        SKIP: {
            $name =~ /^(\w+)$/ or skip "invalid name '$name'", 2;
            $name = $1;
            my $v = eval "${callpack}::$name()";

            if(defined $v and $v =~ /^\d+$/) {
                is( $@, '', "calling the constant $name as a function" );
                like( $v, '/^\d+$/', "checking that $name is a number ($v)" );

            } else {
                like( $@, "/^Your vendor has not defined $testpack macro $name/", 
                    "calling the constant via its name" );
                skip "irrelevant test in this case", 1
            }
        }
    }
}