asmdata.t 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env perl -w
  2. # blead cannot run -T
  3. BEGIN {
  4. if ($ENV{PERL_CORE}){
  5. chdir('t') if -d 't';
  6. @INC = ('.', '../lib');
  7. }
  8. require Config;
  9. if ($ENV{PERL_CORE} and ($Config::Config{'extensions'} !~ /\bB\b/) ){
  10. print "1..0 # Skip -- Perl configured without B module\n";
  11. exit 0;
  12. }
  13. }
  14. use Test::More tests => ($] < 5.009) ? 13 : 14;
  15. if ($] < 5.009) {
  16. use_ok('B::Asmdata', qw(%insn_data @insn_name @optype @specialsv_name));
  17. } else {
  18. use_ok('B', qw(@optype @specialsv_name));
  19. use_ok('B::Asmdata', qw(%insn_data @insn_name));
  20. }
  21. # check we got something.
  22. isnt( keys %insn_data, 0, '%insn_data exported and populated' );
  23. isnt( @insn_name, 0, ' @insn_name' );
  24. isnt( @optype, 0, ' @optype' );
  25. isnt( @specialsv_name, 0, ' @specialsv_name' );
  26. # pick an op that's not likely to go away in the future
  27. my @data = values %insn_data;
  28. is( (grep { ref eq 'ARRAY' } @data), @data, '%insn_data contains arrays' );
  29. # sort out unsupport ones, with no PUT method
  30. @data = grep {$_[2]} @data;
  31. # pick one at random to test with.
  32. my $opname = (keys %insn_data)[rand @data];
  33. my $data = $insn_data{$opname};
  34. like( $data->[0], qr/^\d+$/, ' op number' );
  35. is( ref $data->[1], 'CODE', ' PUT code ref' );
  36. ok( !ref $data->[2], ' GET method' );
  37. is( $insn_name[$data->[0]], $opname, '@insn_name maps correctly' );
  38. # I'm going to assume that op types will all be named /OP$/.
  39. # If this changes in the future, change this test.
  40. is( grep(/OP$/, @optype), @optype, '@optype is all /OP$/' );
  41. # comment in bytecode.pl says "Nullsv *must come first so that the
  42. # condition ($$sv == 0) can continue to be used to test (sv == Nullsv)."
  43. is( $specialsv_name[0], 'Nullsv', 'Nullsv come first in @special_sv_name' );
  44. # other than that, we can't really say much more about @specialsv_name
  45. # than it has to contain strings (on the off chance &PL_sv_undef gets
  46. # flubbed)
  47. is( grep(!ref, @specialsv_name), @specialsv_name, ' contains all strings' );