remove test numbers
[gitmo/Eval-Closure.git] / t / errors.t
CommitLineData
9736bf12 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
01b68b64 5use Test::Fatal;
9736bf12 6
7use Eval::Closure;
8
01b68b64 9like(
10 exception { eval_closure() },
11 qr/'source'.*required/,
12 "error when source isn't declared"
13);
14
15like(
16 exception { eval_closure(source => {}) },
17 qr/'source'.*string or array/,
18 "error when source isn't string or array"
19);
20
21like(
22 exception { eval_closure(source => 1) },
23 qr/'source'.*return.*sub/,
24 "error when source doesn't return a sub"
25);
26
27like(
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
38like(
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
49like(
50 exception { eval_closure(source => '$1++') },
51 qr/Modification of a read-only value/,
52 "gives us compile errors properly"
53);
9736bf12 54
5617e966 55like(
56 exception { eval_closure(source => 'sub { $x }') },
57 qr/sub \s* { \s* \$x \s* }/x,
58 "without terse_error, includes the source code"
59);
60
61unlike(
62 exception { eval_closure(source => 'sub { $x }', terse_error => 1) },
63 qr/sub \s* { \s* \$x \s* }/x,
64 "with terse_error, does not include the source code"
65);
66
9736bf12 67done_testing;