1N/A#!./perl -w
1N/A$|=1;
1N/ABEGIN {
1N/A require Config; import Config;
1N/A if ($Config{'extensions'} !~ /\bOpcode\b/ && $Config{'osname'} ne 'VMS') {
1N/A print "1..0\n";
1N/A exit 0;
1N/A }
1N/A
1N/A}
1N/A
1N/A# Tests Todo:
1N/A# 'main' as root
1N/A
1N/Apackage test; # test from somewhere other than main
1N/A
1N/Ause vars qw($bar);
1N/A
1N/Ause Opcode 1.00, qw(opdesc opset opset_to_ops opset_to_hex
1N/A opmask_add full_opset empty_opset opcodes opmask define_optag);
1N/A
1N/Ause Safe 1.00;
1N/A
1N/Amy $last_test; # initalised at end
1N/Aprint "1..$last_test\n";
1N/A
1N/Amy $t = 1;
1N/Amy $cpt;
1N/A# create and destroy some automatic Safe compartments first
1N/A$cpt = new Safe or die;
1N/A$cpt = new Safe or die;
1N/A$cpt = new Safe or die;
1N/A
1N/A$cpt = new Safe "Root" or die;
1N/A
1N/Aforeach(1..3) {
1N/A $foo = 42;
1N/A
1N/A $cpt->share(qw($foo));
1N/A
1N/A print ${$cpt->varglob('foo')} == 42 ? "ok $t\n" : "not ok $t\n"; $t++;
1N/A
1N/A ${$cpt->varglob('foo')} = 9;
1N/A
1N/A print $foo == 9 ? "ok $t\n" : "not ok $t\n"; $t++;
1N/A
1N/A print $cpt->reval('$foo') == 9 ? "ok $t\n" : "not ok $t\n"; $t++;
1N/A # check 'main' has been changed:
1N/A print $cpt->reval('$::foo') == 9 ? "ok $t\n" : "not ok $t\n"; $t++;
1N/A print $cpt->reval('$main::foo') == 9 ? "ok $t\n" : "not ok $t\n"; $t++;
1N/A # check we can't see our test package:
1N/A print $cpt->reval('$test::foo') ? "not ok $t\n" : "ok $t\n"; $t++;
1N/A print $cpt->reval('${"test::foo"}') ? "not ok $t\n" : "ok $t\n"; $t++;
1N/A
1N/A $cpt->erase; # erase the compartment, e.g., delete all variables
1N/A
1N/A print $cpt->reval('$foo') ? "not ok $t\n" : "ok $t\n"; $t++;
1N/A
1N/A # Note that we *must* use $cpt->varglob here because if we used
1N/A # $Root::foo etc we would still see the original values!
1N/A # This seems to be because the compiler has created an extra ref.
1N/A
1N/A print ${$cpt->varglob('foo')} ? "not ok $t\n" : "ok $t\n"; $t++;
1N/A}
1N/A
1N/Aprint "ok $last_test\n";
1N/ABEGIN { $last_test = 28 }