Async-Hooks
view release on metacpan or search on metacpan
t/20-hooks.t view on Meta::CPAN
#!perl
use strict;
use warnings;
use Test::More;
use Test::Deep;
use Test::Fatal;
use Async::Hooks;
subtest 'registry tests' => sub {
my $nc = Async::Hooks->new;
ok($nc);
my $r = $nc->registry;
ok($r);
is(ref($r), 'HASH');
is(scalar(%$r), 0);
is($nc->has_hooks_for('h1'), 0);
$nc->hook('h1', sub { });
$r = $nc->registry;
is(scalar(keys %$r), 1);
is($nc->has_hooks_for('h1'), 1);
$nc->hook('h1', sub { });
$r = $nc->registry;
is(scalar(keys %$r), 1);
is($nc->has_hooks_for('h1'), 2);
is($nc->has_hooks_for('h2'), 0);
$nc->hook('h2', sub { });
$r = $nc->registry;
is(scalar(keys %$r), 2);
$nc->hook('h2', sub { });
is($nc->has_hooks_for('h2'), 2);
};
subtest 'basic tests' => sub {
my ($nc, $called, $reset) = hook_test_setup();
foreach my $try (1 .. 3) {
$reset->();
$nc->call('h1');
cmp_deeply($called, {h1_1 => 1, h1_2 => 1}, "h1, try $try");
$reset->();
$nc->call('h2', [], sub { $called->{'clean'}++ });
cmp_deeply($called, {h2_1 => 1, h2_2 => 1, clean => 1}, "h2, try $try");
$reset->();
$nc->call('non-existent');
cmp_deeply($called, {}, "non-existent, try $try");
$reset->();
$nc->call('non-existent', [], sub { $called->{'clean'}++ });
cmp_deeply($called, {clean => 1}, "non-existent with clean, try $try");
}
};
subtest 'is_done flag tests' => sub {
( run in 0.781 second using v1.01-cache-2.11-cpan-54e63673c56 )