autotest.pl 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/perl -w
  2. ## Author: Alois Mahdal at zxcvb cz
  3. # my private testing helper script
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. use v5.10;
  15. use warnings;
  16. $PLATFORM = (-d "c:\\windows" ? 'windows' : 'unix' );
  17. $DUMPS = "dumps";
  18. $TESTS = "t";
  19. $COLORS = { windows => { ok => 'color 0a', nok => 'color 0c' } };
  20. sub clear {
  21. if ($PLATFORM eq 'windows') {
  22. system "cls";
  23. } elsif ($PLATFORM eq 'unix') {
  24. system "clear";
  25. }
  26. }
  27. sub color {
  28. $mood = shift;
  29. $cmd = $COLORS->{$PLATFORM}->{$mood};
  30. system ($cmd) if $cmd;
  31. }
  32. sub cat {
  33. $_ = shift;
  34. my ($name) = m|^.*/(.*?)$|;
  35. printf "$name:\n";
  36. if (open my $fh, "<", $_) {
  37. my @lines = <$fh>;
  38. print @lines, "\n";
  39. close $fh or die "cannot close $_"
  40. }
  41. else {
  42. warn "cannot open $_";
  43. next STDERR;
  44. }
  45. }
  46. sub run_tests {
  47. my $ret = 0;
  48. printf "===== STDOUT =====\n";
  49. foreach (@_) {
  50. s|^$TESTS/*||;
  51. say "$_:";
  52. $cmd = sprintf 'perl %s 2>%s', "$TESTS\\$_", "$DUMPS\\$_.err";
  53. system($cmd);
  54. $ret = $? >> 8;
  55. if ($ret) {
  56. print "last test failed with exit code $ret!\n";
  57. return;
  58. }
  59. }
  60. return 1;
  61. }
  62. sub freakout {
  63. my $ret = shift;
  64. color "nok";
  65. my @paths = glob "$DUMPS/*.err";
  66. printf "\n===== STDERR =====\n";
  67. STDERR: foreach (@paths) {
  68. cat $_ and unlink $_ or warn "could not print $_";
  69. }
  70. }
  71. mkdir $DUMPS unless -d $DUMPS;
  72. while (1) {
  73. my @paths = glob "$TESTS/*.t";
  74. &clear;
  75. color "ok";
  76. my $ok = &run_tests(@paths);
  77. if ($ok) {
  78. say "------------------";
  79. say "All tests finished.";
  80. } else {
  81. &freakout();
  82. }
  83. sleep 5;
  84. }