summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2014-05-07 21:45:25 +0000
committerjilles <jilles@FreeBSD.org>2014-05-07 21:45:25 +0000
commit3facf3e95417422a832c8620af1785e69c99487d (patch)
tree19f6fd0da8438502d2fa2b93624c7f5c64044fc5
parentefb4e81e7402d0fe763fb4e1816712e7493bd763 (diff)
downloadFreeBSD-src-3facf3e95417422a832c8620af1785e69c99487d.zip
FreeBSD-src-3facf3e95417422a832c8620af1785e69c99487d.tar.gz
sh: Add some tests for normal use of getopts.
-rw-r--r--bin/sh/tests/builtins/Makefile3
-rw-r--r--bin/sh/tests/builtins/getopts3.06
-rw-r--r--bin/sh/tests/builtins/getopts4.010
-rw-r--r--bin/sh/tests/builtins/getopts5.010
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 ]
OpenPOWER on IntegriCloud