xref: /openbsd-src/gnu/usr.bin/perl/dist/Safe/t/safeload.t (revision 5486feefcc8cb79b19e014ab332cc5dfd05b3b33)
1b39c5158Smillert#!perl
2b39c5158Smillert
3b39c5158SmillertBEGIN {
4b39c5158Smillert    require Config;
5b39c5158Smillert    import Config;
6b39c5158Smillert    if ($Config{'extensions'} !~ /\bOpcode\b/) {
7b39c5158Smillert	print "1..0\n";
8b39c5158Smillert	exit 0;
9b39c5158Smillert    }
10b39c5158Smillert    # Can we load the version module ?
11b39c5158Smillert    eval { require version; 1 } or do {
12b39c5158Smillert	print "1..0 # no version.pm\n";
13b39c5158Smillert	exit 0;
14b39c5158Smillert    };
15b39c5158Smillert    delete $INC{"version.pm"};
16b39c5158Smillert}
17b39c5158Smillert
18b39c5158Smillertuse strict;
19b39c5158Smillertuse Test::More;
20b39c5158Smillertuse Safe;
21*5486feefSafresh1plan(tests => 4);
22b39c5158Smillert
23b39c5158Smillertmy $c = new Safe;
24f2a19305Safresh1$c->permit(qw(require caller entereval unpack rand));
25b39c5158Smillertmy $r = $c->reval(q{ use version; 1 });
26b39c5158Smillertok( defined $r, "Can load version.pm in a Safe compartment" ) or diag $@;
27898184e3Ssthen
2891f110e0Safresh1$r = $c->reval(q{ version->new(1.2) });
2991f110e0Safresh1is(ref $r, "Safe::Root0::version", "version objects rerooted");
3091f110e0Safresh1$r or diag $@;
3191f110e0Safresh1
32898184e3Ssthen# Does this test really belong here?  We are testing the "loading" of
33898184e3Ssthen# a perl version number.
34898184e3Ssthen# This should died because of strictures under 5.12+ and because of the
35898184e3Ssthen# perl version in 5.10-.
36898184e3Ssthenok !$c->reval(q{use 5.012; $undeclared; 1}),
37898184e3Ssthen   'reval does not prevent use 5.012 from enabling strict';
38*5486feefSafresh1
39*5486feefSafresh1# "use Tie::Scalar" depends on UNIVERSAL::import as Tie::Scalar does not have
40*5486feefSafresh1# its own import method.
41*5486feefSafresh1$r = $c->reval(q{ use Tie::Scalar; 1 });
42*5486feefSafresh1ok( defined $r, "Can load Tie::Scalar.pm in a Safe compartment" ) or diag $@;
43