aboutsummaryrefslogtreecommitdiff
path: root/shell/ash_test
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-11 02:05:21 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-11 02:05:21 +0200
commit81f962f3df0d7194b7a52c6f83259727759094c4 (patch)
tree906d5d55118f0a7c96579c7d12c62b3a14311a7a /shell/ash_test
parent74d40589288890fffea437ed2f38ad1f2dc740e5 (diff)
downloadbusybox-w32-81f962f3df0d7194b7a52c6f83259727759094c4.tar.gz
busybox-w32-81f962f3df0d7194b7a52c6f83259727759094c4.tar.bz2
busybox-w32-81f962f3df0d7194b7a52c6f83259727759094c4.zip
hush: teach getopts to set/unset OPTARG
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash_test')
-rw-r--r--shell/ash_test/ash-getopts/getopt_optarg.right18
-rwxr-xr-xshell/ash_test/ash-getopts/getopt_optarg.tests16
2 files changed, 34 insertions, 0 deletions
diff --git a/shell/ash_test/ash-getopts/getopt_optarg.right b/shell/ash_test/ash-getopts/getopt_optarg.right
new file mode 100644
index 000000000..dff28de57
--- /dev/null
+++ b/shell/ash_test/ash-getopts/getopt_optarg.right
@@ -0,0 +1,18 @@
1*** no OPTIND, optstring:'w:et' args:-q -w e -r -t -y
2Illegal option -q
3var:'?' OPTIND:2 OPTARG:''
4var:'w' OPTIND:4 OPTARG:'e'
5Illegal option -r
6var:'?' OPTIND:5 OPTARG:''
7var:'t' OPTIND:6 OPTARG:''
8Illegal option -y
9var:'?' OPTIND:7 OPTARG:''
10exited: var:'?' OPTIND:7 OPTARG:''
11*** OPTIND=0, optstring:'w:et' args:-w 1 -w2 -w -e -e -t -t
12var:'w' OPTIND:3 OPTARG:'1'
13var:'w' OPTIND:4 OPTARG:'2'
14var:'w' OPTIND:6 OPTARG:'-e'
15var:'e' OPTIND:7 OPTARG:''
16var:'t' OPTIND:8 OPTARG:''
17var:'t' OPTIND:9 OPTARG:''
18exited: var:'?' OPTIND:9 OPTARG:''
diff --git a/shell/ash_test/ash-getopts/getopt_optarg.tests b/shell/ash_test/ash-getopts/getopt_optarg.tests
new file mode 100755
index 000000000..b346284f0
--- /dev/null
+++ b/shell/ash_test/ash-getopts/getopt_optarg.tests
@@ -0,0 +1,16 @@
1set -- -q -w e -r -t -y
2echo "*** no OPTIND, optstring:'w:et' args:$*"
3var=QWERTY
4OPTARG=ASDFGH
5while getopts "w:et" var; do
6 echo "var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
7done
8echo "exited: var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
9
10set -- -w 1 -w2 -w -e -e -t -t
11echo "*** OPTIND=0, optstring:'w:et' args:$*"
12OPTIND=0
13while getopts "w:et" var; do
14 echo "var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
15done
16echo "exited: var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"