summaryrefslogtreecommitdiffstats
path: root/t/errors.t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-08-01 23:27:34 -0500
committerJesse Luehrs <doy@tozt.net>2011-08-01 23:27:34 -0500
commit7fdc514fb2d9768b3d38d078cf24d9d03403539b (patch)
treee479a548f1c1c73e2a8082b36386aff5460469c3 /t/errors.t
parent1a2acf758e0e3bcd0694753469d237ebc356e8c1 (diff)
downloadeval-closure-7fdc514fb2d9768b3d38d078cf24d9d03403539b.tar.gz
eval-closure-7fdc514fb2d9768b3d38d078cf24d9d03403539b.zip
remove test numbers
Diffstat (limited to 't/errors.t')
-rw-r--r--t/errors.t67
1 files changed, 67 insertions, 0 deletions
diff --git a/t/errors.t b/t/errors.t
new file mode 100644
index 0000000..905d6c8
--- /dev/null
+++ b/t/errors.t
@@ -0,0 +1,67 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Fatal;
+
+use Eval::Closure;
+
+like(
+ exception { eval_closure() },
+ qr/'source'.*required/,
+ "error when source isn't declared"
+);
+
+like(
+ exception { eval_closure(source => {}) },
+ qr/'source'.*string or array/,
+ "error when source isn't string or array"
+);
+
+like(
+ exception { eval_closure(source => 1) },
+ qr/'source'.*return.*sub/,
+ "error when source doesn't return a sub"
+);
+
+like(
+ exception {
+ eval_closure(
+ source => 'sub { }',
+ environment => { 'foo' => \1 },
+ )
+ },
+ qr/should start with \@, \%, or \$/,
+ "error from malformed env"
+);
+
+like(
+ exception {
+ eval_closure(
+ source => 'sub { }',
+ environment => { '$foo' => 1 },
+ )
+ },
+ qr/must be.*reference/,
+ "error from non-ref value"
+);
+
+like(
+ exception { eval_closure(source => '$1++') },
+ qr/Modification of a read-only value/,
+ "gives us compile errors properly"
+);
+
+like(
+ exception { eval_closure(source => 'sub { $x }') },
+ qr/sub \s* { \s* \$x \s* }/x,
+ "without terse_error, includes the source code"
+);
+
+unlike(
+ exception { eval_closure(source => 'sub { $x }', terse_error => 1) },
+ qr/sub \s* { \s* \$x \s* }/x,
+ "with terse_error, does not include the source code"
+);
+
+done_testing;