bc: fix for() to not leave data on stack
[oweals/busybox.git] / testsuite / printf.tests
index 0a63f0f5715c66acd7134a4891070edef4799cd7..34a65926eb6a565e3dab9d0d375d8348ba5ace58 100755 (executable)
@@ -1,8 +1,8 @@
 #!/bin/sh
 # Copyright 2008 by Denys Vlasenko
-# Licensed under GPL v2, see file LICENSE for details.
+# Licensed under GPLv2, see file LICENSE in this source tree.
 
-. testing.sh
+. ./testing.sh
 
 # Need this in order to not execute shell builtin
 bb="busybox "
@@ -20,7 +20,7 @@ testing "printf produces no further output 2" \
        "" ""
 
 testing "printf repeatedly uses pattern for each argv" \
-       "${bb}printf '%s\n' foo \$HOME" \
+       "${bb}printf '%s\n' foo '$HOME'" \
        "foo\n$HOME\n" \
        "" ""
 
@@ -79,6 +79,39 @@ testing "printf understands %Ld" \
        "-5\n""0\n" \
        "" ""
 
+testing "printf handles positive numbers for %d" \
+       "${bb}printf '%d\n' 3 +3 '   3' '   +3' 2>&1; echo \$?" \
+       "3\n"\
+"3\n"\
+"3\n"\
+"3\n""0\n" \
+       "" ""
+
+testing "printf handles positive numbers for %i" \
+       "${bb}printf '%i\n' 3 +3 '   3' '   +3' 2>&1; echo \$?" \
+       "3\n"\
+"3\n"\
+"3\n"\
+"3\n""0\n" \
+       "" ""
+
+testing "printf handles positive numbers for %x" \
+       "${bb}printf '%x\n' 42 +42 '   42' '   +42' 2>&1; echo \$?" \
+       "2a\n"\
+"2a\n"\
+"2a\n"\
+"2a\n""0\n" \
+       "" ""
+
+testing "printf handles positive numbers for %f" \
+       "${bb}printf '%0.3f\n' .42 +.42 '   .42' '   +.42' 2>&1; echo \$?" \
+       "0.420\n"\
+"0.420\n"\
+"0.420\n"\
+"0.420\n""0\n" \
+       "" ""
+
+
 # "FIXED" now to act compatibly
 ## We are "more correct" here than bash/coreutils: they happily print -2
 ## as if it is a huge unsigned number
@@ -89,9 +122,9 @@ testing "printf understands %Ld" \
 
 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"\
+"1\n""printf: invalid number '-'\n""0\n"\
+"2\n""printf: invalid number 'bad'\n""0\n"\
+"3\n""printf: invalid number '123bad'\n""0\n"\
 "4\n""1\n" \
        "" ""