gitlab-ci: assert that NM_TEST_SELECT_RUN is valid in "run-test.sh"

The script now fails, if the user passes an invalid "$NM_TEST_SELECT_RUN"
or if the script references an invalid name.
This commit is contained in:
Thomas Haller 2023-04-12 20:06:39 +02:00
parent 513c7f0280
commit 8da0f9f79d
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -2,6 +2,11 @@
set -ex
die() {
printf "%s\n" "$*" >&2
exit 1
}
export PAGER=cat
export OMP_NUM_THREADS=1
@ -44,9 +49,47 @@ meson --version
# to run that test as part of the build. Disable it.
export NMTST_SKIP_CHECK_GITLAB_CI=1
# Assert that "$1" is one of the valid values for NM_TEST_SELECT_RUN. die() otherwise.
check_run_assert() {
{ set +x; } 2>/dev/null
local run="$1"
local a
# These are the supported $NM_TEST_SELECT_RUN values.
local _CHECK_RUN_LIST=(
1
2
3
4
5
6
7
8
9
10
)
if [ "$run" = '' ] ; then
set -x
return 0
fi
for a in "${_CHECK_RUN_LIST[@]}" ; do
if [ "$a" = "$run" ] ; then
set -x
return 0
fi
done
die "invalid NM_TEST_SELECT_RUN value \"$1\""
}
check_run_assert "$NM_TEST_SELECT_RUN"
check_run() {
local test_no="$1"
check_run_assert "$test_no"
# Usually, we run the build several times. However, for testing
# the build script manually, it can be useful to explicitly select
# one step to run. For example, if step 3 is known to fail, you
@ -55,7 +98,6 @@ check_run() {
test -z "$NM_TEST_SELECT_RUN" -o "$NM_TEST_SELECT_RUN" = "$test_no"
}
check_run_clean() {
if ! check_run "$1" ; then
return 1