ash.tests 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. #
  3. # These are not ash tests, we use ash as a way to test lineedit!
  4. #
  5. # Copyright 2010 by Denys Vlasenko
  6. # Licensed under GPL v2, see file LICENSE for details.
  7. . ./testing.sh
  8. test -f "$bindir/.config" && . "$bindir/.config"
  9. test x"CONFIG_SCRIPT" = x"y" || exit 0
  10. test x"CONFIG_HEXDUMP" = x"y" || exit 0
  11. test x"CONFIG_FEATURE_DEVPTS" = x"y" || exit 0
  12. # testing "test name" "options" "expected result" "file input" "stdin"
  13. if test x"$CONFIG_UNICODE_PRESERVE_BROKEN" = x"y"; then
  14. testing "One byte which is not valid unicode char followed by valid input" \
  15. "script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
  16. "\
  17. 00000000 ff 2d 0a |.-.|
  18. 00000003
  19. " \
  20. "" \
  21. "echo \xff- | hexdump -C >ash.output; exit; exit; exit; exit\n"
  22. testing "30 bytes which are not valid unicode chars followed by valid input" \
  23. "script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
  24. "\
  25. 00000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
  26. 00000010 ff ff ff ff ff ff ff ff ff ff ff ff ff ff 2d 0a |..............-.|
  27. 00000020
  28. " \
  29. "" \
  30. "echo \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff- | hexdump -C >ash.output; exit; exit; exit; exit\n"
  31. else
  32. testing "One byte which is not valid unicode char followed by valid input" \
  33. "script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
  34. "\
  35. 00000000 3f 2d 0a |?-.|
  36. 00000003
  37. " \
  38. "" \
  39. "echo \xff- | hexdump -C >ash.output; exit; exit; exit; exit\n"
  40. testing "30 bytes which are not valid unicode chars followed by valid input" \
  41. "script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
  42. "\
  43. 00000000 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f |????????????????|
  44. 00000010 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 2d 0a |??????????????-.|
  45. 00000020
  46. " \
  47. "" \
  48. "echo \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff- | hexdump -C >ash.output; exit; exit; exit; exit\n"
  49. fi
  50. # Not sure this behavior is perfect: we lose all invalid input which precedes
  51. # arrow keys and such. In this example, \xff\xff are lost
  52. testing "2 bytes which are not valid unicode chars followed by left arrow key" \
  53. "script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
  54. "\
  55. 00000000 3d 2d 0a |=-.|
  56. 00000003
  57. " \
  58. "" \
  59. "echo =+\xff\xff\x1b\x5b\x44- | hexdump -C >ash.output; exit; exit; exit; exit\n"
  60. # ash should see "echo \xff\n",pause -> execute it as "echo ?" (which is
  61. # not checked by the test), then read and execute the rest: "echo A | ..."
  62. # The bug was that ash was eating the beginning of "echo A" despite the pause.
  63. testing "Invalid unicode chars followed by a pause do not eat next chars" \
  64. "{ $ECHO -ne 'echo \xff\n'; sleep 1; $ECHO -ne 'echo A | hexdump -C >ash.output; exit; exit; exit; exit\n'; } \
  65. | script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
  66. "\
  67. 00000000 41 0a |A.|
  68. 00000002
  69. " \
  70. "" ""
  71. rm ash.output
  72. exit $FAILCOUNT