sh: Add some tests for normal use of getopts.

This commit is contained in:
Jilles Tjoelker 2014-05-07 21:45:25 +00:00
parent 97a9b0b123
commit 5699ef2588
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=265616
4 changed files with 29 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,6 @@
# $FreeBSD$
shift $#
getopts x opt
r=$?
[ "$r" != 0 ] && [ "$OPTIND" = 1 ]

View File

@ -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 ]

View File

@ -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 ]