2 # Tests that all ops can be trapped by a Safe compartment
5 unless ($ENV{PERL_CORE}) {
6 # this won't work outside of the core, so exit
7 print "1..0 # skipped: PERL_CORE unset\n"; exit 0;
12 if ($Config{'extensions'} !~ /\bOpcode\b/ && $Config{'osname'} ne 'VMS') {
13 print "1..0\n"; exit 0;
16 # We need test.pl for runperl(). Since this test script is only run in
17 # the perl core, this should be fine:
18 require '../../t/test.pl';
24 # Read the op names and descriptions directly from opcode.pl
30 die "Can't match $_" unless /^([a-z_0-9]+)\t+(.*)/;
34 open my $fh, '<', '../../regen/opcodes' or die "Can't open opcodes: $!";
38 my ($op, $opname) = split /\t+/;
39 push @op, [$op, $opname, $code{$op}];
43 plan(tests => scalar @op + 3);
46 my ($op, $opname, $code) = @_;
47 pass("$op : skipped") and return if $code =~ /^SKIP/;
48 pass("$op : skipped") and return if $code =~ m://|~~: && $] < 5.010;
52 like($@, qr/'\Q$opname\E' trapped by operation mask/, $op);
59 local our $TODO = "No test yet for $_->[0] ($_->[1])";
64 # Test also that the errors resulting from disallowed ops do not cause
65 # ‘Unbalanced’ warnings.
67 local $ENV{PERL_DESTRUCT_LEVEL}=2;
70 switches => [ '-MSafe', '-w' ],
71 prog => 'Safe->new->reval(q(use strict))',
75 'No Unbalanced warnings when disallowing ops';
78 switches => [ '-MSafe', '-w' ],
79 prog => 'Safe->new->reval(q(use strict), 1)',
83 'No Unbalanced warnings when disallowing ops';
86 switches => [ '-MSafe', '-w' ],
87 prog => 'Safe->new->reval('
88 . 'q(BEGIN{$^H{foo}=bar};use strict), 0'
93 'No Unbalanced warnings when disallowing ops with %^H set';
96 # things that begin with SKIP are skipped, for various reasons (notably
97 # optree modified by the optimizer -- Safe checks are done before the
98 # optimizer modifies the optree)
107 gvsv SKIP (set by optimizer) $x
113 padany SKIP (not implemented)
114 pushre SKIP split /foo/
120 prototype prototype 'foo'
128 rcatline SKIP (set by optimizer) $x .= <F>
129 regcmaybe SKIP (internal)
130 regcreset SKIP (internal)
131 regcomp SKIP (internal)
135 substcont SKIP (set by optimizer)
148 i_preinc SKIP (set by optimizer)
150 i_predec SKIP (set by optimizer)
152 i_postinc SKIP (set by optimizer)
154 i_postdec SKIP (set by optimizer)
157 i_multiply SKIP (set by optimizer)
159 i_divide SKIP (set by optimizer)
161 i_modulo SKIP (set by optimizer)
164 i_add SKIP (set by optimizer)
166 i_subtract SKIP (set by optimizer)
172 i_lt SKIP (set by optimizer)
174 i_gt SKIP (set by optimizer)
176 i_le SKIP (set by optimizer)
178 i_ge SKIP (set by optimizer)
180 i_eq SKIP (set by optimizer)
182 i_ne SKIP (set by optimizer)
184 i_ncmp SKIP (set by optimizer)
196 i_negate SKIP (set by optimizer)
216 sprintf sprintf '%s', 'foo'
220 crypt crypt 'foo','bar'
227 aelemfast SKIP (set by optimizer)
233 delete delete $h{Key}
234 exists exists $h{Key}
238 multideref SKIP (set by optimizer)
247 splice splice @x, 1, 2, 3
254 grepstart grep { $_ eq 'foo' } @x
255 grepwhile SKIP grep { $_ eq 'foo' } @x
256 mapstart map $_ + 1, @foo
257 mapwhile SKIP (set by optimizer)
270 leavesublv sub f:lvalue{return $x} f()
277 dbstate SKIP (needs debugger)
297 umask umask 0755, 'foo'
304 sselect SKIP (set by optimizer)
320 seek seek FH, $pos, $whence
321 truncate truncate FOO, 42
334 getsockname getsockname
335 getpeername getpeername
369 chmod chmod 511, 'foo'
371 rename rename 'foo', 'bar'
372 link link 'foo', 'bar'
373 symlink symlink 'foo', 'bar'
374 readlink readlink 'foo'
380 seekdir seekdir DIR, $pos
381 rewinddir rewinddir DIR
382 closedir closedir DIR
392 getpriority getpriority
393 setpriority setpriority
415 entertry SKIP eval { 1+1 }
416 leavetry SKIP eval { 1+1 }
417 ghbyname gethostbyname 'foo'
418 ghbyaddr gethostbyaddr 'foo'
420 gnbyname getnetbyname 'foo'
421 gnbyaddr getnetbyaddr 'foo'
423 gpbyname getprotobyname 'foo'
424 gpbynumber getprotobynumber 42
425 gprotoent getprotoent
426 gsbyname getservbyname 'name', 'proto'
427 gsbyport getservbyport 'a', 'b'
431 sprotoent setprotoent
435 eprotoent endprotoent
454 once SKIP {use feature 'state'; state $foo = 42;}
455 say SKIP {use feature 'say'; say "foo";}
456 smartmatch no warnings 'experimental::smartmatch'; $x ~~ $y
459 avalues SKIP values @t