File: 11-new.t

package info (click to toggle)
libsnmp-extension-passpersist-perl 0.06-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 168 kB
  • sloc: perl: 746; makefile: 3
file content (68 lines) | stat: -rw-r--r-- 1,600 bytes parent folder | download | duplicates (5)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!perl
use strict;
use warnings;
use Test::More;
use lib "t/lib";
use SNMP::Extension::PassPersist;


my $module = "SNMP::Extension::PassPersist";
my @cases  = (
    {
        attr => [],
        diag => qr/^$/,
    },
    {
        attr => [ {} ],
        diag => qr/^$/,
    },
    {
        attr => [ 42 ],
        diag => qr/^error: Odd number of arguments/,
    },
    {
        attr => [ 1, 2, 3 ],
        diag => qr/^error: Odd number of arguments/,
    },
    {   # unknown attributes are ignored
        attr => [ foo => "bar" ],
        diag => qr/^$/,
    },
    {
        attr => [ { foo => "bar" } ],
        diag => qr/^$/,
    },
    {
        attr => [ \my $var ],
        diag => qr/^error: Don't know how to handle scalar reference/,
    },
    {
        attr => [ [] ],
        diag => qr/^error: Don't know how to handle array reference/,
    },
    {
        attr => [ sub {} ],
        diag => qr/^error: Don't know how to handle code reference/,
    },
    {   # checking that code attributes are correctly checked
        attr => [ backend_init => sub {} ],
        diag => qr/^$/,
    },
    {
        attr => [ backend_init => [] ],
        diag => qr/^error: Attribute backend_init must be a code reference/,
    },
    {
        attr => [ backend_init => {} ],
        diag => qr/^error: Attribute backend_init must be a code reference/,
    },
);

plan tests => ~~@cases;

for my $case (@cases) {
    my $attr = $case->{attr};
    my $diag = $case->{diag};
    my $object = eval { $module->new(@$attr) };
    like( $@, $diag, "$module->new(".join(", ", @$attr).")" );
}