is setting up hints as in the caller a sane thing to do?
[gitmo/Eval-Closure.git] / t / lexical-env.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 {
10     my $source = 'sub { ++$foo }';
11
12     {
13         like(
14             exception {
15                 eval_closure(source => $source);
16             },
17             qr/Global symbol "\$foo/,
18             "errors with strict enabled"
19         );
20     }
21
22     {
23         no strict;
24         my $c1;
25         is(
26             exception {
27                 $c1 = eval_closure(source => $source);
28             },
29             undef,
30             "no errors with no strict"
31         );
32         is($c1->(), 1);
33         is($c1->(), 2);
34     }
35 }
36
37 {
38     my $source = 'our $less; BEGIN { $less = $^H{less} } sub { $less }';
39
40     {
41         my $c1 = eval_closure(source => $source);
42         is($c1->(), undef, "nothing in the hint hash");
43     }
44
45     {
46         local $TODO = 'not sure how exactly to get %^H copied';
47         use less "stuff";
48         my $c1 = eval_closure(source => $source);
49         is($c1->(), 'stuff', "use less put stuff in the hints hash");
50     }
51 }
52
53 done_testing;