summaryrefslogtreecommitdiffstats
path: root/Test
diff options
context:
space:
mode:
authordana <dana@dana.is>2026-05-04 20:16:03 -0500
committerdana <dana@dana.is>2026-05-06 21:44:56 -0500
commit08a487691c417fb24fde8b51fe9bd27bbcd0a63a (patch)
tree4df1267c984ccfa03af8346f46cb48374a20784c /Test
parent54454: _values: auto-remove argument separator (diff)
downloadzsh-08a487691c417fb24fde8b51fe9bd27bbcd0a63a.tar
zsh-08a487691c417fb24fde8b51fe9bd27bbcd0a63a.tar.gz
zsh-08a487691c417fb24fde8b51fe9bd27bbcd0a63a.tar.bz2
zsh-08a487691c417fb24fde8b51fe9bd27bbcd0a63a.tar.lz
zsh-08a487691c417fb24fde8b51fe9bd27bbcd0a63a.tar.xz
zsh-08a487691c417fb24fde8b51fe9bd27bbcd0a63a.tar.zst
zsh-08a487691c417fb24fde8b51fe9bd27bbcd0a63a.zip
54471: getopts: don't look for +o with posix_builtins, add -p
Diffstat (limited to 'Test')
-rw-r--r--Test/B10getopts.ztst61
1 files changed, 61 insertions, 0 deletions
diff --git a/Test/B10getopts.ztst b/Test/B10getopts.ztst
index e50d177c7..5ababebcc 100644
--- a/Test/B10getopts.ztst
+++ b/Test/B10getopts.ztst
@@ -125,3 +125,64 @@
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>
+
+ for 1 in no_posix_builtins posix_builtins; do (
+ setopt $1
+ print -rn - $1:
+ set -- -a -b +b -c
+ while getopts :abc opt; do
+ case $opt in
+ a|b|+b|c) print -rn - " $opt" ;;
+ ?) print -rn - " ?$OPTARG" ;;
+ esac
+ done
+ print
+ ); done
+0:POSIX_BUILTINS disables '+' variant handling
+>no_posix_builtins: a b +b c
+>posix_builtins: a b
+
+ (
+ setopt no_posix_builtins
+ for 1 in -a +a -x +x; do
+ () { local opt; getopts :abc opt; print -r - $opt } $1
+ done
+ for 1 in -a +a -x +x; do
+ () { local opt; getopts -p :abc opt; print -r - $opt } $1
+ done
+ )
+0:-p works like POSIX_BUILTINS
+>a
+>+a
+>?
+>?
+>a
+>
+>?
+>
+
+ # not enough arguments
+ () { getopts }
+ () { getopts '' }
+ () { getopts x }
+ () { getopts - x }
+ () { getopts -p - x }
+ () { getopts -p -- x }
+ # invalid option to getopts
+ () { getopts -x x }
+ () { getopts -x x y }
+ () { getopts -x - x y }
+ # guarded spec
+ () { getopts - -x y }
+ # argv on command line
+ () { getopts x y a b c }
+-:option parsing
+?(anon):getopts: not enough arguments
+?(anon):getopts: not enough arguments
+?(anon):getopts: not enough arguments
+?(anon):getopts: not enough arguments
+?(anon):getopts: not enough arguments
+?(anon):getopts: not enough arguments
+?(anon):getopts: bad option: -x
+?(anon):getopts: bad option: -x
+?(anon):getopts: bad option: -x