summaryrefslogtreecommitdiff
path: root/dist/Safe/t
diff options
context:
space:
mode:
authorTim Bunce <Tim.Bunce@pobox.com>2009-12-01 00:15:21 +0100
committerRafael Garcia-Suarez <rgs@consttype.org>2009-12-01 00:16:41 +0100
commit576b33a19ccaf98d4dfe201d529c55c3747f0cb6 (patch)
tree09782e2c22c0e7ce60311bbc0c3bb88816db6a6e /dist/Safe/t
parent2e0a827f13b2065625fa468c74693fcff824b17f (diff)
downloadperl-576b33a19ccaf98d4dfe201d529c55c3747f0cb6.tar.gz
[rt.cpan.org #51574] Safe.pm sort {} bug accessing $a and $b with -Dusethreads
Diffstat (limited to 'dist/Safe/t')
-rw-r--r--dist/Safe/t/safesort.t37
1 files changed, 37 insertions, 0 deletions
diff --git a/dist/Safe/t/safesort.t b/dist/Safe/t/safesort.t
new file mode 100644
index 0000000000..383ad1ab26
--- /dev/null
+++ b/dist/Safe/t/safesort.t
@@ -0,0 +1,37 @@
+#!./perl -w
+$|=1;
+BEGIN {
+ if($ENV{PERL_CORE}) {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+ }
+ require Config; import Config;
+ if ($Config{'extensions'} !~ /\bOpcode\b/ && $Config{'osname'} ne 'VMS') {
+ print "1..0\n";
+ exit 0;
+ }
+}
+
+use Safe 1.00;
+use Test::More tests => 4;
+
+my $safe = Safe->new('PLPerl');
+$safe->permit_only(qw(:default sort));
+
+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); }
+
+ 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->();
+is $l_sorted, "1,2,3";
+is $p_sorted, "1,2,3";