tests/unpack-valid: port to printf that do not grok hex
authorJim Meyering <meyering@fb.com>
Sun, 29 Oct 2017 18:46:07 +0000 (11:46 -0700)
committerJim Meyering <meyering@fb.com>
Sun, 29 Oct 2017 18:51:32 +0000 (11:51 -0700)
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
tests/unpack-valid

index 901209ceae96dd53ef2d110784fdba39c98254b4..27515c5ad655d4819a70ae068a802e43b38f5b9a 100644 (file)
@@ -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"
+}
index 23484664eb6f5b2396cc7440d6d46c614d0197cc..8fdb203d111ba5695076510f2c2bf4712f810071 100755 (executable)
@@ -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