term_config.sh 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. # tests/term_config.sh -- assert the terminal CONFIG loader and decoder.
  3. #
  4. # The shell reads TP3.TRM at startup (TermCfg.Load) instead of having escape
  5. # sequences patched into it. This suite is that loader's oracle: it feeds a
  6. # fixture config to a tiny harness and compares every decoded sequence byte for
  7. # byte. The interesting cases are the ones an eyeball misses:
  8. #
  9. # * \e must be ONE ESC byte, not a backslash and an 'e';
  10. # * ^G must be BEL (07), not '^' and 'G';
  11. # * the ANSI default must survive when no keys are given;
  12. # * VT52's GOTO uses %R/%C (raw bytes), which are still just text here - the
  13. # shell substitutes them, and their presence is pinned so the substitution
  14. # site cannot silently lose them.
  15. #
  16. # It is a separate suite, not part of the shell UI tests, because the loader is
  17. # pure data: no pty, no screen, no timing.
  18. set -u
  19. D=/home/eric/Projets/Projets-Modula2/MyWork/TP3-comp/shell
  20. GM2=/home/eric/Modula2/Gm2/bin/gm2
  21. [ -x "$GM2" ] || GM2=/home/eric/bin/Modula2/Gm2/bin/gm2
  22. cd "$D" || exit 9
  23. mkdir -p ../tmp
  24. if [ ! -f Posix.o ] || [ Posix.c -nt Posix.o ]; then
  25. cc -c Posix.c >../tmp/termcfg_c_posix 2>&1 || {
  26. echo "COMPILE_FAIL Posix"; grep -m5 "error:" ../tmp/termcfg_c_posix; exit 1; }
  27. fi
  28. if [ ! -f TermCfg.o ] || [ TermCfg.mod -nt TermCfg.o ]; then
  29. $GM2 -fiso -c TermCfg.mod >../tmp/termcfg_c 2>&1 || {
  30. echo "COMPILE_FAIL TermCfg"; grep -m5 "error:" ../tmp/termcfg_c; exit 1; }
  31. fi
  32. if [ ! -x tests/termcfgtest ] || [ tests/TermCfgTest.mod -nt tests/termcfgtest ] \
  33. || [ TermCfg.o -nt tests/termcfgtest ] || [ Posix.o -nt tests/termcfgtest ]; then
  34. rm -f tests/termcfgtest
  35. $GM2 -fiso -o tests/termcfgtest tests/TermCfgTest.mod TermCfg.o Posix.o \
  36. >../tmp/termcfg_link 2>&1 || {
  37. echo "LINK_FAIL"; grep -m5 -E "error:|undefined" ../tmp/termcfg_link; exit 1; }
  38. fi
  39. pass=0; fail=0
  40. for name in term_ansi term_vt52; do
  41. cp "tests/fixtures/$name.trm" ../tmp/term_test.trm || exit 1
  42. ./tests/termcfgtest > "../tmp/$name.got" 2>&1
  43. if diff -u "tests/fixtures/$name.hex" "../tmp/$name.got" > "../tmp/$name.diff"; then
  44. printf ' %-20s PASS\n' "$name"
  45. pass=$((pass + 1))
  46. else
  47. printf ' %-20s FAIL\n' "$name"
  48. head -20 "../tmp/$name.diff"
  49. fail=$((fail + 1))
  50. fi
  51. done
  52. # ---- the editor's key map ------------------------------------------------
  53. if [ ! -f Keys.o ] || [ Keys.mod -nt Keys.o ]; then
  54. $GM2 -fiso -c Keys.mod >../tmp/termcfg_c_keys 2>&1 || {
  55. echo "COMPILE_FAIL Keys"; grep -m5 "error:" ../tmp/termcfg_c_keys; exit 1; }
  56. fi
  57. if [ ! -x tests/keycfgtest ] || [ tests/KeysTest.mod -nt tests/keycfgtest ] \
  58. || [ Keys.o -nt tests/keycfgtest ] || [ TermCfg.o -nt tests/keycfgtest ]; then
  59. rm -f tests/keycfgtest
  60. $GM2 -fiso -o tests/keycfgtest tests/KeysTest.mod Keys.o TermCfg.o Posix.o \
  61. >../tmp/keycfg_link 2>&1 || {
  62. echo "LINK_FAIL KeysTest"; grep -m5 -E "error:|undefined" ../tmp/keycfg_link; exit 1; }
  63. fi
  64. for name in key_default key_custom; do
  65. cp "tests/fixtures/$name.key" ../tmp/key_test.key || exit 1
  66. ./tests/keycfgtest > "../tmp/$name.got" 2>&1
  67. if diff -u "tests/fixtures/$name.hex" "../tmp/$name.got" > "../tmp/$name.diff"; then
  68. printf ' %-20s PASS\n' "$name"
  69. pass=$((pass + 1))
  70. else
  71. printf ' %-20s FAIL\n' "$name"
  72. head -20 "../tmp/$name.diff"
  73. fail=$((fail + 1))
  74. fi
  75. done
  76. echo "----------------------------------------------------------------"
  77. echo "terminal config: $pass passed, $fail failed (of $((pass + fail)))"
  78. [ "$fail" -eq 0 ] || exit 1