File Coverage

File:t/03-on-warn.t
Coverage:84.9%

linestmtbrancondsubpodtimecode
1
1
1
1
2874
2
24
use strict;
2
1
1
1
3
1
32
use warnings;
3
1
1
1
252
2
50
use Dispatch::Fu;
4
1
1
1
360
78033
7
use Test::More tests => 4;
5
6
1
69058
my $error = q{};
7{
8
1
1
0
3
    local $@;
9
1
1
0
1
3
0
    eval { dispatch { return q{foo} } 1 };
10
1
3
    $error = $@;
11}
12
1
4
like $error, qr/no cases defined/i,
13  q{croaks with the expected diagnostic if no cases are defined};
14
15
1
228
$error = q{};
16{
17
1
1
1
1
    local $@;
18
1
1
1
0
1
4
1
0
    eval { dispatch { return q{foo} } 1, on bar => sub { 1 } };
19
1
3
    $error = $@;
20}
21
1
3
like $error, qr/Computed static bucket "foo" not found/i,
22  q{croaks if dispatch returns an unregistered case};
23
24
1
196
my $warning = q{};
25{
26
1
1
1
1
4
3
    local $SIG{__WARN__} = sub { $warning .= shift };
27
1
0
2
0
    on foo => sub { 1 };
28}
29
1
4
like $warning, qr/follows a comma/i,
30  q{'on' warns when used in void context};
31
32
1
193
$warning = q{};
33{
34
1
1
1
1
4
3
    local $SIG{__WARN__} = sub { $warning .= shift };
35
1
0
3
0
    my $ignored = on foo => sub { 1 };
36}
37
1
4
like $warning, qr/follows a comma/i,
38  q{'on' warns when used in scalar context};
39