summaryrefslogtreecommitdiffstats
path: root/t/lexical-env.t
diff options
context:
space:
mode:
Diffstat (limited to 't/lexical-env.t')
-rw-r--r--t/lexical-env.t53
1 files changed, 53 insertions, 0 deletions
diff --git a/t/lexical-env.t b/t/lexical-env.t
new file mode 100644
index 0000000..24d4885
--- /dev/null
+++ b/t/lexical-env.t
@@ -0,0 +1,53 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Fatal;
+
+use Eval::Closure;
+
+{
+ my $source = 'sub { ++$foo }';
+
+ {
+ like(
+ exception {
+ eval_closure(source => $source);
+ },
+ qr/Global symbol "\$foo/,
+ "errors with strict enabled"
+ );
+ }
+
+ {
+ no strict;
+ my $c1;
+ is(
+ exception {
+ $c1 = eval_closure(source => $source);
+ },
+ undef,
+ "no errors with no strict"
+ );
+ is($c1->(), 1);
+ is($c1->(), 2);
+ }
+}
+
+{
+ my $source = 'our $less; BEGIN { $less = $^H{less} } sub { $less }';
+
+ {
+ my $c1 = eval_closure(source => $source);
+ is($c1->(), undef, "nothing in the hint hash");
+ }
+
+ {
+ local $TODO = 'not sure how exactly to get %^H copied';
+ use less "stuff";
+ my $c1 = eval_closure(source => $source);
+ is($c1->(), 'stuff', "use less put stuff in the hints hash");
+ }
+}
+
+done_testing;