Skip to content

Commit

Permalink
another test
Browse files Browse the repository at this point in the history
  • Loading branch information
doy committed Oct 20, 2010
1 parent ce19c70 commit 460a4d1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions dist.ini
Expand Up @@ -13,6 +13,7 @@ Try::Tiny = 0

[Prereq / TestRequires]
Test::More = 0.88
Test::Requires = 0

[Prereq / RuntimeRecommends]
Perl::Tidy = 0
51 changes: 51 additions & 0 deletions 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;

0 comments on commit 460a4d1

Please sign in to comment.