"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Christian Weisgerber <naddy@mips.inka.de>
Subject:
Re: storing regress test data outside of /tmp
To:
gameoftrees@openbsd.org
Date:
Fri, 2 Oct 2020 22:17:57 +0200

Download raw body.

Thread
Christian Weisgerber:

> > Sure, we can add quotes. Note though that paths with spaces do not
> > work regardless because getopt(1) does not process such arguments
> > correctly (see the BUGS section in its man page).
> 
> That I can fix.

getopt(1) is woefully obsolete, let's use getopts:

rewrite argument parsing with the POSIX getopts shell built-in

diff 016859fc51b660d7fc95ca5eff449d62c67f8a7f /home/naddy/got
blob - d9826710cfeadefeac8b7e325869f980798d41af
file + regress/cmdline/common.sh
--- regress/cmdline/common.sh
+++ regress/cmdline/common.sh
@@ -200,26 +200,20 @@ test_cleanup()
 
 test_parseargs()
 {
-	args=`getopt qr: $*`
-	if [ $? -ne 0 ]; then
-		echo "Supported options:"
-		echo "  -q: quiet mode"
-		echo "  -r PATH: use PATH as test data root directory"
-		exit 2
-	fi
-	set -- $args
-	while [ $# -ne 0 ]; do
-		case "$1"
-		in
-			-q)
-			   export GOT_TEST_QUIET=1; shift;;
-			-r)
-			   export GOT_TEST_ROOT="$2"; shift; shift;;
-			--)
-			   shift; break;;
+	while getopts qr: flag; do
+		case $flag in
+		q)	export GOT_TEST_QUIET=1
+			;;
+		r)	export GOT_TEST_ROOT=$OPTARG
+			;;
+		?)	echo "Supported options:"
+			echo "  -q: quiet mode"
+			echo "  -r PATH: use PATH as test data root directory"
+			exit 2
+			;;
 		esac
 	done
-}
+} >&2
 
 run_test()
 {
-- 
Christian "naddy" Weisgerber                          naddy@mips.inka.de