File: basic.t

package info (click to toggle)
libeval-closure-perl 0.14-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, stretch
  • size: 196 kB
  • ctags: 12
  • sloc: perl: 559; makefile: 2
file content (48 lines) | stat: -rw-r--r-- 896 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Fatal;

use Eval::Closure;

{
    my $code = eval_closure(
        source => 'sub { die "called\n" }',
    );
    ok($code, "got something");

    like(exception { $code->() }, qr/^called$/, "got the right thing");
}

{
    my $foo = [];

    my $code = eval_closure(
        source      => 'sub { push @$bar, @_ }',
        environment => {
            '$bar' => \$foo,
        },
    );
    ok($code, "got something");

    $code->(1);

    is_deeply($foo, [1], "got the right thing");
}

{
    my $foo = [1, 2, 3];

    my $code = eval_closure(
        # not sure if strict leaking into evals is intended, i think i remember
        # it being changed in newer perls
        source => 'do { no strict; sub { $foo } }',
    );

    ok($code, "got something");

    ok(!$code->(), "environment is clean");
}

done_testing;