OSDN Git Service

Merge changes I768f0948,I3d79bb35 am: 2474ba9744
[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 #testing "name" "command" "result" "infile" "stdin"
11
12 testcmd "echo" "&& echo yes" "\nyes\n" "" ""
13 testcmd "1 2 3" "one  two       three" "one two three\n" "" ""
14 testcmd "with spaces" "'one  two        three'" \
15         "one  two       three\n" "" ""
16 testcmd "" "-n" "" "" ""
17 testcmd "" "-n one" "one" "" ""
18 testcmd "" "one -n" "one -n\n" "" ""
19 testcmd "-en" "-en 'one\ntwo'" "one\ntwo" "" ""
20 testcmd "" "--hello" "--hello\n" "" ""
21 testcmd "-e all" "-e '\a\b\c\f\n\r\t\v\\\0123' | xxd -p" "0708\n" "" ""
22 testcmd "-e all but \\c" "-e '"'\a\b\f\n\r\t\v\\\0123'"' | xxd -p" \
23         "07080c0a0d090b5c530a\n" "" ""
24 testcmd "-nex hello" "-nex hello" "-nex hello\n" "" ""
25
26 # Octal formatting tests
27 testcmd "-e octal values" \
28         "-ne '\01234 \0060 \060 \0130\0131\0132 \077\012'" \
29         "S4 0 0 XYZ ?\n" "" ""
30
31 # Hexadecimal value tests
32 testcmd "-e hexadecimal values" \
33         "-ne '\x534 \x30 \x58\x59\x5a \x3F\x0A'"\
34         "S4 0 XYZ ?\n" "" ""
35
36 testcmd "-e \p" "-e '\\p'" "\\p\n" "" ""