From 305aa43815bb66e4c512d0f0900a0727940dfecb Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Fri, 19 May 2023 18:48:07 +0200 Subject: [PATCH] tests: run all functions with testcase_ prefix automagically --- test/units/testsuite-73.sh | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/test/units/testsuite-73.sh b/test/units/testsuite-73.sh index 39992a844b9..8e2bca10052 100755 --- a/test/units/testsuite-73.sh +++ b/test/units/testsuite-73.sh @@ -51,7 +51,7 @@ restore_locale() { fi } -test_locale() { +testcase_locale() { local i output if [[ -f /etc/locale.conf ]]; then @@ -222,7 +222,7 @@ wait_vconsole_setup() { return 1 } -test_vc_keymap() { +testcase_vc_keymap() { local i output vc if [[ -z "$(localectl list-keymaps)" ]]; then @@ -292,7 +292,7 @@ test_vc_keymap() { assert_in "VC Keymap: .unset." "$(localectl)" } -test_x11_keymap() { +testcase_x11_keymap() { local output if [[ -z "$(localectl list-x11-keymap-layouts)" ]]; then @@ -431,7 +431,7 @@ XKBMODEL=pc105+inet" assert_not_in "X11 Options:" "$output" } -test_convert() { +testcase_convert() { if [[ -z "$(localectl list-keymaps)" ]]; then echo "No vconsole keymap installed, skipping test." return @@ -552,7 +552,7 @@ test_convert() { assert_not_in "X11 Options:" "$output" } -test_validate() { +testcase_validate() { if [[ -z "$(localectl list-keymaps)" ]]; then echo "No vconsole keymap installed, skipping test." return @@ -656,11 +656,18 @@ EOF export SYSTEMD_KBD_MODEL_MAP=/usr/lib/systemd/tests/testdata/test-keymap-util/kbd-model-map enable_debug -test_locale -test_vc_keymap -test_x11_keymap -test_convert -test_validate + +# Create a list of all functions prefixed with testcase_ +mapfile -t TESTCASES < <(declare -F | awk '$3 ~ /^testcase_/ {print $3;}') + +if [[ "${#TESTCASES[@]}" -eq 0 ]]; then + echo >&2 "No test cases found, this is most likely an error" + exit 1 +fi + +for testcase in "${TESTCASES[@]}"; do + "$testcase" +done touch /testok rm /failed