8 require Config; import Config;
9 if ($Config{'extensions'} !~ /\bOpcode\b/ && $Config{'osname'} ne 'VMS') {
16 opcodes opdesc opmask verify_opset
17 opset opset_to_ops opset_to_hex invert_opset
18 opmask_add full_opset empty_opset define_optag
24 my $last_test; # initalised at end
25 print "1..$last_test\n";
30 # --- opset_to_ops and opset
32 my @empty_l = opset_to_ops(empty_opset);
33 print @empty_l == 0 ? "ok $t\n" : "not ok $t\n"; $t++;
35 my @full_l1 = opset_to_ops(full_opset);
36 print @full_l1 == opcodes() ? "ok $t\n" : "not ok $t\n"; $t++;
37 my @full_l2 = @full_l1; # = opcodes(); # XXX to be fixed
38 print "@full_l1" eq "@full_l2" ? "ok $t\n" : "not ok $t\n"; $t++;
40 @empty_l = opset_to_ops(opset(':none'));
41 print @empty_l == 0 ? "ok $t\n" : "not ok $t\n"; $t++;
43 my @full_l3 = opset_to_ops(opset(':all'));
44 print @full_l1 == @full_l3 ? "ok $t\n" : "not ok $t\n"; $t++;
45 print "@full_l1" eq "@full_l3" ? "ok $t\n" : "not ok $t\n"; $t++;
47 die $t unless $t == 7;
48 $s1 = opset( 'padsv');
49 $s2 = opset($s1, 'padav');
50 $s3 = opset($s2, '!padav');
51 print $s1 eq $s2 ? "not ok $t\n" : "ok $t\n"; ++$t;
52 print $s1 eq $s3 ? "ok $t\n" : "not ok $t\n"; ++$t;
56 print eval { opset(':_tst_') } ? "not ok $t\n" : "ok $t\n"; ++$t;
57 define_optag(":_tst_", opset(qw(padsv padav padhv)));
58 print eval { opset(':_tst_') } ? "ok $t\n" : "not ok $t\n"; ++$t;
60 # --- opdesc and opcodes
62 die $t unless $t == 11;
63 print opdesc("gv") eq "glob value" ? "ok $t\n" : "not ok $t\n"; $t++;
64 my @desc = opdesc(':_tst_','stub');
65 print "@desc" eq "private variable private array private hash stub"
66 ? "ok $t\n" : "not ok $t\n#@desc\n"; $t++;
67 print opcodes() ? "ok $t\n" : "not ok $t\n"; $t++;
68 print "ok $t\n"; ++$t;
72 $s1 = opset(qw(fileno padsv padav));
73 @o2 = opset_to_ops(invert_opset($s1));
74 print @o2 == opcodes-3 ? "ok $t\n" : "not ok $t\n"; $t++;
78 die $t unless $t == 16;
79 print opmask() eq empty_opset() ? "ok $t\n" : "not ok $t\n"; $t++; # work
80 print length opmask() == int((opcodes()+7)/8) ? "ok $t\n" : "not ok $t\n"; $t++;
84 print verify_opset($s1) && !verify_opset(42) ? "ok $t\n":"not ok $t\n"; $t++;
88 opmask_add(opset(qw(fileno))); # add to global op_mask
89 print eval 'fileno STDOUT' ? "not ok $t\n" : "ok $t\n"; $t++; # fail
90 print $@ =~ /fileno trapped/ ? "ok $t\n" : "not ok $t\n# $@\n"; $t++;
92 # --- check use of bit vector ops on opsets
96 $s3 = opset('padsv', 'padav', 'padhv');
99 print (($s1 | $s2) eq opset($s1,$s2) ? "ok $t\n":"not ok $t\n"); $t++;
100 print (($s2 & $s3) eq opset($s2) ? "ok $t\n":"not ok $t\n"); $t++;
101 print (($s2 ^ $s3) eq opset('padsv','padhv') ? "ok $t\n":"not ok $t\n"); $t++;
103 # Negated, e.g., with possible extra bits in last byte beyond last op bit.
104 # The extra bits mean we can't just say ~mask eq invert_opset(mask).
106 @o1 = opset_to_ops( ~ $s3);
107 @o2 = opset_to_ops(invert_opset $s3);
108 print "@o1" eq "@o2" ? "ok $t\n":"not ok $t\n"; $t++;
110 # --- finally, check some opname assertions
112 foreach(@full_l1) { die "bad opname: $_" if /\W/ or /^\d/ }
114 print "ok $last_test\n";
115 BEGIN { $last_test = 25 }