typo fix
[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::Fatal;
6
7 use Eval::Closure;
8
9 like(
10     exception { eval_closure() },
11     qr/'source'.*required/,
12     "error when source isn't declared"
13 );
14
15 like(
16     exception { eval_closure(source => {}) },
17     qr/'source'.*string or array/,
18     "error when source isn't string or array"
19 );
20
21 like(
22     exception { eval_closure(source => 1) },
23     qr/'source'.*return.*sub/,
24     "error when source doesn't return a sub"
25 );
26
27 like(
28     exception {
29         eval_closure(
30             source      => 'sub { }',
31             environment => { 'foo' => \1 },
32         )
33     },
34     qr/should start with \@, \%, or \$/,
35     "error from malformed env"
36 );
37
38 like(
39     exception {
40         eval_closure(
41             source      => 'sub { }',
42             environment => { '$foo' => 1 },
43         )
44     },
45     qr/must be.*reference/,
46     "error from non-ref value"
47 );
48
49 like(
50     exception { eval_closure(source => '$1++') },
51     qr/Modification of a read-only value/,
52     "gives us compile errors properly"
53 );
54
55 done_testing;