From 238ff98bb85adfb5563d10b37ea4c33fef3af2f2 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 29 Aug 2017 13:38:30 +0200 Subject: hush: fix "getopts" builtin to not be upset by other builtins calling getopt() function old new delta builtin_getopts 363 403 +40 unset_local_var_len 185 215 +30 set_local_var 440 466 +26 reset_traps_to_defaults 151 157 +6 pseudo_exec_argv 320 326 +6 install_special_sighandlers 52 58 +6 pick_sighandler 62 65 +3 execvp_or_die 85 88 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 8/0 up/down: 120/0) Total: 120 bytes Signed-off-by: Denys Vlasenko --- shell/hush_test/hush-getopts/getopt_nested.tests | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 shell/hush_test/hush-getopts/getopt_nested.tests (limited to 'shell/hush_test/hush-getopts/getopt_nested.tests') diff --git a/shell/hush_test/hush-getopts/getopt_nested.tests b/shell/hush_test/hush-getopts/getopt_nested.tests new file mode 100755 index 000000000..1b48b4075 --- /dev/null +++ b/shell/hush_test/hush-getopts/getopt_nested.tests @@ -0,0 +1,21 @@ +# Test that there is no interference of getopt() +# in getopts and unset. +# It's unclear what "correct" OPTIND values should be +# for "b" and "c" results from "-bc": 2? 3? +# What we focus on here is that all options are reported +# correct number of times and in correct sequence. + +( + +loop=99 +while getopts "abc" var -a -bc -abc -def -a; do + echo "var:$var" #OPTIND:$OPTIND + # this may use getopt(): + unset -ff func + test $((--loop)) = 0 && break # BUG if this triggers +done +echo "End: var:$var OPTIND:$OPTIND" + +) 2>&1 \ +| sed -e 's/ unrecognized option: / invalid option -- /' \ + -e 's/ illegal option -- / invalid option -- /' \ -- cgit v1.2.3