File: basic.t

package info (click to toggle)
libb-hooks-op-check-entersubforcv-perl 0.10-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 176 kB
  • sloc: perl: 1,339; ansic: 10; makefile: 3
file content (103 lines) | stat: -rw-r--r-- 1,429 bytes parent folder | download | duplicates (6)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use strict;
use warnings;
use Test::More tests => 20;

BEGIN { use_ok('B::Hooks::OP::Check::EntersubForCV') }

sub foo { 'affe'  }
sub bar { 'birne' }

my ($i, $cv);
BEGIN {
    $i = 0;
    $cv = \&foo;
}

sub entersub_cb {
    my ($code) = @_;
    $i++;
    is($code->(), 'affe', 'got the right coderef');
}

foo();

my @id;

BEGIN {
    is($i, 0, 'no callback yet');

    push @id, B::Hooks::OP::Check::EntersubForCV::register($cv, \&entersub_cb);
    is($i, 0, 'no callback after registration');
}

foo();
bar();

BEGIN {
    is($i, 1, 'simple callback');
    $i = 0;
}

my $x = \&foo;

BEGIN {
    is($i, 0, '\&foo does not issue a callback');
    $i = 0;
}

&foo;
&foo();

BEGIN {
    TODO: {
        local $TODO = 'TODO';
        is($i, 2, '&foo and &foo() issue a callback');
    }

    $i = 0;
}

foo();
bar();
foo();

BEGIN {
    is($i, 2, 'multiple callbacks');

    push @id, B::Hooks::OP::Check::EntersubForCV::register($cv, \&entersub_cb);
    is($i, 2, 'no callback after multiple registrations');

    $i = 0;
}

foo();
bar();
foo();

BEGIN {
    is($i, 4, 'multiple callbacks for multiple entersubs');

    B::Hooks::OP::Check::EntersubForCV::unregister(pop @id);

    $i = 0;
}

foo();
bar();
foo();

BEGIN {
    is($i, 2, 'deregistration');

    B::Hooks::OP::Check::EntersubForCV::unregister(pop @id);

    $i = 0;
}

foo();
bar();
foo();

BEGIN {
    is($i, 0, 'no callbacks after removing all registers');
}