From 89fce1562e54a4198bf15ba1daf241fb9460474a Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 29 Oct 2017 11:46:07 -0700 Subject: [PATCH] tests/unpack-valid: port to printf that do not grok hex Many versions of printf do not handle hexadecimal in a format string, so this test would fail. * tests/init.cfg (hex_printf_): Copied from grep's tests/init.cfg. * tests/unpack-valid: Use hex_printf_. Reported by Bruno Haible in https://bugs.gnu.org/29033#26 --- tests/init.cfg | 10 ++++++++++ tests/unpack-valid | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/init.cfg b/tests/init.cfg index 901209c..27515c5 100644 --- a/tests/init.cfg +++ b/tests/init.cfg @@ -3,3 +3,13 @@ # This goes hand in hand with the "exec 9>&2;" in Makefile.am's # TESTS_ENVIRONMENT definition. stderr_fileno_=9 + +# Like printf with a single argument, but that argument must be a +# sequence of four-byte strings \xHH where each H is a hexadecimal byte. +hex_printf_() +{ + local octal_fmt=$(printf '\\%o' \ + $(printf '%s\n' "$1" \ + | sed 's,\\x\([0-9abcdefABCDEF][0-9abcdefABCDEF]\), 0x\1,g')) + printf "$octal_fmt" +} diff --git a/tests/unpack-valid b/tests/unpack-valid index 2348466..8fdb203 100755 --- a/tests/unpack-valid +++ b/tests/unpack-valid @@ -20,8 +20,8 @@ . "${srcdir=.}/init.sh"; path_prepend_ .. printf banana >exp || framework_failure_ -printf '\x1f\x1e\x00\x00\x00\x06\x03\x01\x01\x00\x61\x6e\x62\x16\xc8' >test.z \ - || framework_failure_ +hex_printf_ '\x1f\x1e\x00\x00\x00\x06\x03\x01\x01\x00\x61\x6e\x62\x16\xc8' \ + > test.z || framework_failure_ fail=0 gzip -dc test.z > out 2> err || fail=1 -- 2.13.5