tests: bonsai/npc.mk: fix harrowing ordeal of a Linux error

This commit is contained in:
dtb 2024-08-21 21:57:10 -06:00
parent 71d4d6ba05
commit 334433536b
Signed by: trinity
GPG Key ID: 34C0543BBB6AF81B

View File

@ -32,11 +32,30 @@ npc_ascii: npc_ascii_controls npc_ascii_symbols npc_ascii_uppers # \
.PHONY: npc_ascii_controls .PHONY: npc_ascii_controls
# (control characters) # (control characters)
npc_ascii_controls: npc_ascii_controls:
# The following test prints the bytes 0x00 (inclusive) through 0x20
# (exclusive) and pipes them through npc(1). npc(1) should then replace all
# non-printing, non-space (in the isspace(3p) sense) characters with their
# graphical carat-char counterparts (see the npc(1) man page). The head(1p)
# invocation then strips off everything past the first line (or past the
# first newline byte, 0x0A) and xargs(1p) is used to test(1p) the output
# against the known good answer.
# Immediately before that newline, 0x09 is printed - in ASCII, the
# horizontal tab. If xargs' -I option is used, tr(1p) should used to delete
# that tab. If the tab is left as part of input, OpenBSD's xargs(1)
# implementation has been observed to strip it along with the other
# trailing whitespace (the newline), but Busybox's and GNU's xargs(1)
# implementations have been observed to leave the tab in. All three
# implementations strip off the trailing tab if `-I` is not used. The POSIX
# specification for `-I` is ambiguous as to which behavior is correct.
# This comment is the result of much bewilderment and debugging.
# ASCII 0x00 to 0x0a (before the newline, due to xargs(1p) issues) # ASCII 0x00 to 0x0a (before the newline, due to xargs(1p) issues)
awk 'BEGIN{ for (i = 0; i < 32; ++i) printf("%c", i); }' \ awk 'BEGIN{ for (i = 0; i < 32; ++i) printf("%c", i); }' \
| $(BIN)/npc \ | $(BIN)/npc \
| head -n 1 \ | head -n 1 \
| xargs -I out test "^@^A^B^C^D^E^F^G^H" = out | tr -d '\t' \
| xargs test "^@^A^B^C^D^E^F^G^H" =
# ASCII 0x0a (otherwise the head|tail sequence won't work) to 0x1f # ASCII 0x0a (otherwise the head|tail sequence won't work) to 0x1f
awk 'BEGIN{ for (i = 0; i < 32; ++i) printf("%c", i); print }' \ awk 'BEGIN{ for (i = 0; i < 32; ++i) printf("%c", i); print }' \