diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-11 17:21:14 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-11 17:21:14 +0200 |
commit | 419db0391e47444dd12fb052613fd415694d04f0 (patch) | |
tree | 0b989526666cd6150b7bae6151f9273c4a5db487 /shell/ash_test/ash-getopts | |
parent | 129e1ce72c28ec14aee459cceffc25ed9d5cae85 (diff) | |
download | busybox-419db0391e47444dd12fb052613fd415694d04f0.tar.gz |
hush: implement "silent" optstrings of ":opts"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash_test/ash-getopts')
-rw-r--r-- | shell/ash_test/ash-getopts/getopt_silent.right | 6 | ||||
-rwxr-xr-x | shell/ash_test/ash-getopts/getopt_silent.tests | 23 |
2 files changed, 29 insertions, 0 deletions
diff --git a/shell/ash_test/ash-getopts/getopt_silent.right b/shell/ash_test/ash-getopts/getopt_silent.right new file mode 100644 index 000000000..03d4eb149 --- /dev/null +++ b/shell/ash_test/ash-getopts/getopt_silent.right @@ -0,0 +1,6 @@ +*** optstring:':ac' args:-a -b -c +1 rc:0 var:'a' OPTIND:2 OPTARG:'' +2 rc:0 var:'?' OPTIND:3 OPTARG:'b' +3 rc:0 var:'c' OPTIND:4 OPTARG:'' +4 rc:1 var:'?' OPTIND:4 OPTARG:'' +5 rc:1 var:'?' OPTIND:4 OPTARG:'' diff --git a/shell/ash_test/ash-getopts/getopt_silent.tests b/shell/ash_test/ash-getopts/getopt_silent.tests new file mode 100755 index 000000000..097d7ba85 --- /dev/null +++ b/shell/ash_test/ash-getopts/getopt_silent.tests @@ -0,0 +1,23 @@ +# Open Group Base Specifications Issue 7: +# """ +# If an unknown option is met, VAR shall be set to "?". In this case, +# if the first character in optstring is ":", OPTARG shall be set +# to the option character found, but no output shall be written +# to standard error; otherwise, the shell variable OPTARG shall be +# unset and a diagnostic message shall be written to standard error." +# ... +# If an option-argument is missing: +# If the first character of optstring is ":", VAR shall be set to ":" +# and OPTARG shall be set to the option character found. +# """ + +echo "*** optstring:':ac' args:-a -b -c" +getopts ":ac" var -a -b -c; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" +getopts ":ac" var -a -b -c; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" +getopts ":ac" var -a -b -c; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" +getopts ":ac" var -a -b -c; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" +# Previous line should result in "rc:1", which is normally treated +# in getopts loops as exit condition. +# Nevertheless, let's verify that calling it yet another time doesn't do +# anything weird: +getopts ":ac" var -a -b -c; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'" |