xref: /openbsd-src/gnu/usr.bin/perl/dist/Safe/t/safesig.t (revision 5486feefcc8cb79b19e014ab332cc5dfd05b3b33)
1#!perl
2
3BEGIN {
4    require Config;
5    import Config;
6    if ($Config{'extensions'} !~ /\bOpcode\b/) {
7        print "1..0\n";
8        exit 0;
9    }
10}
11
12use strict;
13use warnings;
14use Test::More;
15use Safe;
16plan(tests => 2);
17
18$SIG{$_} = $_ for keys %SIG;
19my %saved_SIG = %SIG;
20
21my $compartment = Safe->new;
22my $rv = $compartment->reval(q| return 1+1 |);
23
24my $success = 0;
25for (keys %saved_SIG) {
26    $success++ if $SIG{$_} and $SIG{$_} eq $saved_SIG{$_};
27}
28
29# This tests for: https://rt.cpan.org/Ticket/Display.html?id=112092
30is( $success, scalar(keys %saved_SIG),
31    '%SIG content restored after compartmentized evaluation' );
32
33my ($signame, ) = keys %SIG; # just pick any signal name
34is( defined $compartment->reval(qq| return \$SIG{$signame} |),
35    defined undef,
36    '%SIG values undefined inside compartment' );
37