logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: cb193c6e878d08097d6e503287071c2bd154b948
parent 5e49368e64f10e226c7f192d471bd14565f0f84b
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 28 Dec 2025 03:21:49 +0100

cmd/printf: add ARG_MAX based tests

Diffstat:

Mtest-cmd/printf.sh31++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/test-cmd/printf.sh b/test-cmd/printf.sh @@ -2,7 +2,7 @@ # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> # SPDX-License-Identifier: MPL-2.0 -plans=43 +plans=48 WD="$(dirname "$0")/../" target="${WD}/cmd/printf" . "${WD}/test-cmd/tap.sh" @@ -80,3 +80,32 @@ t_args extraconv_d '42;69;0;' '%d;%d;%d;' 42 69 t_args fmt_star_width ' foo;bar;' '%*s;' 4 foo 2 bar t_args fmt_star_width_prec0 ' ; ;' '%*.0s;' 4 foo 2 bar t_args fmt_star_prec 'foo;ba;' '%.*s;' 4 foo 2 bar + +wc_c() { + "$target" "$@" | wc -c | tr -cd '[:graph:]' +} + +if arg_max=$(getconf ARG_MAX); then + # 64 should be enough but somehow ArchLinux and {Free,Net,Open}BSD need more + # 128 also wasn't enough for them + # 1024 is 1/4th of _POSIX_ARG_MAX so really ought to be enough leeway + arg_max=$((arg_max - 1024)) + + arg_max=$(( (arg_max/2)*2 )) + max_str=$("$target" '%*s' "$arg_max" '' | tr ' ' '=') + max_esc=$("$target" '%*s' "$arg_max" '' | tr ' ' '\\') + + t_cmd arg_max_str "$arg_max" wc_c "$max_str" + t_cmd arg_max_str:%s "$arg_max" wc_c '%s' "$max_str" + + t_cmd arg_max_esc "$((arg_max/2))" wc_c "$max_esc" + t_cmd arg_max_esc:%b "$((arg_max/2))" wc_c '%b' "$max_esc" + t_cmd arg_max_esc:%s "$arg_max" wc_c '%s' "$max_esc" +else + skip arg_max_str + skip arg_max_str:%s + + skip arg_max_esc + skip arg_max_esc:%b + skip arg_max_esc:%s +fi