tools: parse parameters to "tools/run-nm-test.sh" in mixed order

When "tools/run-nm-test.sh" is called from the build scripts,
it has as first argument "--called-from-make". Then all arguments
must follow in a well defined order, which autotools/meson understand
and follow.

Another main use is however to call "tools/run-nm-test.sh" form the command
line. In that case, we want to have the command line parsing convenient.

Some of the parameters to the script are interpreted by the script, and
some are passed on to the test. The user can use "--" to separate the
parameters:

   ./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -- -p /general/test_strv_cmp

Otherwise, on the first unknown argument "tools/run-nm-test.sh" would
assume all following arguments are for the test. So this worked too:

   ./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p /general/test_strv_cmp

However, if you now want to run the test with valgrind, you need to edit
the command line before the test arguments, like

   ./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -v -p /general/test_strv_cmp

That is inconvenient because I call the script from the shell history and
the cursor is at the end of the line. Instead, assume that all unknown parameters
are for the test (until "--" is encountered).

Now this works:

   ./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p /general/test_strv_cmp -v

Arguably, now also

   ./tools/run-nm-test.sh -m shared/nm-glib-aux/tests/test-shared-general -p -v /general/test_strv_cmp

works, which is a bid odd.
This commit is contained in:
Thomas Haller
2021-01-22 11:48:09 +01:00
parent 9c516a497e
commit 608b5f0515

View File

@@ -90,6 +90,7 @@ if [ "$CALLED_FROM_MAKE" == 1 ]; then
TEST="$1"; shift
NMTST_MAKE_FIRST=0
TEST_ARGV=("$@")
else
if [[ -z "${NMTST_USE_VALGRIND+x}" ]]; then
# by default, disable valgrind checks.
@@ -103,6 +104,7 @@ else
else
NMTST_LIBTOOL=("$NMTST_LIBTOOL" "--mode=execute")
fi
TEST_ARGV=()
unset TEST
while test $# -gt 0; do
case "$1" in
@@ -141,19 +143,22 @@ else
;;
"--")
shift
TEST_ARGV+=("$@")
break
;;
*)
break
if test -z "${TEST+x}"; then
TEST="$1";
shift
fi
TEST_ARGV+=("$1")
shift
;;
esac
done
# we support calling the script directly. In this case,
# only pass the path to the test to run.
if test -z "${TEST+x}"; then
TEST="$1"; shift
fi
if [[ -z "${NMTST_SUPPRESSIONS+x}" ]]; then
NMTST_SUPPRESSIONS="$SCRIPT_PATH/../valgrind.suppressions"
fi
@@ -178,6 +183,8 @@ if [ "$NMTST_SET_DEBUG" == 1 -a -z "${NMTST_DEBUG+x}" ]; then
export NMTST_DEBUG=d
fi
[ -n "$TEST" ] || die "Missing test name. Specify it on the command line."
if _is_true "$NMTST_MAKE_FIRST" 0; then
git_dir="$(readlink -f "$(git rev-parse --show-toplevel)")"
rel_path="$(realpath --relative-to="$git_dir" -m "$TEST" 2>/dev/null)" || die "cannot resolve test-name \"$TEST\". Did you call the script properly?"
@@ -244,7 +251,7 @@ fi
if ! _is_true "$NMTST_USE_VALGRIND" 0; then
export NM_TEST_UNDER_VALGRIND=0
exec "${NMTST_DBUS_RUN_SESSION[@]}" \
"$TEST" "$@"
"$TEST" "${TEST_ARGV[@]}"
die "exec \"$TEST\" failed"
fi
@@ -276,7 +283,7 @@ export NM_TEST_UNDER_VALGRIND=1
--num-callers=100 \
--log-file="$LOGFILE" \
"$TEST" \
"$@"
"${TEST_ARGV[@]}"
RESULT=$?
test -s "$LOGFILE"