test: run_subtests_and_exit helper
Replace the "run_subtests; touch /testok" tail with a single wrapper invocation. Report the test itself as skipped if every subtest is skipped. Signed-off-by: Paul Meyer <katexochen0@gmail.com>
This commit is contained in:
@@ -6,6 +6,4 @@ set -o pipefail
|
||||
# shellcheck source=test/units/test-control.sh
|
||||
. "$(dirname "$0")"/test-control.sh
|
||||
|
||||
run_subtests
|
||||
|
||||
touch /testok
|
||||
run_subtests_and_exit
|
||||
|
||||
@@ -6,6 +6,4 @@ set -o pipefail
|
||||
# shellcheck source=test/units/test-control.sh
|
||||
. "$(dirname "$0")"/test-control.sh
|
||||
|
||||
run_subtests
|
||||
|
||||
touch /testok
|
||||
run_subtests_and_exit
|
||||
|
||||
@@ -18,6 +18,4 @@ fi
|
||||
# shellcheck source=test/units/test-control.sh
|
||||
. "$(dirname "$0")"/test-control.sh
|
||||
|
||||
run_subtests
|
||||
|
||||
touch /testok
|
||||
run_subtests_and_exit
|
||||
|
||||
@@ -8,6 +8,4 @@ set -o pipefail
|
||||
|
||||
udevadm settle
|
||||
|
||||
run_subtests
|
||||
|
||||
touch /testok
|
||||
run_subtests_and_exit
|
||||
|
||||
@@ -6,6 +6,4 @@ set -o pipefail
|
||||
# shellcheck source=test/units/test-control.sh
|
||||
. "$(dirname "$0")"/test-control.sh
|
||||
|
||||
run_subtests
|
||||
|
||||
touch /testok
|
||||
run_subtests_and_exit
|
||||
|
||||
@@ -14,6 +14,4 @@ if systemd-detect-virt --quiet --container; then
|
||||
ln -s /dev/null /run/tmpfiles.d/selinux-policy.conf
|
||||
fi
|
||||
|
||||
run_subtests
|
||||
|
||||
touch /testok
|
||||
run_subtests_and_exit
|
||||
|
||||
@@ -7,6 +7,4 @@ set -o pipefail
|
||||
. "$(dirname "$0")"/test-control.sh
|
||||
|
||||
# Note: the signal shenanigans are necessary for the Upholds= tests
|
||||
run_subtests_with_signals SIGUSR1 SIGUSR2 SIGRTMIN+1
|
||||
|
||||
touch /testok
|
||||
run_subtests_with_signals_and_exit SIGUSR1 SIGUSR2 SIGRTMIN+1
|
||||
|
||||
@@ -6,6 +6,4 @@ set -o pipefail
|
||||
# shellcheck source=test/units/test-control.sh
|
||||
. "$(dirname "$0")"/test-control.sh
|
||||
|
||||
run_subtests
|
||||
|
||||
touch /testok
|
||||
run_subtests_and_exit
|
||||
|
||||
@@ -6,6 +6,4 @@ set -o pipefail
|
||||
# shellcheck source=test/units/test-control.sh
|
||||
. "$(dirname "$0")"/test-control.sh
|
||||
|
||||
run_subtests
|
||||
|
||||
touch /testok
|
||||
run_subtests_and_exit
|
||||
|
||||
@@ -6,6 +6,4 @@ set -o pipefail
|
||||
# shellcheck source=test/units/test-control.sh
|
||||
. "$(dirname "$0")"/test-control.sh
|
||||
|
||||
run_subtests
|
||||
|
||||
touch /testok
|
||||
run_subtests_and_exit
|
||||
|
||||
@@ -6,6 +6,4 @@ set -o pipefail
|
||||
# shellcheck source=test/units/test-control.sh
|
||||
. "$(dirname "$0")"/test-control.sh
|
||||
|
||||
run_subtests
|
||||
|
||||
touch /testok
|
||||
run_subtests_and_exit
|
||||
|
||||
@@ -6,6 +6,4 @@ set -o pipefail
|
||||
# shellcheck source=test/units/test-control.sh
|
||||
. "$(dirname "$0")"/test-control.sh
|
||||
|
||||
run_subtests
|
||||
|
||||
touch /testok
|
||||
run_subtests_and_exit
|
||||
|
||||
@@ -172,6 +172,31 @@ run_subtests() {
|
||||
_show_summary
|
||||
}
|
||||
|
||||
_finalize_subtests() {
|
||||
if [[ ${#_PASSED_TESTS[@]} -eq 0 && ${#_SKIPPED_TESTS[@]} -gt 0 ]]; then
|
||||
echo "All subtests skipped" | tee --append /skipped
|
||||
exit "$_SUBTEST_SKIP_RC"
|
||||
fi
|
||||
|
||||
touch /testok
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Run all subtests and finalize the test in one shot: exit 77 (skipped) if every subtest skipped,
|
||||
# otherwise mark success (/testok) and exit. Use this ONLY for tests whose body is just subtests.
|
||||
# Do NOT use it if the parent script has meaningful test content of its own.
|
||||
run_subtests_and_exit() {
|
||||
run_subtests
|
||||
_finalize_subtests
|
||||
}
|
||||
|
||||
# Like run_subtests_and_exit, but propagates the given signals to the subtests (see
|
||||
# run_subtests_with_signals).
|
||||
run_subtests_with_signals_and_exit() {
|
||||
run_subtests_with_signals "$@"
|
||||
_finalize_subtests
|
||||
}
|
||||
|
||||
# Run all test cases (i.e. functions prefixed with testcase_ in the current namespace)
|
||||
run_testcases() {
|
||||
local testcase testcases
|
||||
|
||||
Reference in New Issue
Block a user