diff options
author | Jesse Luehrs <doy@tozt.net> | 2010-10-20 16:17:19 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2010-10-20 16:17:19 -0500 |
commit | 9736bf12e7521f7d8a4587c6c4be9c47da39c7cf (patch) | |
tree | 4298d9f13f7fdc6066b4d95b95ac559317a9afca /t/01-basic.t | |
parent | b3bd5eb84e7a0251075360a04fd7e76a42815bcd (diff) | |
download | eval-closure-9736bf12e7521f7d8a4587c6c4be9c47da39c7cf.tar.gz eval-closure-9736bf12e7521f7d8a4587c6c4be9c47da39c7cf.zip |
more tests
Diffstat (limited to 't/01-basic.t')
-rw-r--r-- | t/01-basic.t | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/t/01-basic.t b/t/01-basic.t index 82224d9..7856f6e 100644 --- a/t/01-basic.t +++ b/t/01-basic.t @@ -2,22 +2,48 @@ use strict; use warnings; use Test::More; +use Test::Exception; use Eval::Closure; -my $foo = []; +{ + my $code = eval_closure( + source => 'sub { die "called\n" }', + ); + ok($code, "got something"); -my $code = eval_closure( - source => 'sub { push @$bar, @_ }', - environment => { - '$bar' => \$foo, - }, - name => 'test', -); -ok($code, "got something"); + throws_ok { $code->() } qr/^called$/, "got the right thing"; +} -$code->(1); +{ + my $foo = []; -is_deeply($foo, [1], "got the right thing"); + my $code = eval_closure( + source => 'sub { push @$bar, @_ }', + environment => { + '$bar' => \$foo, + }, + name => 'test', + ); + 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; |