Skip to content

Commit eb321f8

Browse files
committed
Safe: clean up some tests
- `BEGIN { require Config; Config->import; }` -> `use Config;` - `new Safe` -> `Safe->new` - more use of Test::More skip_all instead of manual print/exit
1 parent a2492d6 commit eb321f8

13 files changed

+76
-130
lines changed

dist/Safe/t/safe1.t

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#!./perl -w
22
$|=1;
3+
use Config;
34
BEGIN {
4-
require Config; Config->import;
55
if ($Config{'extensions'} !~ /\bOpcode\b/ && $Config{'osname'} ne 'VMS') {
66
print "1..0\n";
77
exit 0;
88
}
9-
109
}
1110

1211
# Tests Todo:
@@ -24,11 +23,11 @@ use Test::More;
2423

2524
my $cpt;
2625
# create and destroy some automatic Safe compartments first
27-
$cpt = new Safe or die;
28-
$cpt = new Safe or die;
29-
$cpt = new Safe or die;
26+
$cpt = Safe->new or die;
27+
$cpt = Safe->new or die;
28+
$cpt = Safe->new or die;
3029

31-
$cpt = new Safe "Root" or die;
30+
$cpt = Safe->new("Root") or die;
3231

3332
foreach(1..3) {
3433
$foo = 42;

dist/Safe/t/safe2.t

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!./perl -w
22
$|=1;
3+
use Config;
34
BEGIN {
4-
require Config; Config->import;
55
if ($Config{'extensions'} !~ /\bOpcode\b/ && $Config{'osname'} ne 'VMS') {
66
print "1..0\n";
77
exit 0;
@@ -28,10 +28,10 @@ $Root::foo .= "";
2828

2929
my $cpt;
3030
# create and destroy a couple of automatic Safe compartments first
31-
$cpt = new Safe or die;
32-
$cpt = new Safe or die;
31+
$cpt = Safe->new or die;
32+
$cpt = Safe->new or die;
3333

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

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

dist/Safe/t/safe3.t

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
#!perl -w
22

3-
BEGIN {
4-
require Config; Config->import;
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;
11-
}
12-
}
3+
use Config;
4+
use Test::More
5+
$Config{'extensions'} =~ /\bOpcode\b/
6+
|| $Config{'extensions'} =~ /\bPOSIX\b/
7+
|| $Config{'osname'} eq 'VMS'
8+
? (tests => 2)
9+
: (skip_all => "no Opcode and POSIX extensions and we're not on VMS");
1310

1411
use strict;
1512
use warnings;
1613
use POSIX qw(ceil);
17-
use Test::More tests => 2;
1814
use Safe;
1915

20-
my $safe = new Safe;
16+
my $safe = Safe->new;
2117
$safe->deny('add');
2218

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

33-
my $safe2 = new Safe;
29+
my $safe2 = Safe->new;
3430
$safe2->deny('add');
3531

3632
open my $fh, '>nasty.pl' or die "Can't write nasty.pl: $!\n";

dist/Safe/t/safeload.t

+7-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
#!perl
22

3-
BEGIN {
4-
require Config;
5-
Config->import;
6-
if ($Config{'extensions'} !~ /\bOpcode\b/) {
7-
print "1..0\n";
8-
exit 0;
9-
}
10-
# Can we load the version module ?
11-
eval { require version; 1 } or do {
12-
print "1..0 # no version.pm\n";
13-
exit 0;
14-
};
15-
delete $INC{"version.pm"};
16-
}
3+
use Config;
4+
use Test::More
5+
$Config{'extensions'} =~ /\bOpcode\b/
6+
&& eval { require version; delete $INC{"version.pm"}; 1 }
7+
? (tests => 4)
8+
: (skip_all => "no Opcode extension or can't load version.pm");
179

1810
use strict;
19-
use Test::More;
2011
use Safe;
21-
plan(tests => 4);
2212

23-
my $c = new Safe;
13+
my $c = Safe->new;
2414
$c->permit(qw(require caller entereval unpack rand));
2515
my $r = $c->reval(q{ use version; 1 });
2616
ok( defined $r, "Can load version.pm in a Safe compartment" ) or diag $@;

dist/Safe/t/safenamedcap.t

+5-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
BEGIN {
2-
if ($] < 5.010) {
3-
print "1..0\n";
4-
exit 0;
5-
}
6-
require Config;
7-
Config->import;
8-
if ($Config{'extensions'} !~ /\bOpcode\b/) {
9-
print "1..0\n";
10-
exit 0;
11-
}
12-
}
13-
141
use strict;
15-
use Test::More;
2+
use Config;
3+
use Test::More
4+
$] < 5.010 || $Config{'extensions'} =~ /\bOpcode\b/
5+
? (tests => 1)
6+
: (skip_all => "pre-5.10 perl or no Opcode extension");
167
use Safe;
17-
plan(tests => 1);
188

199
BEGIN { Safe->new }
2010
"foo" =~ /(?<foo>fo*)/;

