diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-18 11:10:51 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-18 11:10:51 +0000 |
commit | a48656b441224a53d2bb3face920ba5487eaae09 (patch) | |
tree | 5120d90a6cd45463e5a7f358d6e01ab6d6e34c61 /testsuite | |
parent | 1a715e487dc6b37a996ff3041c332765dbba45a7 (diff) | |
download | busybox-w32-a48656b441224a53d2bb3face920ba5487eaae09.tar.gz busybox-w32-a48656b441224a53d2bb3face920ba5487eaae09.tar.bz2 busybox-w32-a48656b441224a53d2bb3face920ba5487eaae09.zip |
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-x | testsuite/printf.tests | 88 |
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 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | # Copyright 2008 by Denys Vlasenko | |
3 | set -e | 3 | # Licensed under GPL v2, see file LICENSE for details. |
4 | 4 | ||
5 | . testing.sh | 5 | . testing.sh |
6 | 6 | ||
@@ -9,25 +9,95 @@ bb="busybox " | |||
9 | 9 | ||
10 | # testing "test name" "command" "expected result" "file input" "stdin" | 10 | # testing "test name" "command" "expected result" "file input" "stdin" |
11 | 11 | ||
12 | testing "printf produce no further output 1" \ | 12 | testing "printf produces no further output 1" \ |
13 | "${bb}printf '\c' foo" \ | 13 | "${bb}printf '\c' foo" \ |
14 | "" \ | 14 | "" \ |
15 | "" "" | 15 | "" "" |
16 | 16 | ||
17 | testing "printf produce no further output 2" \ | 17 | testing "printf produces no further output 2" \ |
18 | "${bb}printf '%s\c' foo \$HOME" \ | 18 | "${bb}printf '%s\c' foo bar" \ |
19 | "foo" \ | 19 | "foo" \ |
20 | "" "" | 20 | "" "" |
21 | 21 | ||
22 | testing "printf repeatedly use pattern for each argv" \ | 22 | testing "printf repeatedly uses pattern for each argv" \ |
23 | "${bb}printf '%s\n' foo \$HOME" \ | 23 | "${bb}printf '%s\n' foo \$HOME" \ |
24 | "foo\n$HOME\n" \ | 24 | "foo\n$HOME\n" \ |
25 | "" "" | 25 | "" "" |
26 | 26 | ||
27 | # Why ()s are necessary I have no idea... | 27 | testing "printf understands %b escaped_string" \ |
28 | "${bb}printf '%b' 'a\tb' 'c\\d\n' 2>&1; echo \$?" \ | ||
29 | "a\tbc\\d\n""0\n" \ | ||
30 | "" "" | ||
31 | |||
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" \ | ||
35 | "" "" | ||
36 | |||
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" \ | ||
40 | "" "" | ||
41 | |||
42 | testing "printf understands %23.12f" \ | ||
43 | "${bb}printf '|%23.12f|\n' 5.25 2>&1; echo \$?" \ | ||
44 | "| 5.250000000000|\n""0\n" \ | ||
45 | "" "" | ||
46 | |||
47 | testing "printf understands %*.*f" \ | ||
48 | "${bb}printf '|%*.*f|\n' 23 12 5.25 2>&1; echo \$?" \ | ||
49 | "| 5.250000000000|\n""0\n" \ | ||
50 | "" "" | ||
51 | |||
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" \ | ||
55 | "" "" | ||
56 | |||
57 | testing "printf understands %.*f with negative precision" \ | ||
58 | "${bb}printf '|%.*f|\n' -12 5.25 2>&1; echo \$?" \ | ||
59 | "|5.250000|\n""0\n" \ | ||
60 | "" "" | ||
61 | |||
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" \ | ||
65 | "" "" | ||
66 | |||
67 | testing "printf understands %zd" \ | ||
68 | "${bb}printf '%zd\n' -5 2>&1; echo \$?" \ | ||
69 | "-5\n""0\n" \ | ||
70 | "" "" | ||
71 | |||
72 | testing "printf understands %ld" \ | ||
73 | "${bb}printf '%ld\n' -5 2>&1; echo \$?" \ | ||
74 | "-5\n""0\n" \ | ||
75 | "" "" | ||
76 | |||
77 | # We are "more correct" here than bash/coreutils: they happily print -2 | ||
78 | # as if it is a huge unsigned number | ||
79 | testing "printf handles %u -N" \ | ||
80 | "${bb}printf '%u\n' 1 -2 3 2>&1; echo \$?" \ | ||
81 | "1\n""printf: -2: invalid number\n""0\n""3\n""0\n" \ | ||
82 | "" "" | ||
83 | |||
84 | # Actually, we are wrong here: exit code should be 1 | ||
85 | testing "printf handles %d bad_input" \ | ||
86 | "${bb}printf '%d\n' 1 - 2 bad 3 123bad 4 2>&1; echo \$?" \ | ||
87 | "1\n""printf: -: invalid number\n""0\n"\ | ||
88 | "2\n""printf: bad: invalid number\n""0\n"\ | ||
89 | "3\n""printf: 123bad: invalid number\n""0\n"\ | ||
90 | "4\n""0\n" \ | ||
91 | "" "" | ||
92 | |||
28 | testing "printf aborts on bare %" \ | 93 | testing "printf aborts on bare %" \ |
29 | "(${bb}printf '%' a b c) 2>&1; echo \$?" \ | 94 | "${bb}printf '%' a b c 2>&1; echo \$?" \ |
30 | "printf: invalid directive '%'\n""1\n" \ | 95 | "printf: %: invalid format\n""1\n" \ |
96 | "" "" | ||
97 | |||
98 | testing "printf aborts on %r" \ | ||
99 | "${bb}printf '%r' a b c 2>&1; echo \$?" \ | ||
100 | "printf: %r: invalid format\n""1\n" \ | ||
31 | "" "" | 101 | "" "" |
32 | 102 | ||
33 | exit $FAILCOUNT | 103 | exit $FAILCOUNT |