about summary refs log tree commit diff
path: root/Test
diff options
context:
space:
mode:
authordana <dana@dana.is>2021-05-03 18:08:11 -0500
committerdana <dana@dana.is>2021-05-03 18:11:38 -0500
commitc23a0d84b029676832ea0f2eeb0caa8c47d0500d (patch)
tree2d404a5367fb6b02b895a53b017d7aa1ffc0ab6e /Test
parent2da0d8b52fc90ce82891ae161fe6df89111c5e5c (diff)
downloadzsh-c23a0d84b029676832ea0f2eeb0caa8c47d0500d.tar.gz
zsh-c23a0d84b029676832ea0f2eeb0caa8c47d0500d.tar.xz
zsh-c23a0d84b029676832ea0f2eeb0caa8c47d0500d.zip
48614: getopts: Calculate OPTIND according to POSIX_BUILTINS
Diffstat (limited to 'Test')
-rw-r--r--Test/B10getopts.ztst29
1 files changed, 29 insertions, 0 deletions
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>