dist/Safe/t/safeops.t

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ sub testop {
4646
my ($op, $opname, $code) = @_;
4747
pass("$op : skipped") and return if $code =~ /^SKIP/;
4848
pass("$op : skipped") and return if $code =~ m://|~~: && $] < 5.010;
49-
my $c = new Safe;
49+
my $c = Safe->new;
5050
$c->deny_only($op);
5151
$c->reval($code);
5252
like($@, qr/'\Q$opname\E' trapped by operation mask/, $op);

dist/Safe/t/saferegexp.t

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
#!perl -w
22

3-
BEGIN {
4-
require Config; Config->import;
5-
if ($Config{'extensions'} !~ /\bOpcode\b/) {
6-
print "1..0\n";
7-
exit 0;
8-
}
9-
}
10-
11-
use Test::More tests => 3;
3+
use Config;
4+
use Test::More
5+
$Config{'extensions'} =~ /\bOpcode\b/
6+
? (tests => 3)
7+
: (skip_all => "no Opcode extension");
128
use Safe;
139

1410
my $c; my $r;
1511
my $snippet = q{
1612
my $foo = qr/foo/;
1713
ref $foo;
1814
};
19-
$c = new Safe;
15+
$c = Safe->new;
2016
$r = $c->reval($snippet);
2117
is( $r, "Safe::Root0::Regexp" );
2218
$r or diag $@;
@@ -28,7 +24,7 @@ is( $r, "Safe::Root0::Regexp" );
2824
$r or diag $@;
2925

3026
# try with a new compartment
31-
$c = new Safe;
27+
$c = Safe->new;
3228
$r = $c->reval($snippet);
3329
is( $r, "Safe::Root1::Regexp" );
3430
$r or diag $@;

dist/Safe/t/safesecurity.t

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
#!perl
22

3-
BEGIN {
4-
require Config;
5-
Config->import;
6-
if ($Config{'extensions'} !~ /\bOpcode\b/) {
7-
print "1..0\n";
8-
exit 0;
9-
}
10-
}
11-
123
use strict;
134
use warnings;
14-
use Test::More;
5+
use Config;
6+
use Test::More
7+
$Config{'extensions'} =~ /\bOpcode\b/
8+
? (tests => 1)
9+
: (skip_all => "no Opcode extension");
1510
use Safe;
16-
plan(tests => 1);
1711

18-
my $c = new Safe;
12+
my $c = Safe->new;
1913

2014
{
2115
package My::Controller;

dist/Safe/t/safesig.t

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
#!perl
2-
3-
BEGIN {
4-
require Config;
5-
Config->import;
6-
if ($Config{'extensions'} !~ /\bOpcode\b/) {
7-
print "1..0\n";
8-
exit 0;
9-
}
10-
}
11-
122
use strict;
133
use warnings;
14-
use Test::More;
4+
5+
use Config;
6+
use Test::More
7+
$Config{'extensions'} =~ /\bOpcode\b/
8+
? (tests => 2)
9+
: (skip_all => "no Opcode extension");
1510
use Safe;
16-
plan(tests => 2);
1711

1812
$SIG{$_} = $_ for keys %SIG;
1913
my %saved_SIG = %SIG;

dist/Safe/t/safesort.t

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
#!perl -w
2-
$|=1;
3-
BEGIN {
4-
require Config; Config->import;
5-
if ($Config{'extensions'} !~ /\bOpcode\b/ && $Config{'osname'} ne 'VMS') {
6-
print "1..0\n";
7-
exit 0;
8-
}
9-
}
2+
use Config;
3+
use Test::More
4+
$Config{'extensions'} =~ /\bOpcode\b/ || $Config{'osname'} eq 'VMS'
5+
? (tests => 10)
6+
: (skip_all => "no Opcode extension and we're not on VMS");
107

118
use Safe 1.00;
12-
use Test::More tests => 10;
9+
10+
$| = 1;
1311

1412
my $safe = Safe->new('PLPerl');
1513
$safe->permit_only(qw(:default sort));

dist/Safe/t/safeuniversal.t

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
#!perl
22

3-
BEGIN {
4-
require Config;
5-
Config->import;
6-
if ($Config{'extensions'} !~ /\bOpcode\b/) {
7-
print "1..0\n";
8-
exit 0;
9-
}
10-
}
3+
use Config;
4+
use Test::More
5+
$Config{'extensions'} =~ /\bOpcode\b/
6+
? (tests => 6)
7+
: (skip_all => "no Opcode extension");
118

129
use strict;
1310
use warnings;
14-
use Test::More;
1511
use Safe;
16-
plan(tests => 6);
1712

18-
my $c = new Safe;
13+
my $c = Safe->new;
1914
$c->permit(qw(require caller));
2015

2116
my $no_warn_redef = ($] != 5.008009)

dist/Safe/t/safeutf8.t

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
#!perl -w
2-
$|=1;
3-
BEGIN {
4-
require Config; Config->import;
5-
if ($Config{'extensions'} !~ /\bOpcode\b/ && $Config{'osname'} ne 'VMS') {
6-
print "1..0\n";
7-
exit 0;
8-
}
9-
}
10-
11-
use Test::More tests => 7;
2+
use Config;
3+
use Test::More
4+
$Config{'extensions'} =~ /\bOpcode\b/ || $Config{'osname'} eq 'VMS'
5+
? (tests => 7)
6+
: (skip_all => "no Opcode extension and we're not on VMS");
127

138
use Safe 1.00;
149
use Opcode qw(full_opset);
1510

11+
$| = 1;
1612
pass;
1713

1814
my $safe = Safe->new('PLPerl');

dist/Safe/t/safewrap.t

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
#!perl -w
22

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

129
use strict;
1310
use Safe 1.00;
14-
use Test::More tests => 10;
11+
12+
$| = 1;
1513

1614
my $safe = Safe->new('PLPerl');
1715
$safe->permit_only(qw(:default sort));

0 commit comments

Comments
 (0)