OSDN Git Service

basename: fix segfault on null input; add tests
[android-x86/external-toybox.git] / tests / echo.test
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 CMD="$(which echo)"
11
12 #testing "name" "command" "result" "infile" "stdin"
13
14 testing "echo" "$CMD && echo yes" "\nyes\n" "" ""
15 testing "1 2 3" "$CMD one  two  three" "one two three\n" "" ""
16 testing "with spaces" "$CMD 'one  two   three'" \
17         "one  two       three\n" "" ""
18 testing "-n" "$CMD -n" "" "" ""
19 testing "-n one" "$CMD -n one" "one" "" ""
20 testing "one -n" "$CMD one -n" "one -n\n" "" ""
21 testing "-en" "$CMD -en 'one\ntwo'" "one\ntwo" "" ""
22 testing "--hello" "$CMD --hello" "--hello\n" "" ""
23 testing "-e all" "$CMD -e '\a\b\c\f\n\r\t\v\\\0123'" \
24         "\a\b\c\f\n\r\t\v\\\0123\n" "" ""
25 testing "-nex hello" "$CMD -nex hello" "-nex hello\n" "" ""
26
27 # Octal formatting tests
28 testing "-e octal values" \
29         "$CMD -ne '\01234 \0060 \060 \0130\0131\0132 \077\012'" \
30         "S4 0 0 XYZ ?\n" "" ""
31
32 # Hexadecimal value tests
33 testing "-e hexadecimal values" \
34         "$CMD -ne '\x534 \x30 \x58\x59\x5a \x3F\x0A'"\
35         "S4 0 XYZ ?\n" "" ""
36
37 testing "-e \p" "$CMD -e '\\p'" "\\p\n" "" ""