use consistent sorting, so memoization works properly
[gitmo/Eval-Closure.git] / t / 10-errors.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use Test::More;
5 use Test::Exception;
6
7 use Eval::Closure;
8
9 throws_ok {
10     eval_closure()
11 } qr/'source'.*required/, "error when source isn't declared";
12
13 throws_ok {
14     eval_closure(
15         source => {},
16     )
17 } qr/'source'.*string or array/, "error when source isn't string or array";
18
19 throws_ok {
20     eval_closure(
21         source => '1',
22     )
23 } qr/'source'.*return.*sub/, "error when source doesn't return a sub";
24
25 throws_ok {
26     eval_closure(
27         source      => 'sub { }',
28         environment => { 'foo' => \1 },
29     )
30 } qr/should start with \@, \%, or \$/, "error from malformed env";
31
32 throws_ok {
33     eval_closure(
34         source      => 'sub { }',
35         environment => { '$foo' => 1 },
36     )
37 } qr/must be.*reference/, "error from non-ref value";
38
39 throws_ok {
40     eval_closure(
41         source => '$1++',
42     )
43 } qr/Modification of a read-only value/, "gives us compile errors properly";
44
45 done_testing;