echo.test 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. # This one's tricky both because echo is a shell builtin (so $PATH is
  4. # irrelevant) and because the "result" field is parsed with echo -e.
  5. # To make it work, "$CMD" is an explicit path to the command being tested,
  6. # so "result" keeps using the shell builtin but we test the one in toybox.
  7. #testing "name" "command" "result" "infile" "stdin"
  8. testcmd "echo" "&& $C yes" "\nyes\n" "" ""
  9. testcmd "1 2 3" "one two three" "one two three\n" "" ""
  10. testcmd "with spaces" "'one two three'" \
  11. "one two three\n" "" ""
  12. testcmd "" "-n" "" "" ""
  13. testcmd "" "-n one" "one" "" ""
  14. testcmd "" "one -n" "one -n\n" "" ""
  15. testcmd "-en" "-en 'one\ntwo'" "one\ntwo" "" ""
  16. testcmd "" "--hello" "--hello\n" "" ""
  17. testcmd "-e all" "-e '\a\b\c\f\n\r\t\v\\\0123' | xxd -p" "0708\n" "" ""
  18. testcmd "-e all but \\c" "-e '"'\a\b\f\n\r\t\v\\\0123'"' | xxd -p" \
  19. "07080c0a0d090b5c530a\n" "" ""
  20. testcmd "-nex hello" "-nex hello" "-nex hello\n" "" ""
  21. # Octal formatting tests
  22. testcmd "-e octal values" \
  23. "-ne '\01234 \0060 \060 \0130\0131\0132 \077\012'" \
  24. "S4 0 0 XYZ ?\n" "" ""
  25. testcmd "-e invalid oct" "-ne 'one\\079two'" "one\a9two" "" ""
  26. testcmd "-e \\0040" "-ne '\0040'" " " "" ""
  27. # Hexadecimal value tests
  28. testcmd "-e hexadecimal values" \
  29. "-ne '\x534 \x30 \x58\x59\x5a \x3F\x0A'"\
  30. "S4 0 XYZ ?\n" "" ""
  31. testcmd "-e invalid hex 1" "-e 'one\xvdtwo'" "one\\xvdtwo\n" "" ""
  32. testcmd "-e invalid hex 2" "-e 'one\xavtwo'" "one\nvtwo\n" "" ""
  33. # GNU extension for ESC
  34. testcmd "-e \e" "-ne '\\e' | xxd -p" "1b\n" "" ""
  35. testcmd "-e \p" "-e '\\p'" "\\p\n" "" ""
  36. # http://austingroupbugs.net/view.php?id=1222 added -E
  37. testcmd "-En" "-En 'one\ntwo'" 'one\\ntwo' "" ""
  38. testcmd "-eE" "-eE '\e'" '\\e\n' "" ""
  39. # This is how bash's built-in echo behaves, but now how /bin/echo behaves.
  40. toyonly testcmd "" "-e 'a\x123\ufb3bbc' | od -An -tx1" \
  41. " 61 12 33 ef ac bb 62 63 0a\n" "" ""
  42. testcmd "trailing nul" "-ne 'a\0b\0' | od -An -tx1" " 61 00 62 00\n" "" ""