Eviscerate README.macos to match the state of the world
[p5sagit/p5-mst-13.2.git] / dist / Safe / t / safe3.t
CommitLineData
7a823c14 1#!perl -w
33f7e1aa 2
3BEGIN {
ac5e3691 4 require Config; import Config;
5 if ($Config{'extensions'} !~ /\bOpcode\b/
6 && $Config{'extensions'} !~ /\bPOSIX\b/
7 && $Config{'osname'} ne 'VMS')
8 {
9 print "1..0\n";
10 exit 0;
33f7e1aa 11 }
12}
13
14use strict;
15use warnings;
16use POSIX qw(ceil);
d00660f4 17use Test::More tests => 2;
33f7e1aa 18use Safe;
19
20my $safe = new Safe;
21$safe->deny('add');
22
d00660f4 23my $masksize = ceil( Opcode::opcodes / 8 );
33f7e1aa 24# Attempt to change the opmask from within the safe compartment
d00660f4 25$safe->reval( qq{\$_[1] = qq/\0/ x } . $masksize );
33f7e1aa 26
27# Check that it didn't work
28$safe->reval( q{$x + $y} );
c3c3bebb 29# Written this way to keep the Test::More that comes with perl 5.6.2 happy
7a823c14 30ok( $@ =~ /^'?addition \(\+\)'? trapped by operation mask/,
d00660f4 31 'opmask still in place with reval' );
32
33my $safe2 = new Safe;
34$safe2->deny('add');
35
36open my $fh, '>nasty.pl' or die "Can't write nasty.pl: $!\n";
37print $fh <<EOF;
38\$_[1] = "\0" x $masksize;
39EOF
40close $fh;
41$safe2->rdo('nasty.pl');
42$safe2->reval( q{$x + $y} );
c3c3bebb 43# Written this way to keep the Test::More that comes with perl 5.6.2 happy
7a823c14 44ok( $@ =~ /^'?addition \(\+\)'? trapped by operation mask/,
d00660f4 45 'opmask still in place with rdo' );
46END { unlink 'nasty.pl' }