summaryrefslogtreecommitdiffstats
path: root/t/10-errors.t
blob: d8925eebbcb47e596f24838d25fd5426c9a4f067 (plain) (blame)
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
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Exception;

use Eval::Closure;

throws_ok {
    eval_closure()
} qr/'source'.*required/, "error when source isn't declared";

throws_ok {
    eval_closure(
        source => {},
    )
} qr/'source'.*string or array/, "error when source isn't string or array";

throws_ok {
    eval_closure(
        source => '1',
    )
} qr/'source'.*return.*sub/, "error when source doesn't return a sub";

throws_ok {
    eval_closure(
        source      => 'sub { }',
        environment => { 'foo' => \1 },
    )
} qr/should start with \@, \%, or \$/, "error from malformed env";

throws_ok {
    eval_closure(
        source      => 'sub { }',
        environment => { '$foo' => 1 },
    )
} qr/must be.*reference/, "error from non-ref value";

throws_ok {
    eval_closure(
        source => '$1++',
    )
} qr/Modification of a read-only value/, "gives us compile errors properly";

done_testing;