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