From c23a0d84b029676832ea0f2eeb0caa8c47d0500d Mon Sep 17 00:00:00 2001 From: dana Date: Mon, 3 May 2021 18:08:11 -0500 Subject: 48614: getopts: Calculate OPTIND according to POSIX_BUILTINS --- Test/B10getopts.ztst | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'Test') diff --git a/Test/B10getopts.ztst b/Test/B10getopts.ztst index 72c9e209e..e50d177c7 100644 --- a/Test/B10getopts.ztst +++ b/Test/B10getopts.ztst @@ -96,3 +96,32 @@ done 0:missing option-argument (quiet mode) >:,x + + # This function is written so it can be easily referenced against other shells + t() { + local o i=0 n=$1 + shift + while [ $i -lt $n ]; do + i=$(( i + 1 )) + getopts a: o "$@" 2> /dev/null + done + printf '<%d>' "$OPTIND" + } + # Try all these the native way, then the POSIX_BUILTINS way + for 1 in no_posix_builtins posix_builtins; do ( + setopt $1 + print -rn - "$1: " + t 1 + t 1 foo + t 1 -- foo + t 1 -a + t 1 -b + t 2 -a -b + t 4 -a -b -c -d -a + t 5 -a -b -c -a -b -c + t 5 -a -b -c -d -ax -a + print + ); done +0:OPTIND calculation with and without POSIX_BUILTINS (workers/42248) +>no_posix_builtins: <1><1><2><1><1><3><5><7><6> +>posix_builtins: <1><1><2><2><2><3><6><7><7> -- cgit 1.4.1