From: Tim Bunce Date: Thu, 14 Jan 2010 14:38:53 +0000 (+0000) Subject: Added tests for perl#72068 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=32f28238059591da8025e5f6cf1bc5ecc6c99fe7;p=p5sagit%2Fp5-mst-13.2.git Added tests for perl#72068 --- diff --git a/dist/Safe/t/safesort.t b/dist/Safe/t/safesort.t index 2b90afc..f2b7ed0 100644 --- a/dist/Safe/t/safesort.t +++ b/dist/Safe/t/safesort.t @@ -9,25 +9,30 @@ BEGIN { } use Safe 1.00; -use Test::More tests => 4; +use Test::More tests => 6; my $safe = Safe->new('PLPerl'); $safe->permit_only(qw(:default sort)); +# check basic argument passing and context for anon-subs +my $func = $safe->reval(q{ sub { @_ } }); +is_deeply [ $func->() ], [ ]; +is_deeply [ $func->("foo") ], [ "foo" ]; + my $func = $safe->reval(<<'EOS'); # uses quotes in { "$a" <=> $b } to avoid the optimizer replacing the block # with a hardwired comparison - { package Pkg; sub p_sort { return sort { "$a" <=> $b } qw(2 1 3); } } - sub l_sort { return sort { "$a" <=> $b } qw(2 1 3); } + { package Pkg; sub p_sort { return sort { "$a" <=> $b } @_; } } + sub l_sort { return sort { "$a" <=> $b } @_; } - return sub { return join(",",l_sort()), join(",",Pkg::p_sort()) } + return sub { return join(",",l_sort(@_)), join(",",Pkg::p_sort(@_)) } EOS is $@, '', 'reval should not fail'; is ref $func, 'CODE', 'reval should return a CODE ref'; -my ($l_sorted, $p_sorted) = $func->(); +my ($l_sorted, $p_sorted) = $func->(@_); is $l_sorted, "1,2,3"; is $p_sorted, "1,2,3";