]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: run all functions with testcase_ prefix automagically
authorFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 19 May 2023 16:48:07 +0000 (18:48 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Fri, 19 May 2023 18:03:34 +0000 (20:03 +0200)
test/units/testsuite-73.sh

index 39992a844b9b1dc2c4ee8e529a9d1a0679e3466d..8e2bca10052420898acaef8f83186c064d559ba7 100755 (executable)
@@ -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