Mock.pm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package
  2. Mock; # do not index
  3. use strict;
  4. BEGIN {
  5. unshift @INC, 't';
  6. }
  7. =head1 NAME
  8. Mock lengthy compiler tests. Replay from TAP.
  9. =head1 DESCRIPTION
  10. Replay results from stored log files to test the result of the
  11. current TODO status.
  12. Currently perl compiler tests are stored in two formats:
  13. 1. log.test-$arch-$perlversion
  14. 2. log.modules-$perlversion
  15. When running the Mock tests the actual tests are not executed,
  16. instead the results from log file are used instead. A typical
  17. perl-compiler testrun lasts several hours to days, with Mock
  18. several seconds.
  19. =head1 SYNOPSIS
  20. perlall="5.6.2 5.8.9 5.10.1 5.12.1 5.13.4"
  21. # actual tests
  22. for p in perl$perlall; do
  23. perl$p Makefile.PL && make && \
  24. make test TEST_VERBOSE=1 2>&1 > log.test-`uname -s`-$p
  25. done
  26. # fixup TODO's
  27. # check tests
  28. for p in perl$perlall; do
  29. perl$p t/mock t/*.t
  30. done
  31. =cut
  32. require "test.pl";
  33. use Test::More;
  34. use TAP::Parser;
  35. use Test::Harness::Straps;
  36. use Config;
  37. use Cwd;
  38. use Exporter;
  39. our $details;
  40. our @ISA = qw(Exporter);
  41. our @EXPORT = qw(find_modules_report find_test_report
  42. mock_harness run_cc_test ctest ctestok ccompileok
  43. );
  44. # log.test or log.modules
  45. # check only the latest version, and match revision and perlversion
  46. sub find_test_report ($;$) {
  47. my $logdir = shift;
  48. my $arch = shift || `uname -s`;
  49. #log.test-$arch-$versuffix
  50. my $tmpl = "$logdir/log.test-*-5.*";
  51. my @f = latest_files($tmpl);
  52. }
  53. sub find_modules_report {
  54. my $logdir = shift;
  55. #log.modules-$ver$suffix
  56. latest_files("$logdir/log.modules-5.*");
  57. }
  58. # check date, max diff one day from youngest
  59. sub latest_files {
  60. my $tmpl = shift;
  61. my @f = glob $tmpl;
  62. my @fdates = sort{$a->[1]<=>$b->[1]} map { [$_ => -M $_] } @f;
  63. my $latest = $fdates[0]->[1];
  64. my @ret;
  65. for (@fdates) {
  66. if ($_->[1]-$latest < 1.2) {
  67. push @ret, $_->[0];
  68. } else {
  69. last;
  70. }
  71. }
  72. @ret;
  73. }
  74. sub parse_report {
  75. my ($log, $t) = @_;
  76. my $straps = Test::Harness::Straps->new;
  77. open my $fh, "<", $log;
  78. my $result = $straps->analyze_fh($t, $fh);
  79. close $fh;
  80. # XXX replay only the part for the given test
  81. $result;
  82. }
  83. sub result ($) {
  84. my $parse = shift;
  85. }
  86. # 1, "C", "require LWP::UserAgent;\nprint q(ok);", "ok",0,1,"#TODO issue 27"
  87. sub run_cc_test {
  88. my ($cnt, $backend, $script, $expect, $keep_c, $keep_c_fail, $todo) = @_;
  89. print @_;
  90. }
  91. # 1, "ok", "CC", "ccode37i", $script, $todo
  92. sub ctest {
  93. my ($num, $expected, $backend, $base, $script, $todo) = @_;
  94. print @_;
  95. }
  96. # 1, "CC", "ccode37i", $script, $todo
  97. #sub ctestok {
  98. #}
  99. # 1, "CC", "ccode36i", $script, $todo
  100. sub ccompileok {
  101. my ($num, $backend, $base, $script, $todo) = @_;
  102. print @_;
  103. }
  104. sub mock_harness {
  105. my ($log, $t) = @_;
  106. my $rpt = parse_report($log, $t);
  107. $details = $rpt->details;
  108. # execute the real tests with mock_harness (overridden test)
  109. my $X = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
  110. my $dbg = $^P ? "-d" : "";
  111. system("$X $dbg -It -MMock -MExtUtils::Command::MM -e\"test_harness(1, 'blib/lib', 'blib/arch')\" $t");
  112. }
  113. 1;