testcore.t 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. # -*- cperl -*-
  2. # t/testcore.t - run the core testsuite with the compilers C, CC and ByteCode
  3. #
  4. # Copy your matching CORE t dirs into t/CORE.
  5. # For now we test qw(base comp lib op run)
  6. # Then fixup the @INC setters, and various require ./test.pl calls.
  7. #
  8. # perl -pi -e 's/^(\s*\@INC = )/# $1/' t/CORE/*/*.t
  9. # perl -pi -e "s|^(\s*)chdir 't' if -d|\$1chdir 't/CORE' if -d|" t/CORE/*/*.t
  10. # perl -pi -e "s|require './|use lib "CORE"; require '|" `grep -l "require './" t/CORE/*/*.t`
  11. #
  12. #
  13. # See TESTS for recent results
  14. use Cwd;
  15. use File::Copy;
  16. BEGIN {
  17. unless (-d "t/CORE") {
  18. print "1..0 #skip t/CORE missing. Read t/testcore.t how to setup.\n";
  19. exit 0;
  20. }
  21. unshift @INC, ("t");
  22. }
  23. require "test.pl";
  24. sub vcmd {
  25. my $cmd = join "", @_;
  26. print "#",$cmd,"\n";
  27. run_cmd($cmd, 120); # timeout 2min
  28. }
  29. my $dir = getcwd();
  30. unlink ("t/perl", "t/CORE/perl");
  31. #symlink "t/perl", $^X;
  32. #symlink "t/CORE/perl", $^X;
  33. #symlink "t/CORE/test.pl", "t/test.pl" unless -e "t/CORE/test.pl";
  34. #symlink "t/CORE/harness", "t/test.pl" unless -e "t/CORE/harness";
  35. `ln -sf $^X t/perl`;
  36. `ln -sf $^X t/CORE/perl`;
  37. # CORE t/test.pl would be better, but this fails only on 2 tests
  38. -e "t/CORE/test.pl" or `ln -s t/test.pl t/CORE/test.pl`;
  39. -e "t/CORE/harness" or `ln -s t/test.pl t/CORE/harness`; # better than nothing
  40. `ln -s t/test.pl harness`; # base/term
  41. `ln -s t/test.pl TEST`; # cmd/mod 8
  42. my %ALLOW_PERL_OPTIONS;
  43. for (qw(
  44. comp/cpp.t
  45. run/runenv.t
  46. )) {
  47. $ALLOW_PERL_OPTIONS{"t/CORE/$_"} = 1;
  48. }
  49. my $SKIP = { "CC" =>
  50. { "t/CORE/op/bop.t" => "hangs",
  51. "t/CORE/op/die.t" => "hangs",
  52. }
  53. };
  54. my @fail = map { "t/CORE/$_" }
  55. qw{
  56. base/lex.t
  57. base/rs.t
  58. base/term.t
  59. cmd/while.t
  60. comp/bproto.t
  61. comp/colon.t
  62. comp/decl.t
  63. comp/fold.t
  64. comp/form_scope.t
  65. comp/line_debug.t
  66. comp/hints.t
  67. comp/our.t
  68. comp/package.t
  69. comp/packagev.t
  70. comp/parser.t
  71. comp/proto.t
  72. comp/require.t
  73. comp/retainedlines.t
  74. comp/script.t
  75. comp/use.t
  76. op/anonsub.t
  77. op/avhv.t
  78. op/bop.t
  79. op/chop.t
  80. op/eval.t
  81. op/goto.t
  82. op/overload.t
  83. op/pat.t
  84. op/ref.t
  85. op/sort.t
  86. op/substr.t
  87. op/undef.t
  88. op/write.t
  89. };
  90. my @tests = $ARGV[0] eq '-fail' ? @fail :
  91. (@ARGV ? @ARGV : <t/CORE/*/*.t>);
  92. my $Mblib = Mblib;
  93. sub run_c {
  94. my ($t, $backend) = @_;
  95. chdir $dir;
  96. my $result = $t; $result =~ s/\.t$/-c.result/;
  97. my $a = $backend eq 'C' ? 'a' : 'aa';
  98. $result =~ s/-c.result$/-cc.result/ if $backend eq 'CC';
  99. unlink ($a, "$a.c", "t/$a.c", "t/CORE/$a.c", $result);
  100. # perlcc 2.06 should now work also: omit unneeded B::Stash -u<> and fixed linking
  101. # see t/c_argv.t
  102. my $backopts = $backend eq 'C' ? "-qq,C,-O3" : "-qq,CC";
  103. $backopts .= ",-fno-warnings" if $backend =~ /^C/ and $] >= 5.013005;
  104. $backopts .= ",-fno-fold" if $backend =~ /^C/ and $] >= 5.013009;
  105. vcmd "$^X $Mblib -MO=$backopts,-o$a.c $t";
  106. # CORE often does BEGIN chdir "t", patched to chdir "t/CORE"
  107. chdir $dir;
  108. move ("t/$a.c", "$a.c") if -e "t/$a.c";
  109. move ("t/CORE/$a.c", "$a.c") if -e "t/CORE/$a.c";
  110. my $d = "";
  111. $d = "-DALLOW_PERL_OPTIONS" if $ALLOW_PERL_OPTIONS{$t};
  112. vcmd "$^X $Mblib script/cc_harness -q $d $a.c -o $a" if -e "$a.c";
  113. vcmd "./$a | tee $result" if -e "$a";
  114. prove ($a, $result, $i, $t, $backend);
  115. $i++;
  116. }
  117. sub prove {
  118. my ($a, $result, $i, $t, $backend) = @_;
  119. if ( -e "$a" and -s $result) {
  120. system(qq[prove -Q --exec cat $result || echo -n "n";echo "ok $i - $backend $t"]);
  121. } else {
  122. print "not ok $i - $backend $t\n";
  123. }
  124. }
  125. print "1..", @tests * 3, "\n";
  126. my $i = 1;
  127. for my $t (@tests) {
  128. C: {
  129. (print "ok $i #skip $SKIP->{C}->{$t}\n" and goto CC)
  130. if exists $SKIP->{C}->{$t};
  131. run_c($t, "C");
  132. }
  133. CC: {
  134. (print "ok $i #skip $SKIP->{CC}->{$t}\n" and goto BC)
  135. if exists $SKIP->{CC}->{$t};
  136. run_c($t, "CC");
  137. }
  138. BC: {
  139. (print "ok $i #skip $SKIP->{BC}->{$t}\n" and next)
  140. if exists $SKIP->{BC}->{$t};
  141. my $backend = 'Bytecode';
  142. chdir $dir;
  143. $result = $t; $result =~ s/\.t$/-bc.result/;
  144. unlink ("b.plc", "t/b.plc", "t/CORE/b.plc", $result);
  145. vcmd "$^X $Mblib -MO=-qq,Bytecode,-H,-s,-ob.plc $t";
  146. chdir $dir;
  147. move ("t/b.plc", "b.plc") if -e "t/b.plc";
  148. move ("t/CORE/b.plc", "b.plc") if -e "t/CORE/b.plc";
  149. vcmd "$^X $Mblib b.plc > $result" if -e "b.plc";
  150. prove ("b.plc", $result, $i, $t, $backend);
  151. $i++;
  152. }
  153. }
  154. END {
  155. unlink ( "t/perl", "t/CORE/perl", "harness", "TEST" );
  156. unlink ("a","a.c","t/a.c","t/CORE/a.c","aa.c","aa","t/aa.c","t/CORE/aa.c","b.plc");
  157. }