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" "&& $C 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" "" "" 30testcmd "-e invalid oct" "-ne 'one\\079two'" "one\a9two" "" "" 31testcmd "-e \\0040" "-ne '\0040'" " " "" "" 32 33# Hexadecimal value tests 34testcmd "-e hexadecimal values" \ 35 "-ne '\x534 \x30 \x58\x59\x5a \x3F\x0A'"\ 36 "S4 0 XYZ ?\n" "" "" 37testcmd "-e invalid hex 1" "-e 'one\xvdtwo'" "one\\xvdtwo\n" "" "" 38testcmd "-e invalid hex 2" "-e 'one\xavtwo'" "one\nvtwo\n" "" "" 39 40# GNU extension for ESC 41testcmd "-e \e" "-ne '\\e' | xxd -p" "1b\n" "" "" 42 43testcmd "-e \p" "-e '\\p'" "\\p\n" "" "" 44 45# http://austingroupbugs.net/view.php?id=1222 added -E 46testcmd "-En" "-En 'one\ntwo'" 'one\\ntwo' "" "" 47testcmd "-eE" "-eE '\e'" '\\e\n' "" "" 48 49# This is how bash's built-in echo behaves, but now how /bin/echo behaves. 50toyonly testcmd "" "-e 'a\x123\ufb3bbc' | od -An -tx1" \ 51 " 61 12 33 ef ac bb 62 63 0a\n" "" "" 52 53testcmd "trailing nul" "-ne 'a\0b\0' | od -An -tx1" " 61 00 62 00\n" "" "" 54