From 7fdc514fb2d9768b3d38d078cf24d9d03403539b Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 1 Aug 2011 23:27:34 -0500 Subject: remove test numbers --- t/close-over.t | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 t/close-over.t (limited to 't/close-over.t') diff --git a/t/close-over.t b/t/close-over.t new file mode 100644 index 0000000..8a58aa3 --- /dev/null +++ b/t/close-over.t @@ -0,0 +1,55 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; +use Test::Fatal; + +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"); +} + +{ + my $foo = []; + my $env = { '$foo' => \$foo }; + + like( + exception { + eval_closure( + source => 'sub { push @$foo, @_; return $__captures }', + environment => $env, + ); + }, + qr/Global symbol "\$__captures/, + "we don't close over \$__captures" + ); +} + +# 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; -- cgit v1.2.3-54-g00ecf