File: 01_api.t

package info (click to toggle)
libdancer-perl 1.3202%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,408 kB
  • ctags: 638
  • sloc: perl: 7,215; xml: 1,977; sh: 51; makefile: 29; sql: 5
file content (41 lines) | stat: -rw-r--r-- 1,212 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
use strict;
use warnings;
use Test::More import => ['!pass'];

use Dancer ':syntax';

plan tests => 10;

my $cpt = 0;

ok( hook( 'before' => sub { $cpt += shift || 1 }), 'add a before filter');

my $app = Dancer::App->current->name;
is scalar @{ Dancer::Factory::Hook->instance->get_hooks_for('before') }, 1, 'got one before filter';

my $hooks = Dancer::Factory::Hook->instance->get_hooks_for('before');
is scalar @$hooks, 1, 'got one before filter';

Dancer::Factory::Hook->instance->execute_hooks('before');
is $cpt, 1, 'execute hooks without args';

Dancer::Factory::Hook->instance->execute_hooks( 'before', 2 );
is $cpt, 3, 'execute hooks with one arg';


sub exception (&) { eval { $_[0]->() }; return $@ }

ok(
    hook('before' => sub { $cpt += 2; undef $_ }),
    'add a bad filter that manipulates $_'
);

$cpt = 0;
is(exception { Dancer::Factory::Hook->instance->execute_hooks('before', 5) },
    '', 'execute_hooks() lives with bad hooks');
is($cpt, 7, 'execute hooks with one arg, ok result');

$cpt = 0;
is(exception { Dancer::Factory::Hook->instance->execute_hooks('before', 8) },
    '', 'execute_hooks() lives second time with bad hooks');
is($cpt, 10, 'execute hooks with one arg, ok result');