aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-08-17 19:53:56 -0700
committerRob Landley <rob@landley.net>2019-08-19 11:23:41 -0500
commit81518f643d4d53b035b2cefbce25f06bd3cb5079 (patch)
tree9420219c83f68c0345b770a31d7958dc1eb6295a /tests
parentaa88ba047fa4210c03c3ad1168f84261167c3644 (diff)
downloadtoybox-81518f643d4d53b035b2cefbce25f06bd3cb5079.tar.gz
echo/printf: expand test cases, fix \x corner cases.
The behavior with "\xAV" (where the second hex digit is invalid) is different from the behavior with "\xVA", and echo and printf differ from each other.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/echo.test7
-rwxr-xr-xtests/printf.test16
2 files changed, 23 insertions, 0 deletions
diff --git a/tests/echo.test b/tests/echo.test
index 248454e7..80774e66 100755
--- a/tests/echo.test
+++ b/tests/echo.test
@@ -27,11 +27,18 @@ testcmd "-nex hello" "-nex hello" "-nex hello\n" "" ""
testcmd "-e octal values" \
"-ne '\01234 \0060 \060 \0130\0131\0132 \077\012'" \
"S4 0 0 XYZ ?\n" "" ""
+testcmd "-e invalid oct" "-ne 'one\\079two'" "one\a9two" "" ""
+testcmd "-e \\0040" "-ne '\0040'" " " "" ""
# Hexadecimal value tests
testcmd "-e hexadecimal values" \
"-ne '\x534 \x30 \x58\x59\x5a \x3F\x0A'"\
"S4 0 XYZ ?\n" "" ""
+testcmd "-e invalid hex 1" "-e 'one\xvdtwo'" "one\\xvdtwo\n" "" ""
+testcmd "-e invalid hex 2" "-e 'one\xavtwo'" "one\nvtwo\n" "" ""
+
+# GNU extension for ESC
+testcmd "-e \e" "-ne '\\e' | xxd -p" "1b\n" "" ""
testcmd "-e \p" "-e '\\p'" "\\p\n" "" ""
diff --git a/tests/printf.test b/tests/printf.test
index eb0e0bec..a341615e 100755
--- a/tests/printf.test
+++ b/tests/printf.test
@@ -68,3 +68,19 @@ testing "printf posix inconsistency" "$PRINTF '\\0066-%b' '\\0066'" "\x066-6" \
testing "printf \x" "$PRINTF 'A\x1b\x2B\x3Q\xa' | od -An -tx1" \
" 41 1b 2b 03 51 0a\n" "" ""
+
+testing "printf \c" "$PRINTF 'one\ctwo'" "one" "" ""
+
+# An extra leading 0 is fine for %b, but not as a direct escape, for some
+# reason...
+testing "printf octal %b" "$PRINTF '\0007%b' '\0007' | xxd -p" "003707\n" "" ""
+
+# Unlike echo, printf errors out on bad hex.
+testcmd "invalid hex 1" "'one\xvdtwo' 2>/dev/null || echo err" "oneerr\n" "" ""
+testcmd "invalid hex 2" "'one\xavtwo'" "one\nvtwo" "" ""
+# But bad octal is shown as text.
+testcmd "invalid oct" "'one\079two'" "one\a9two" "" ""
+
+# extension for ESC
+testcmd "%b \e" "'%b' '\\e' | xxd -p" "1b\n" "" ""
+testcmd "\e" "'\\e' | xxd -p" "1b\n" "" ""