REGTEST: script: Process script arguments before everything else

The help message is now in the function _help(). It exits the script with the
status 0 to not run regtests when the help is displayed. So it is also handy to
process script arguments before anything else. This avoids to start printing
messages related to regtests execution when it is not appropriate. Another
change, when it detects an invalid argument, the script exits with an error.
This commit is contained in:
Christopher Faulet 2018-12-18 22:41:20 +01:00
parent fdafd9a3f8
commit 8d67cf8187

View File

@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
if [ "$1" = "--help" ]; then _help()
{
cat << EOF cat << EOF
### run-regtests.sh ### ### run-regtests.sh ###
Running run-regtests.sh --help shows this information about how to use it Running run-regtests.sh --help shows this information about how to use it
@ -44,8 +45,8 @@ if [ "$1" = "--help" ]; then
export HAPROXY_PROGRAM=/usr/local/sbin/haproxy export HAPROXY_PROGRAM=/usr/local/sbin/haproxy
export VARNISHTEST_PROGRAM=/usr/local/bin/varnishtest export VARNISHTEST_PROGRAM=/usr/local/bin/varnishtest
EOF EOF
return exit 0
fi }
add_range_to_test_list() add_range_to_test_list()
{ {
@ -206,9 +207,6 @@ _findtests() {
} }
_process() { _process() {
jobcount=""
verbose="-q"
while [ ${#} -gt 0 ]; do while [ ${#} -gt 0 ]; do
if _startswith "$1" "-"; then if _startswith "$1" "-"; then
case "${1}" in case "${1}" in
@ -227,32 +225,38 @@ _process() {
LEVEL="$2" LEVEL="$2"
shift shift
;; ;;
--help)
_help
;;
*) *)
echo "Unknown parameter : $1" echo "Unknown parameter : $1"
return 1 exit 1
;; ;;
esac esac
else else
_findtests "$1" REGTESTS="${REGTESTS} $1"
pathwasset=1
fi fi
shift 1 shift 1
done done
if [ -z $pathwasset ]; then
# no path was given, find all tests under current path
_findtests ./
fi
} }
_version() { _version() {
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\012", $1,$2,$3,$4); }'; echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\012", $1,$2,$3,$4); }';
} }
echo ""
echo "########################## Preparing to run tests ##########################"
HAPROXY_PROGRAM="${HAPROXY_PROGRAM:-${PWD}/haproxy}" HAPROXY_PROGRAM="${HAPROXY_PROGRAM:-${PWD}/haproxy}"
VARNISHTEST_PROGRAM="${VARNISHTEST_PROGRAM:-varnishtest}" VARNISHTEST_PROGRAM="${VARNISHTEST_PROGRAM:-varnishtest}"
REGTESTS=""
jobcount=""
verbose="-q"
testlist=""
_process "$@";
echo ""
echo "########################## Preparing to run tests ##########################"
preparefailed= preparefailed=
if ! [ -x "$(command -v $HAPROXY_PROGRAM)" ]; then if ! [ -x "$(command -v $HAPROXY_PROGRAM)" ]; then
@ -350,11 +354,13 @@ echo "Target : $TARGET"
echo "Options : $OPTIONS" echo "Options : $OPTIONS"
echo "########################## Gathering tests to run ##########################" echo "########################## Gathering tests to run ##########################"
if [ -z "$REGTESTS" ]; then
testlist="" _findtests ./
pathwasset= else
for t in $REGTESTS; do
_process "$@"; _findtests $t
done
fi
echo "########################## Starting varnishtest ##########################" echo "########################## Starting varnishtest ##########################"
echo "Testing with haproxy version: $HAPROXY_VERSION" echo "Testing with haproxy version: $HAPROXY_VERSION"