diff options
author | Jesse Luehrs <doy@tozt.net> | 2010-10-20 15:05:54 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2010-10-20 15:05:54 -0500 |
commit | 460a4d15ded58deecdacebbd9b68844d6768892b (patch) | |
tree | cfe8a078d0d6850e8a23dc519bdef1c597533a45 | |
parent | ce19c70b6c5870c9ee5f8fd6548cd172719e8aa3 (diff) | |
download | eval-closure-460a4d15ded58deecdacebbd9b68844d6768892b.tar.gz eval-closure-460a4d15ded58deecdacebbd9b68844d6768892b.zip |
another test
-rw-r--r-- | dist.ini | 1 | ||||
-rw-r--r-- | t/02-close-over.t | 51 |
2 files changed, 52 insertions, 0 deletions
@@ -13,6 +13,7 @@ Try::Tiny = 0 [Prereq / TestRequires] Test::More = 0.88 +Test::Requires = 0 [Prereq / RuntimeRecommends] Perl::Tidy = 0 diff --git a/t/02-close-over.t b/t/02-close-over.t new file mode 100644 index 0000000..ea6792a --- /dev/null +++ b/t/02-close-over.t @@ -0,0 +1,51 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +use Eval::Closure; + +use Test::Requires 'PadWalker'; + +{ + my $foo = []; + my $env = { '$foo' => \$foo }; + + my $code = eval_closure( + source => 'sub { push @$foo, @_ }', + environment => $env, + ); + is_deeply(scalar(PadWalker::closed_over($code)), $env, + "closed over the right things"); +} + +{ + my $foo = {}; + my $bar = []; + my $env = { '$foo' => \$bar, '$bar' => \$foo }; + + my $code = eval_closure( + source => 'sub { push @$foo, @_; $bar->{foo} = \@_ }', + environment => $env, + ); + is_deeply(scalar(PadWalker::closed_over($code)), $env, + "closed over the right things"); +} + +{ + local $TODO = "we still have to close over \$__captures"; + my $foo = []; + my $env = { '$foo' => \$foo }; + + my $code = eval_closure( + source => 'sub { push @$foo, @_; return $__captures }', + environment => $env, + ); + is_deeply(scalar(PadWalker::closed_over($code)), $env, + "closed over the right things"); +} + +# it'd be nice if we could test that closing over other things wasn't possible, +# but perl's optimizer gets in the way of that + +done_testing; |