Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safe: clean up some tests #23120

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/Safe/Safe.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package Safe;
use 5.003_11;
use Scalar::Util qw(reftype refaddr);

$Safe::VERSION = "2.46";
$Safe::VERSION = "2.47";

# *** Don't declare any lexicals above this point ***
#
Expand Down
9 changes: 4 additions & 5 deletions dist/Safe/t/safe1.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ BEGIN {
print "1..0\n";
exit 0;
}

}

# Tests Todo:
Expand All @@ -24,11 +23,11 @@ use Test::More;

my $cpt;
# create and destroy some automatic Safe compartments first
$cpt = new Safe or die;
$cpt = new Safe or die;
$cpt = new Safe or die;
$cpt = Safe->new or die;
$cpt = Safe->new or die;
$cpt = Safe->new or die;

$cpt = new Safe "Root" or die;
$cpt = Safe->new("Root") or die;

foreach(1..3) {
$foo = 42;
Expand Down
6 changes: 3 additions & 3 deletions dist/Safe/t/safe2.t
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ $Root::foo .= "";

my $cpt;
# create and destroy a couple of automatic Safe compartments first
$cpt = new Safe or die;
$cpt = new Safe or die;
$cpt = Safe->new or die;
$cpt = Safe->new or die;

$cpt = new Safe "Root";
$cpt = Safe->new("Root");

$cpt->permit(qw(:base_io));

Expand Down
20 changes: 8 additions & 12 deletions dist/Safe/t/safe3.t
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
#!perl -w

use Config;
BEGIN {
if ($Config{'extensions'} !~ /\bOpcode\b/
&& $Config{'extensions'} !~ /\bPOSIX\b/
&& $Config{'osname'} ne 'VMS')
{
print "1..0\n";
exit 0;
}
}
use Test::More
$Config{'extensions'} =~ /\bOpcode\b/
|| $Config{'extensions'} =~ /\bPOSIX\b/
|| $Config{'osname'} eq 'VMS'
? (tests => 2)
: (skip_all => "no Opcode and POSIX extensions and we're not on VMS");

use strict;
use warnings;
use POSIX qw(ceil);
use Test::More tests => 2;
use Safe;

my $safe = new Safe;
my $safe = Safe->new;
$safe->deny('add');

my $masksize = ceil( Opcode::opcodes / 8 );
Expand All @@ -30,7 +26,7 @@ $safe->reval( q{$x + $y} );
ok( $@ =~ /^'?addition \(\+\)'? trapped by operation mask/,
'opmask still in place with reval' );

my $safe2 = new Safe;
my $safe2 = Safe->new;
$safe2->deny('add');

open my $fh, '>nasty.pl' or die "Can't write nasty.pl: $!\n";
Expand Down
21 changes: 6 additions & 15 deletions dist/Safe/t/safeload.t
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
#!perl

use Config;
BEGIN {
if ($Config{'extensions'} !~ /\bOpcode\b/) {
print "1..0\n";
exit 0;
}
# Can we load the version module ?
eval { require version; 1 } or do {
print "1..0 # no version.pm\n";
exit 0;
};
delete $INC{"version.pm"};
}
use Test::More
$Config{'extensions'} =~ /\bOpcode\b/
&& eval { require version; delete $INC{"version.pm"}; 1 }
? (tests => 4)
: (skip_all => "no Opcode extension or can't load version.pm");

use strict;
use Test::More;
use Safe;
plan(tests => 4);

my $c = new Safe;
my $c = Safe->new;
$c->permit(qw(require caller entereval unpack rand));
my $r = $c->reval(q{ use version; 1 });
ok( defined $r, "Can load version.pm in a Safe compartment" ) or diag $@;
Expand Down
20 changes: 5 additions & 15 deletions dist/Safe/t/safenamedcap.t
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
BEGIN {
if ($] < 5.010) {
print "1..0\n";
exit 0;
}
require Config;
Config->import;
if ($Config{'extensions'} !~ /\bOpcode\b/) {
print "1..0\n";
exit 0;
}
}

use strict;
use Test::More;
use Config;
use Test::More
$] >= 5.010 && $Config{'extensions'} =~ /\bOpcode\b/
? (tests => 1)
: (skip_all => "pre-5.10 perl or no Opcode extension");
use Safe;
plan(tests => 1);

