- Moved unused argc, temp variable into small scope.
[dragonfly.git] / contrib / perl5 / t / lib / safe1.t
1 #!./perl -w
2 $|=1;
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     require Config; import Config;
7     if ($Config{'extensions'} !~ /\bOpcode\b/ && $Config{'osname'} ne 'VMS') {
8         print "1..0\n";
9         exit 0;
10     }
11 }
12
13 # Tests Todo:
14 #       'main' as root
15
16 package test;   # test from somewhere other than main
17
18 use vars qw($bar);
19
20 use Opcode 1.00, qw(opdesc opset opset_to_ops opset_to_hex
21         opmask_add full_opset empty_opset opcodes opmask define_optag);
22
23 use Safe 1.00;
24
25 my $last_test; # initalised at end
26 print "1..$last_test\n";
27
28 my $t = 1;
29 my $cpt;
30 # create and destroy some automatic Safe compartments first
31 $cpt = new Safe or die;
32 $cpt = new Safe or die;
33 $cpt = new Safe or die;
34
35 $cpt = new Safe "Root" or die;
36
37 foreach(1..3) {
38         $foo = 42;
39
40         $cpt->share(qw($foo));
41
42         print ${$cpt->varglob('foo')}       == 42 ? "ok $t\n" : "not ok $t\n"; $t++;
43
44         ${$cpt->varglob('foo')} = 9;
45
46         print $foo == 9 ? "ok $t\n" : "not ok $t\n"; $t++;
47
48         print $cpt->reval('$foo')       == 9    ? "ok $t\n" : "not ok $t\n"; $t++;
49         # check 'main' has been changed:
50         print $cpt->reval('$::foo')     == 9    ? "ok $t\n" : "not ok $t\n"; $t++;
51         print $cpt->reval('$main::foo') == 9    ? "ok $t\n" : "not ok $t\n"; $t++;
52         # check we can't see our test package:
53         print $cpt->reval('$test::foo')         ? "not ok $t\n" : "ok $t\n"; $t++;
54         print $cpt->reval('${"test::foo"}')             ? "not ok $t\n" : "ok $t\n"; $t++;
55
56         $cpt->erase;    # erase the compartment, e.g., delete all variables
57
58         print $cpt->reval('$foo') ? "not ok $t\n" : "ok $t\n"; $t++;
59
60         # Note that we *must* use $cpt->varglob here because if we used
61         # $Root::foo etc we would still see the original values!
62         # This seems to be because the compiler has created an extra ref.
63
64         print ${$cpt->varglob('foo')} ? "not ok $t\n" : "ok $t\n"; $t++;
65 }
66
67 print "ok $last_test\n";
68 BEGIN { $last_test = 28 }