toybox/tests/echo.test
<<
>>
Prefs
   1#!/bin/bash
   2
   3[ -f testing.sh ] && . testing.sh
   4
   5# This one's tricky both because echo is a shell builtin (so $PATH is
   6# irrelevant) and because the "result" field is parsed with echo -e.
   7# To make it work, "$CMD" is an explicit path to the command being tested,
   8# so "result" keeps using the shell builtin but we test the one in toybox.
   9
  10#testing "name" "command" "result" "infile" "stdin"
  11
  12testcmd "echo" "&& echo yes" "\nyes\n" "" ""
  13testcmd "1 2 3" "one  two       three" "one two three\n" "" ""
  14testcmd "with spaces" "'one  two        three'" \
  15        "one  two       three\n" "" ""
  16testcmd "" "-n" "" "" ""
  17testcmd "" "-n one" "one" "" ""
  18testcmd "" "one -n" "one -n\n" "" ""
  19testcmd "-en" "-en 'one\ntwo'" "one\ntwo" "" ""
  20testcmd "" "--hello" "--hello\n" "" ""
  21testcmd "-e all" "-e '\a\b\c\f\n\r\t\v\\\0123' | xxd -p" "0708\n" "" ""
  22testcmd "-e all but \\c" "-e '"'\a\b\f\n\r\t\v\\\0123'"' | xxd -p" \
  23        "07080c0a0d090b5c530a\n" "" ""
  24testcmd "-nex hello" "-nex hello" "-nex hello\n" "" ""
  25
  26# Octal formatting tests
  27testcmd "-e octal values" \
  28        "-ne '\01234 \0060 \060 \0130\0131\0132 \077\012'" \
  29        "S4 0 0 XYZ ?\n" "" ""
  30
  31# Hexadecimal value tests
  32testcmd "-e hexadecimal values" \
  33        "-ne '\x534 \x30 \x58\x59\x5a \x3F\x0A'"\
  34        "S4 0 XYZ ?\n" "" ""
  35
  36testcmd "-e \p" "-e '\\p'" "\\p\n" "" ""
  37