-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.t
52 lines (40 loc) · 1.08 KB
/
hooks.t
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
use Test::Stream;
use Test::Stream::XS qw/_test_run_hooks _test_run_hook refcount/;
my $ctx = {};
my @ran;
_test_run_hooks($ctx, 0, [
sub {
is(refcount($ctx), 2, "2 refs to the context");
is($_[0], $ctx, "got ctx A");
push @ran => 'a';
},
sub {
is(refcount($ctx), 2, "2 refs to the context");
is($_[0], $ctx, "got ctx B");
push @ran => 'b';
},
]);
is_deeply(\@ran, [qw/a b/], "Both hooks ran");
@ran = ();
_test_run_hooks($ctx, 1, [
sub {
is(refcount($ctx), 2, "2 refs to the context");
is($_[0], $ctx, "got ctx A");
push @ran => 'a';
},
sub {
is(refcount($ctx), 2, "2 refs to the context");
is($_[0], $ctx, "got ctx B");
push @ran => 'b';
},
]);
is_deeply(\@ran, [qw/b a/], "Both hooks ran, reversed");
@ran = ();
_test_run_hook($ctx, sub {
is(refcount($ctx), 2, "2 refs to the context");
is($_[0], $ctx, "got ctx IT");
push @ran => 'IT';
});
is_deeply(\@ran, ['IT'], "Single hook");
is(refcount($ctx), 1, "1 ref to the context remains");
done_testing;