summaryrefslogtreecommitdiffstats
path: root/t/lexical-env.t
blob: 24d4885fc02ab6622fcdc515335eba8526667274 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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;