BEGIN { Safe->new }
"foo" =~ /(?<foo>fo*)/;
Expand Down
2 changes: 1 addition & 1 deletion dist/Safe/t/safeops.t
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ sub testop {
my ($op, $opname, $code) = @_;
pass("$op : skipped") and return if $code =~ /^SKIP/;
pass("$op : skipped") and return if $code =~ m://|~~: && $] < 5.010;
my $c = new Safe;
my $c = Safe->new;
$c->deny_only($op);
$c->reval($code);
like($@, qr/'\Q$opname\E' trapped by operation mask/, $op);
Expand Down
16 changes: 6 additions & 10 deletions dist/Safe/t/saferegexp.t
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
#!perl -w

use Config;
BEGIN {
if ($Config{'extensions'} !~ /\bOpcode\b/) {
print "1..0\n";
exit 0;
}
}

use Test::More tests => 3;
use Test::More
$Config{'extensions'} =~ /\bOpcode\b/
? (tests => 3)
: (skip_all => "no Opcode extension");
use Safe;

my $c; my $r;
my $snippet = q{
my $foo = qr/foo/;
ref $foo;
};
$c = new Safe;
$c = Safe->new;
$r = $c->reval($snippet);
is( $r, "Safe::Root0::Regexp" );
$r or diag $@;
Expand All @@ -28,7 +24,7 @@ is( $r, "Safe::Root0::Regexp" );
$r or diag $@;

# try with a new compartment
$c = new Safe;
$c = Safe->new;
$r = $c->reval($snippet);
is( $r, "Safe::Root1::Regexp" );
$r or diag $@;
17 changes: 6 additions & 11 deletions dist/Safe/t/safesecurity.t
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
#!perl

use Config;
BEGIN {
if ($Config{'extensions'} !~ /\bOpcode\b/) {
print "1..0\n";
exit 0;
}
}

use strict;
use warnings;
use Test::More;
use Config;
use Test::More
$Config{'extensions'} =~ /\bOpcode\b/
? (tests => 1)
: (skip_all => "no Opcode extension");
use Safe;
plan(tests => 1);

my $c = new Safe;
my $c = Safe->new;

{
package My::Controller;
Expand Down
17 changes: 6 additions & 11 deletions dist/Safe/t/safesig.t
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#!perl

use Config;
BEGIN {
if ($Config{'extensions'} !~ /\bOpcode\b/) {
print "1..0\n";
exit 0;
}
}

use strict;
use warnings;
use Test::More;

use Config;
use Test::More
$Config{'extensions'} =~ /\bOpcode\b/
? (tests => 2)
: (skip_all => "no Opcode extension");
use Safe;
plan(tests => 2);

$SIG{$_} = $_ for keys %SIG;
my %saved_SIG = %SIG;
Expand Down
14 changes: 6 additions & 8 deletions dist/Safe/t/safesort.t
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#!perl -w
$|=1;
use Config;
BEGIN {
if ($Config{'extensions'} !~ /\bOpcode\b/ && $Config{'osname'} ne 'VMS') {
print "1..0\n";
exit 0;
}
}
use Test::More
$Config{'extensions'} =~ /\bOpcode\b/ || $Config{'osname'} eq 'VMS'
? (tests => 10)
: (skip_all => "no Opcode extension and we're not on VMS");

use Safe 1.00;
use Test::More tests => 10;

$| = 1;

my $safe = Safe->new('PLPerl');
$safe->permit_only(qw(:default sort));
Expand Down
14 changes: 5 additions & 9 deletions dist/Safe/t/safeuniversal.t
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
#!perl

use Config;
BEGIN {
if ($Config{'extensions'} !~ /\bOpcode\b/) {
print "1..0\n";
exit 0;
}
}
use Test::More
$Config{'extensions'} =~ /\bOpcode\b/
? (tests => 6)
: (skip_all => "no Opcode extension");

use strict;
use warnings;
use Test::More;
use Safe;
plan(tests => 6);

my $c = new Safe;
my $c = Safe->new;
$c->permit(qw(require caller));

my $no_warn_redef = ($] != 5.008009)
Expand Down
14 changes: 5 additions & 9 deletions dist/Safe/t/safeutf8.t
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
#!perl -w
$|=1;
use Config;
BEGIN {
if ($Config{'extensions'} !~ /\bOpcode\b/ && $Config{'osname'} ne 'VMS') {
print "1..0\n";
exit 0;
}
}

use Test::More tests => 7;
use Test::More
$Config{'extensions'} =~ /\bOpcode\b/ || $Config{'osname'} eq 'VMS'
? (tests => 7)
: (skip_all => "no Opcode extension and we're not on VMS");

use Safe 1.00;
use Opcode qw(full_opset);

$| = 1;
pass;

my $safe = Safe->new('PLPerl');
Expand Down
14 changes: 6 additions & 8 deletions dist/Safe/t/safewrap.t
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#!perl -w

$|=1;
use Config;
BEGIN {
if ($Config{'extensions'} !~ /\bOpcode\b/ && $Config{'osname'} ne 'VMS') {
print "1..0\n";
exit 0;
}
}
use Test::More
$Config{'extensions'} =~ /\bOpcode\b/ || $Config{'osname'} eq 'VMS'
? (tests => 10)
: (skip_all => "no Opcode extension and we're not on VMS");

use strict;
use Safe 1.00;
use Test::More tests => 10;

$| = 1;

my $safe = Safe->new('PLPerl');
$safe->permit_only(qw(:default sort));
Expand Down
Loading