4 require_ok 'PublicInbox::OnDestroy';
6 my $od = PublicInbox::OnDestroy->new(sub { push @x, 'hi' });
7 is_deeply(\@x, [], 'not called, yet');
9 is_deeply(\@x, [ 'hi' ], 'no args works');
10 $od = PublicInbox::OnDestroy->new(sub { $x[0] = $_[0] }, 'bye');
11 is_deeply(\@x, [ 'hi' ], 'nothing changed while alive');
13 is_deeply(\@x, [ 'bye' ], 'arg passed');
14 $od = PublicInbox::OnDestroy->new(sub { @x = @_ }, qw(x y));
16 is_deeply(\@x, [ 'x', 'y' ], '2 args passed');
18 open my $tmp, '+>>', undef or BAIL_OUT $!;
20 $od = PublicInbox::OnDestroy->new(1, sub { print $tmp "$$ DESTROY\n" });
22 is(-s $tmp, 0, '$tmp is empty on pid mismatch');
23 $od = PublicInbox::OnDestroy->new($$, sub { $tmp = $$ });
25 is($tmp, $$, '$tmp set to $$ by callback');
27 $od = PublicInbox::OnDestroy->new($$, sub { $tmp = 'foo' });
30 isnt($tmp, 'foo', '->cancel');
32 if (my $nr = $ENV{TEST_LEAK_NR}) {
34 $od = PublicInbox::OnDestroy->new(sub { @x = @_ }, qw(x y));