testcore.t 5.1 KB

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