[PATCH 3/7] stdio-common: Add printf format tests for the b and B conversions
Matt Turner <[email protected]>
| Newsgroups | gmane.comp.lib.glibc.alpha |
|---|---|
| Message-ID | <[email protected]> |
The b and B conversions were left out when the formatted printf output
tests were added, because gawk does not handle them at all.
Verification no longer goes through AWK, so cover them now.
They follow the existing integer conversions, with the alternative form
producing the 0b or 0B prefix for a nonzero value.
Note that B was listed for neither the '#' and '0' flags nor precision,
so add it to those lists next to b, as otherwise most of its records
would never be produced.
Tested on x86_64-linux-gnu, where all 576 results pass.
---
stdio-common/tst-printf-format-skeleton.c | 6 +++---
stdio-common/tst-printf-format-uchar.sh | 2 +-
stdio-common/tst-printf-format-uint.sh | 2 +-
stdio-common/tst-printf-format-ullong.sh | 2 +-
stdio-common/tst-printf-format-ulong.sh | 2 +-
stdio-common/tst-printf-format-ushort.sh | 2 +-
stdio-common/tst-printf-format.py | 10 +++++-----
7 files changed, 13 insertions(+), 13 deletions(-)
diff --git ./stdio-common/tst-printf-format-skeleton.c ./stdio-common/tst-printf-format-skeleton.c
index 3594124513..c880da55e2 100644
--- ./stdio-common/tst-printf-format-skeleton.c
+++ ./stdio-common/tst-printf-format-skeleton.c
@@ -82,9 +82,9 @@
/* The list of conversions permitted for the '#' flag, the '0' flag,
and precision respectively. */
-#define HASH_FORMATS "boxXaAeEfFgG"
-#define ZERO_FORMATS "bdiouxXaAeEfFgG"
-#define PREC_FORMATS "bdiouxXaAeEfFgGs"
+#define HASH_FORMATS "bBoxXaAeEfFgG"
+#define ZERO_FORMATS "bBdiouxXaAeEfFgG"
+#define PREC_FORMATS "bBdiouxXaAeEfFgGs"
/* Output format conversion flags. */
static struct
diff --git ./stdio-common/tst-printf-format-uchar.sh ./stdio-common/tst-printf-format-uchar.sh
index d0d3627e8d..afd8de8ae6 100644
--- ./stdio-common/tst-printf-format-uchar.sh
+++ ./stdio-common/tst-printf-format-uchar.sh
@@ -25,7 +25,7 @@ test_program_prefix=$1; shift
status=0
-for f in o u x X; do
+for f in B b o u x X; do
echo Verifying $f
(set -o pipefail
${test_program_prefix} \
diff --git ./stdio-common/tst-printf-format-uint.sh ./stdio-common/tst-printf-format-uint.sh
index 2c32133212..de4cab01d4 100644
--- ./stdio-common/tst-printf-format-uint.sh
+++ ./stdio-common/tst-printf-format-uint.sh
@@ -25,7 +25,7 @@ test_program_prefix=$1; shift
status=0
-for f in o u x X; do
+for f in B b o u x X; do
echo Verifying $f
(set -o pipefail
${test_program_prefix} \
diff --git ./stdio-common/tst-printf-format-ullong.sh ./stdio-common/tst-printf-format-ullong.sh
index 1136f61bf9..5402ce1e0b 100644
--- ./stdio-common/tst-printf-format-ullong.sh
+++ ./stdio-common/tst-printf-format-ullong.sh
@@ -25,7 +25,7 @@ test_program_prefix=$1; shift
status=0
-for f in o u x X; do
+for f in B b o u x X; do
echo Verifying $f
(set -o pipefail
${test_program_prefix} \
diff --git ./stdio-common/tst-printf-format-ulong.sh ./stdio-common/tst-printf-format-ulong.sh
index 15802cec63..bc4800e0e1 100644
--- ./stdio-common/tst-printf-format-ulong.sh
+++ ./stdio-common/tst-printf-format-ulong.sh
@@ -25,7 +25,7 @@ test_program_prefix=$1; shift
status=0
-for f in o u x X; do
+for f in B b o u x X; do
echo Verifying $f
(set -o pipefail
${test_program_prefix} \
diff --git ./stdio-common/tst-printf-format-ushort.sh ./stdio-common/tst-printf-format-ushort.sh
index b08ae2906c..a11de87ecb 100644
--- ./stdio-common/tst-printf-format-ushort.sh
+++ ./stdio-common/tst-printf-format-ushort.sh
@@ -25,7 +25,7 @@ test_program_prefix=$1; shift
status=0
-for f in o u x X; do
+for f in B b o u x X; do
echo Verifying $f
(set -o pipefail
${test_program_prefix} \
diff --git ./stdio-common/tst-printf-format.py ./stdio-common/tst-printf-format.py
index d10580ae8a..a24ea5d402 100644
--- ./stdio-common/tst-printf-format.py
+++ ./stdio-common/tst-printf-format.py
@@ -40,10 +40,10 @@ from fractions import Fraction
# Conversions grouped by the C type of the corresponding argument.
FLOAT_CONVS = frozenset("eEfFgG")
-INT_CONVS = frozenset("diouxX")
+INT_CONVS = frozenset("bBdiouxX")
# The conversion specifier selects the base an integer is written in.
-INT_FORMATS = {"o": "%o", "u": "%d", "x": "%x", "X": "%X"}
+INT_FORMATS = {"b": "b", "B": "b", "o": "o", "u": "d", "x": "x", "X": "X"}
# Flags and length modifiers accepted in a conversion specification.
FLAG_CHARS = "-+ #0"
@@ -223,7 +223,7 @@ def convert_int(value, spec):
digits = str(-value if neg else value)
sign = spec.sign_of(neg)
else:
- digits = INT_FORMATS[conv] % value
+ digits = format(value, INT_FORMATS[conv])
sign = ""
if spec.prec is not None:
# A zero value converted with a precision of zero produces no
@@ -234,10 +234,10 @@ def convert_int(value, spec):
if spec.alt:
if conv == "o" and not digits.startswith("0"):
digits = "0" + digits
- elif conv in "xX" and value != 0:
+ elif conv in "bBxX" and value != 0:
# The base prefix precedes any '0' flag padding, so it pads
# along with the sign rather than with the digits.
- sign = "0x" if conv == "x" else "0X"
+ sign = "0" + conv
# An explicit precision defeats the '0' flag.
return spec.pad(digits, zero_ok=spec.prec is None, sign=sign)
--
2.54.0