diff options
author | jilles <jilles@FreeBSD.org> | 2014-05-07 21:45:25 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2014-05-07 21:45:25 +0000 |
commit | 3facf3e95417422a832c8620af1785e69c99487d (patch) | |
tree | 19f6fd0da8438502d2fa2b93624c7f5c64044fc5 /bin | |
parent | efb4e81e7402d0fe763fb4e1816712e7493bd763 (diff) | |
download | FreeBSD-src-3facf3e95417422a832c8620af1785e69c99487d.zip FreeBSD-src-3facf3e95417422a832c8620af1785e69c99487d.tar.gz |
sh: Add some tests for normal use of getopts.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/sh/tests/builtins/Makefile | 3 | ||||
-rw-r--r-- | bin/sh/tests/builtins/getopts3.0 | 6 | ||||
-rw-r--r-- | bin/sh/tests/builtins/getopts4.0 | 10 | ||||
-rw-r--r-- | bin/sh/tests/builtins/getopts5.0 | 10 |
4 files changed, 29 insertions, 0 deletions
diff --git a/bin/sh/tests/builtins/Makefile b/bin/sh/tests/builtins/Makefile index 945a14d..c0b21dc 100644 --- a/bin/sh/tests/builtins/Makefile +++ b/bin/sh/tests/builtins/Makefile @@ -80,6 +80,9 @@ FILES+= for2.0 FILES+= for3.0 FILES+= getopts1.0 getopts1.0.stdout FILES+= getopts2.0 getopts2.0.stdout +FILES+= getopts3.0 +FILES+= getopts4.0 +FILES+= getopts5.0 FILES+= hash1.0 hash1.0.stdout FILES+= hash2.0 hash2.0.stdout FILES+= hash3.0 hash3.0.stdout diff --git a/bin/sh/tests/builtins/getopts3.0 b/bin/sh/tests/builtins/getopts3.0 new file mode 100644 index 0000000..d02469b --- /dev/null +++ b/bin/sh/tests/builtins/getopts3.0 @@ -0,0 +1,6 @@ +# $FreeBSD$ + +shift $# +getopts x opt +r=$? +[ "$r" != 0 ] && [ "$OPTIND" = 1 ] diff --git a/bin/sh/tests/builtins/getopts4.0 b/bin/sh/tests/builtins/getopts4.0 new file mode 100644 index 0000000..61d5c2b --- /dev/null +++ b/bin/sh/tests/builtins/getopts4.0 @@ -0,0 +1,10 @@ +# $FreeBSD$ + +set -- -x +opt=not +getopts x opt +r1=$? OPTIND1=$OPTIND opt1=$opt +getopts x opt +r2=$? OPTIND2=$OPTIND +[ "$r1" = 0 ] && [ "$OPTIND1" = 2 ] && [ "$opt1" = x ] && [ "$r2" != 0 ] && + [ "$OPTIND2" = 2 ] diff --git a/bin/sh/tests/builtins/getopts5.0 b/bin/sh/tests/builtins/getopts5.0 new file mode 100644 index 0000000..666ee76 --- /dev/null +++ b/bin/sh/tests/builtins/getopts5.0 @@ -0,0 +1,10 @@ +# $FreeBSD$ + +set -- -x arg +opt=not +getopts x opt +r1=$? OPTIND1=$OPTIND opt1=$opt +getopts x opt +r2=$? OPTIND2=$OPTIND +[ "$r1" = 0 ] && [ "$OPTIND1" = 2 ] && [ "$opt1" = x ] && [ "$r2" != 0 ] && + [ "$OPTIND2" = 2 ] |