test: "detect" the test number automagically
Specifying the test number manually is tedious and prone to errors (as recently proven). Since we have all the necessary data to work out the test number, let's do it automagically.
This commit is contained in:
+14
-3
@@ -57,7 +57,7 @@ fi
|
||||
|
||||
# The calling test.sh scripts have TEST_BASE_DIR set via their Makefile, but we don't need them to provide it
|
||||
TEST_BASE_DIR=${TEST_BASE_DIR:-$(realpath "$(dirname "${BASH_SOURCE[0]}")")}
|
||||
TEST_UNITS_DIR="$TEST_BASE_DIR/units"
|
||||
TEST_UNITS_DIR="$(realpath "$TEST_BASE_DIR/units")"
|
||||
SOURCE_DIR=$(realpath "$TEST_BASE_DIR/..")
|
||||
TOOLS_DIR="$SOURCE_DIR/tools"
|
||||
# These variables are used by test scripts
|
||||
@@ -91,6 +91,17 @@ STATEFILE="$STATEDIR/.testdir"
|
||||
IMAGESTATEDIR="$STATEDIR/.."
|
||||
TESTLOG="$STATEDIR/test.log"
|
||||
|
||||
if ! [[ "$TESTNAME" =~ ^TEST\-([0-9]+)\-.+$ ]]; then
|
||||
echo "ERROR: Test name '$TESTNAME' is not in the expected format: TEST-[0-9]+-*" >&2
|
||||
exit 1
|
||||
fi
|
||||
TESTID="${BASH_REMATCH[1]:?}"
|
||||
|
||||
if [[ ! -f "$TEST_UNITS_DIR/testsuite-$TESTID.service" ]]; then
|
||||
echo "ERROR: Test '$TESTNAME' is missing its service file '$TEST_UNITS_DIR/testsuite-$TESTID.service" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASICTOOLS=(
|
||||
awk
|
||||
basename
|
||||
@@ -2444,7 +2455,7 @@ do_test() {
|
||||
case $1 in
|
||||
--run)
|
||||
echo "${testname} RUN: $TEST_DESCRIPTION"
|
||||
test_run "$2"
|
||||
test_run "$TESTID"
|
||||
ret=$?
|
||||
if [ $ret -eq 0 ]; then
|
||||
echo "${testname} RUN: $TEST_DESCRIPTION [OK]"
|
||||
@@ -2475,7 +2486,7 @@ do_test() {
|
||||
test_setup_cleanup </dev/null >>"$TESTLOG" 2>&1 || ret=$?
|
||||
fi
|
||||
if [ $ret -eq 0 ]; then
|
||||
test_run "$2" </dev/null >>"$TESTLOG" 2>&1 || ret=$?
|
||||
test_run "$TESTID" </dev/null >>"$TESTLOG" 2>&1 || ret=$?
|
||||
fi
|
||||
test_cleanup
|
||||
if [ $ret -eq 0 ]; then
|
||||
|
||||
Reference in New Issue
Block a user