2 # Copyright 2008 by Denys Vlasenko
3 # Licensed under GPLv2, see file LICENSE in this source tree.
7 # Need this in order to not execute shell builtin
10 # testing "test name" "command" "expected result" "file input" "stdin"
12 testing
"printf produces no further output 1" \
13 "${bb}printf '\c' foo" \
17 testing
"printf produces no further output 2" \
18 "${bb}printf '%s\c' foo bar" \
22 testing
"printf repeatedly uses pattern for each argv" \
23 "${bb}printf '%s\n' foo '$HOME'" \
27 testing
"printf understands %b escaped_string" \
28 "${bb}printf '%b' 'a\tb' 'c\\d\n' 2>&1; echo \$?" \
32 testing
"printf understands %d '\"x' \"'y\" \"'zTAIL\"" \
33 "${bb}printf '%d\n' '\"x' \"'y\" \"'zTAIL\" 2>&1; echo \$?" \
34 "120\n""121\n""122\n""0\n" \
37 testing
"printf understands %s '\"x' \"'y\" \"'zTAIL\"" \
38 "${bb}printf '%s\n' '\"x' \"'y\" \"'zTAIL\" 2>&1; echo \$?" \
39 "\"x\n""'y\n""'zTAIL\n""0\n" \
42 testing
"printf understands %23.12f" \
43 "${bb}printf '|%23.12f|\n' 5.25 2>&1; echo \$?" \
44 "| 5.250000000000|\n""0\n" \
47 testing
"printf understands %*.*f" \
48 "${bb}printf '|%*.*f|\n' 23 12 5.25 2>&1; echo \$?" \
49 "| 5.250000000000|\n""0\n" \
52 testing
"printf understands %*f with negative width" \
53 "${bb}printf '|%*f|\n' -23 5.25 2>&1; echo \$?" \
54 "|5.250000 |\n""0\n" \
57 testing
"printf understands %.*f with negative precision" \
58 "${bb}printf '|%.*f|\n' -12 5.25 2>&1; echo \$?" \
62 testing
"printf understands %*.*f with negative width/precision" \
63 "${bb}printf '|%*.*f|\n' -23 -12 5.25 2>&1; echo \$?" \
64 "|5.250000 |\n""0\n" \
67 testing
"printf understands %zd" \
68 "${bb}printf '%zd\n' -5 2>&1; echo \$?" \
72 testing
"printf understands %ld" \
73 "${bb}printf '%ld\n' -5 2>&1; echo \$?" \
77 testing
"printf understands %Ld" \
78 "${bb}printf '%Ld\n' -5 2>&1; echo \$?" \
82 testing
"printf understands %%" \
83 "${bb}printf '%%\n' 2>&1; echo \$?" \
87 testing
"printf handles positive numbers for %d" \
88 "${bb}printf '%d\n' 3 +3 ' 3' ' +3' 2>&1; echo \$?" \
95 testing
"printf handles positive numbers for %i" \
96 "${bb}printf '%i\n' 3 +3 ' 3' ' +3' 2>&1; echo \$?" \
103 testing
"printf handles positive numbers for %x" \
104 "${bb}printf '%x\n' 42 +42 ' 42' ' +42' 2>&1; echo \$?" \
111 testing
"printf handles positive numbers for %f" \
112 "${bb}printf '%0.3f\n' .42 +.42 ' .42' ' +.42' 2>&1; echo \$?" \
120 # "FIXED" now to act compatibly
121 ## We are "more correct" here than bash/coreutils: they happily print -2
122 ## as if it is a huge unsigned number
123 #testing "printf handles %u -N" \
124 # "${bb}printf '%u\n' 1 -2 3 2>&1; echo \$?" \
125 # "1\n""printf: -2: invalid number\n""0\n""3\n""0\n" \
128 testing
"printf handles %d bad_input" \
129 "${bb}printf '%d\n' 1 - 2 bad 3 123bad 4 2>&1; echo \$?" \
130 "1\n""printf: invalid number '-'\n""0\n"\
131 "2\n""printf: invalid number 'bad'\n""0\n"\
132 "3\n""printf: invalid number '123bad'\n""0\n"\
136 testing
"printf aborts on bare %" \
137 "${bb}printf '%' a b c 2>&1; echo \$?" \
138 "printf: %: invalid format\n""1\n" \
141 testing
"printf aborts on %r" \
142 "${bb}printf '%r' a b c 2>&1; echo \$?" \
143 "printf: %r: invalid format\n""1\n" \
146 testing
"printf treats leading 0 as flag" \
147 "${bb}printf '%0*d\n' 2 1 2>&1; echo \$?" \
151 testing
"printf handles multiple flags" \
152 "${bb}printf '%0 d\n' 2 2>&1; echo \$?" \