run-single-test.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. if [ $# = 0 ]
  3. then
  4. echo "Argument required: <test name>"
  5. exit 1
  6. fi
  7. echo "Running test: $1"
  8. rm -rf ut_drive # ut for unit test
  9. rm -f "$1".cld
  10. rm -f test.err
  11. mkdir -p ut_drive
  12. cp -f "$1".bas ut_drive/
  13. # National CF-3300 is chosen because it uses BASIC 1.0 and includes a floppy.
  14. openmsx -machine National_CF-3300 -control stdio -diska ut_drive/\
  15. -script output_capture.tcl > /dev/null <<EOF
  16. <openmsx-control>
  17. <command>set save_settings_on_exit false</command>
  18. <command>set renderer none</command>
  19. <command>set maxframeskip 100</command>
  20. <command>set throttle false</command>
  21. <command>after time 30 exit</command>
  22. <command>set power on</command>
  23. <command>type_via_keybuf "\r\rload\"$1.bas\"\rsave\"$1.cld\"\r"</command>
  24. </openmsx-control>
  25. EOF
  26. python3-coverage run -a ../asc2cld.py "$1".bas "$1".cld 1 3>&2 2>&1 1>&3 |\
  27. sed -rn 's/.*BasicError: //p' > test.err
  28. if [ ! -e "$1".out ]
  29. then
  30. # Error expected.
  31. rm -rf ut_drive
  32. # Compare error message with actual error from machine.
  33. # Remove ESC Y sequences and CRs from input, as a normalization.
  34. sed -r -e $(printf 's/\eY..|\r//g') msx.out\
  35. | egrep -A999 $(printf '^load"')\
  36. | egrep -q "$(printf "\n\a?" ; cat test.err)$(printf "\a?\n")" -\
  37. || { echo "Error message differs, test: $1"; exit 1; }
  38. rm -f test.err msx.out
  39. exit 0
  40. fi
  41. # Success expected. Normalize like above to make msx.out and $1.out comparable.
  42. sed -r -e "$(printf 's/\eY..|\r//g')" msx.out | egrep -A999 '^load"'\
  43. | cmp "$1".out - || { echo "Expected output failed, test: $1"; exit 1; }
  44. # Compare tokenized code.
  45. cmp "$1".cld ut_drive/"$1".cld\
  46. && { rm -rf ut_drive; rm -f test.err msx.out "$1".cld; exit 0; }
  47. echo "Mismatch in tokenized code, test: $1"
  48. exit 1