123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. use File::Spec;
  17. $PLATFORM = (-d "c:\\windows" ? 'windows' : 'unix' );
  18. $DUMPS = "dumps";
  19. $TESTS = "t";
  20. $COLORS = { windows => { ok => 'color 0a', nok => 'color 0c' } };
  21. sub clear {
  22. if ($PLATFORM eq 'windows') {
  23. system "cls";
  24. } elsif ($PLATFORM eq 'unix') {
  25. system "clear";
  26. }
  27. }
  28. sub color {
  29. $mood = shift;
  30. $cmd = $COLORS->{$PLATFORM}->{$mood};
  31. system ($cmd) if $cmd;
  32. }
  33. sub cat {
  34. my $name = File::Spec->splitpath( shift );
  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. my $name = File::Spec->splitpath( $_ );
  51. say "$name:";
  52. $cmd = sprintf 'perl %s 2>%s',
  53. File::Spec->catdir( $TESTS, $name ),
  54. File::Spec->catdir( $DUMPS, $name . '.err' );
  55. system($cmd);
  56. $ret = $? >> 8;
  57. if ($ret) {
  58. print "last test failed with exit code $ret!\n";
  59. return;
  60. }
  61. }
  62. return 1;
  63. }
  64. sub freakout {
  65. my $ret = shift;
  66. color "nok";
  67. my @paths = glob "$DUMPS/*.err";
  68. printf "\n===== STDERR =====\n";
  69. STDERR: foreach (@paths) {
  70. cat $_ and unlink $_ or warn "could not print $_";
  71. }
  72. }
  73. mkdir $DUMPS unless -d $DUMPS;
  74. while (1) {
  75. my @paths = glob "$TESTS/*.t";
  76. &clear;
  77. color "ok";
  78. my $ok = &run_tests(@paths);
  79. if ($ok) {
  80. say "------------------";
  81. say "All tests finished.";
  82. } else {
  83. &freakout();
  84. }
  85. sleep 5;
  86. }