aboutsummaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-18 11:10:51 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-18 11:10:51 +0000
commita48656b441224a53d2bb3face920ba5487eaae09 (patch)
tree5120d90a6cd45463e5a7f358d6e01ab6d6e34c61 /testsuite
parent1a715e487dc6b37a996ff3041c332765dbba45a7 (diff)
downloadbusybox-a48656b441224a53d2bb3face920ba5487eaae09.tar.gz
printf: fix %b, fix several bugs in %*.*, fix compat issues with
aborting too early, support %zd; expand testsuite function old new delta get_width_prec - 46 +46 multiconvert 82 99 +17 conv_strtod 44 54 +10 print_direc 382 391 +9 printf_main 629 633 +4 conv_strtoul 20 16 -4 conv_strtol 20 16 -4 my_xstrtoul 20 - -20 my_xstrtol 20 - -20 my_xstrtod 21 - -21 ------------------------------------------------------------------------------ (add/remove: 1/3 grow/shrink: 4/2 up/down: 86/-69) Total: 17 bytes
Diffstat (limited to 'testsuite')
-rwxr-xr-xtestsuite/printf.tests88
1 files changed, 79 insertions, 9 deletions
diff --git a/testsuite/printf.tests b/testsuite/printf.tests
index d6b60fb8c..a5c71ec9d 100755
--- a/testsuite/printf.tests
+++ b/testsuite/printf.tests
@@ -1,6 +1,6 @@
#!/bin/sh
-
-set -e
+# Copyright 2008 by Denys Vlasenko
+# Licensed under GPL v2, see file LICENSE for details.
. testing.sh
@@ -9,25 +9,95 @@ bb="busybox "
# testing "test name" "command" "expected result" "file input" "stdin"
-testing "printf produce no further output 1" \
+testing "printf produces no further output 1" \
"${bb}printf '\c' foo" \
"" \
"" ""
-testing "printf produce no further output 2" \
- "${bb}printf '%s\c' foo \$HOME" \
+testing "printf produces no further output 2" \
+ "${bb}printf '%s\c' foo bar" \
"foo" \
"" ""
-testing "printf repeatedly use pattern for each argv" \
+testing "printf repeatedly uses pattern for each argv" \
"${bb}printf '%s\n' foo \$HOME" \
"foo\n$HOME\n" \
"" ""
-# Why ()s are necessary I have no idea...
+testing "printf understands %b escaped_string" \
+ "${bb}printf '%b' 'a\tb' 'c\\d\n' 2>&1; echo \$?" \
+ "a\tbc\\d\n""0\n" \
+ "" ""
+
+testing "printf understands %d '\"x' \"'y\" \"'zTAIL\"" \
+ "${bb}printf '%d\n' '\"x' \"'y\" \"'zTAIL\" 2>&1; echo \$?" \
+ "120\n""121\n""122\n""0\n" \
+ "" ""
+
+testing "printf understands %s '\"x' \"'y\" \"'zTAIL\"" \
+ "${bb}printf '%s\n' '\"x' \"'y\" \"'zTAIL\" 2>&1; echo \$?" \
+ "\"x\n""'y\n""'zTAIL\n""0\n" \
+ "" ""
+
+testing "printf understands %23.12f" \
+ "${bb}printf '|%23.12f|\n' 5.25 2>&1; echo \$?" \
+ "| 5.250000000000|\n""0\n" \
+ "" ""
+
+testing "printf understands %*.*f" \
+ "${bb}printf '|%*.*f|\n' 23 12 5.25 2>&1; echo \$?" \
+ "| 5.250000000000|\n""0\n" \
+ "" ""
+
+testing "printf understands %*f with negative width" \
+ "${bb}printf '|%*f|\n' -23 5.25 2>&1; echo \$?" \
+ "|5.250000 |\n""0\n" \
+ "" ""
+
+testing "printf understands %.*f with negative precision" \
+ "${bb}printf '|%.*f|\n' -12 5.25 2>&1; echo \$?" \
+ "|5.250000|\n""0\n" \
+ "" ""
+
+testing "printf understands %*.*f with negative width/precision" \
+ "${bb}printf '|%*.*f|\n' -23 -12 5.25 2>&1; echo \$?" \
+ "|5.250000 |\n""0\n" \
+ "" ""
+
+testing "printf understands %zd" \
+ "${bb}printf '%zd\n' -5 2>&1; echo \$?" \
+ "-5\n""0\n" \
+ "" ""
+
+testing "printf understands %ld" \
+ "${bb}printf '%ld\n' -5 2>&1; echo \$?" \
+ "-5\n""0\n" \
+ "" ""
+
+# We are "more correct" here than bash/coreutils: they happily print -2
+# as if it is a huge unsigned number
+testing "printf handles %u -N" \
+ "${bb}printf '%u\n' 1 -2 3 2>&1; echo \$?" \
+ "1\n""printf: -2: invalid number\n""0\n""3\n""0\n" \
+ "" ""
+
+# Actually, we are wrong here: exit code should be 1
+testing "printf handles %d bad_input" \
+ "${bb}printf '%d\n' 1 - 2 bad 3 123bad 4 2>&1; echo \$?" \
+"1\n""printf: -: invalid number\n""0\n"\
+"2\n""printf: bad: invalid number\n""0\n"\
+"3\n""printf: 123bad: invalid number\n""0\n"\
+"4\n""0\n" \
+ "" ""
+
testing "printf aborts on bare %" \
- "(${bb}printf '%' a b c) 2>&1; echo \$?" \
- "printf: invalid directive '%'\n""1\n" \
+ "${bb}printf '%' a b c 2>&1; echo \$?" \
+ "printf: %: invalid format\n""1\n" \
+ "" ""
+
+testing "printf aborts on %r" \
+ "${bb}printf '%r' a b c 2>&1; echo \$?" \
+ "printf: %r: invalid format\n""1\n" \
"" ""
exit $FAILCOUNT