is setting up hints as in the caller a sane thing to do?
[gitmo/Eval-Closure.git] / t / basic.t
CommitLineData
efb592ef 1#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
01b68b64 5use Test::Fatal;
efb592ef 6
ce19c70b 7use Eval::Closure;
efb592ef 8
9736bf12 9{
10 my $code = eval_closure(
11 source => 'sub { die "called\n" }',
12 );
13 ok($code, "got something");
efb592ef 14
01b68b64 15 like(exception { $code->() }, qr/^called$/, "got the right thing");
9736bf12 16}
efb592ef 17
9736bf12 18{
19 my $foo = [];
efb592ef 20
9736bf12 21 my $code = eval_closure(
22 source => 'sub { push @$bar, @_ }',
23 environment => {
24 '$bar' => \$foo,
25 },
9736bf12 26 );
27 ok($code, "got something");
28
29 $code->(1);
30
31 is_deeply($foo, [1], "got the right thing");
32}
33
34{
35 my $foo = [1, 2, 3];
36
37 my $code = eval_closure(
9736bf12 38 source => 'do { no strict; sub { $foo } }',
39 );
40
41 ok($code, "got something");
42
43 ok(!$code->(), "environment is clean");
44}
efb592ef 45
46done_testing;