blob: 3f562fd8e80ff8bdd547670b5d3d01f0e8660d14 [file] [log] [blame]
Rob Landley1a221d92008-05-17 17:13:26 -05001#!/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
10CMD="$(which echo)"
11
12#testing "name" "command" "result" "infile" "stdin"
13
14testing "echo" "$CMD && echo yes" "\nyes\n" "" ""
15testing "echo 1 2 3" "$CMD one two three" "one two three\n" "" ""
16testing "echo with spaces" "$CMD 'one two three'" \
17 "one two three\n" "" ""
18testing "echo -n" "$CMD -n" "" "" ""
19testing "echo -n one" "$CMD -n one" "one" "" ""
20testing "echo one -n" "$CMD one -n" "one -n\n" "" ""
21testing "echo -en" "$CMD -en 'one\ntwo'" "one\ntwo" "" ""
22testing "echo --hello" "$CMD --hello" "--hello\n" "" ""
23testing "echo -e all" "$CMD -e '\a\b\c\f\n\r\t\v\\\0123'" \
24 "\a\b\c\f\n\r\t\v\\\0123\n" "" ""
25testing "echo -nex hello" "$CMD -nex hello" "-nex hello\n" "" ""
Elie De Brauweref3e5282012-02-11 14:58:50 +010026
27# Octal formatting tests
28testing "echo -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
33testing "echo -e hexadecimal values" \
34 "$CMD -ne '\x534 \x30 \x58\x59\x5a \x3F\x0A'"\
35 "S4 0 XYZ ?\n" "" ""
Rob Landley73395602012-03-02 08:27:50 -060036
37testing "echo -e \p" "$CMD -e '\\p'" "\\p\n" "" ""