diff options
author | dana <dana@dana.is> | 2017-12-01 03:39:00 -0600 |
---|---|---|
committer | Peter Stephenson <pws@zsh.org> | 2017-12-01 09:51:17 +0000 |
commit | 2bc02b4f9800197afcd512e9907d2592ffc1a0df (patch) | |
tree | 7793bbe4fcae3aab8b22ecaa2ca2fe5d27fea337 | |
parent | 755f8571d49a07e85dc77d01f6ccb3944a3abdcb (diff) | |
download | zsh-2bc02b4f9800197afcd512e9907d2592ffc1a0df.tar.gz zsh-2bc02b4f9800197afcd512e9907d2592ffc1a0df.tar.xz zsh-2bc02b4f9800197afcd512e9907d2592ffc1a0df.zip |
42065: new getopts tests
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | Test/B10getopts.ztst | 81 |
2 files changed, 83 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog index e3aaac737..bd67d1dc9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2017-12-01 Peter Stephenson <p.stephenson@samsung.com> + * data: 42065: Test/B10getopts.ztst: new getopts tests. + * dana: 42063: Src/builtin.c: getopts errors now report "+" if appropriate for option. diff --git a/Test/B10getopts.ztst b/Test/B10getopts.ztst new file mode 100644 index 000000000..7eba5a4b1 --- /dev/null +++ b/Test/B10getopts.ztst @@ -0,0 +1,81 @@ +# Test the getopts builtin. + +%prep + + test_getopts() { + local OPTARG OPTIND opt + local -a res + while getopts abc: opt 2>&1; do + [[ $opt == [?:] ]] || res+=( $opt ) + done + (( $#res )) && print -r -- $res + return $(( $#res ? 0 : 1 )) + } + +%test + + test_getopts +1:no arguments + + test_getopts foo +1:one operand + + test_getopts -a +0:one option +>a + + test_getopts -a foo +0:one option, one operand +>a + + test_getopts -a foo -b +0:one option, two operands, leading hyphen +>a + + test_getopts -ab +0:two options, single argument +>a b + + test_getopts -a -b +0:two options, separate arguments +>a b + + test_getopts -a -b +a +0:three options, + variant +>a b +a + + test_getopts -cx +0:one option with value, single argument +>c + + test_getopts +cx +0:one option with value, single argument, + variant +>+c + + test_getopts -c x +0:one option with value, separate arguments +>c + + test_getopts -acx +0:two options, one with value, single argument +>a c + + test_getopts -ac x +0:two options, one with value, separate arguments +>a c + + test_getopts -c +1:one option missing value +>test_getopts:3: argument expected after -c option + + test_getopts +c +1:one option missing value, + variant +>test_getopts:3: argument expected after +c option + + test_getopts -x +1:one illegal option +>test_getopts:3: bad option: -x + + test_getopts +x +1:one illegal option, + variant +>test_getopts:3: bad option: +x |