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