runtest 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/sh
  2. if [ "$1" != "" ]; then
  3. cd $1
  4. fi
  5. testin=test.in
  6. testdb=test.cdc
  7. expected=expected
  8. binary=binary
  9. output=output
  10. prog="$$prog"
  11. trap "rm -rf $testdb $expected $binary $output $prog; exit" 0 1 2
  12. echo -n "Testing..."
  13. perl -e 'while (<>) {
  14. if (s/^\t//) {
  15. if (s/^Output: // || s/^\t//) {
  16. print STDOUT;
  17. }
  18. } else {
  19. print STDERR;
  20. }
  21. }' < $testin 1> $expected 2> $testdb
  22. ./coldcc -o -W -t $testdb 1> $output 2>/dev/null
  23. ## temporary hack until I fix the problems with output files in
  24. ## coldcc
  25. perl -e 'while (<>) { (!/^\r/) && print; }' < $output > ${output}.tmp
  26. mv ${output}.tmp $output
  27. if cmp -s $expected $output; then
  28. echo "All Tests pass."
  29. exit
  30. fi
  31. echo "FAILURE...The following test(s) failed:"
  32. echo '
  33. open(EXP, "expected") || die("open(expected): $!\n");
  34. $eline = 0;
  35. $test = "";
  36. $nextpos = <STDIN>;
  37. while (!eof(STDIN)) {
  38. $pos = $nextpos;
  39. $exp = "";
  40. $rec = "";
  41. while (<STDIN>) {
  42. if (s/^([<>-])//) {
  43. if ($1 eq "<") {
  44. $exp .= " $_";
  45. } elsif ($1 eq ">") {
  46. $rec .= " $_";
  47. }
  48. } else {
  49. $nextpos = $_;
  50. last;
  51. }
  52. }
  53. $xpos = int($pos);
  54. if ($eline < $xpos) {
  55. while (<EXP>) {
  56. $eline++;
  57. if ($eline >= $pos) {
  58. last;
  59. }
  60. if (!/^\s/) {
  61. chop($test = $_);
  62. }
  63. }
  64. }
  65. print "-- ${test}\n Expected:\n${exp} Received:\n${rec}";
  66. }' > $prog
  67. diff $expected $output | perl $prog