]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
test: introduce print_test_result helper function
authorBenjamin Drung <benjamin.drung@canonical.com>
Tue, 21 Oct 2025 16:52:26 +0000 (18:52 +0200)
committerNeal Gompa (ニール・ゴンパ) <ngompa13@gmail.com>
Tue, 28 Oct 2025 23:52:42 +0000 (19:52 -0400)
Introduce a `print_test_result` helper function in preparation for the
following commit.

test/test-functions

index 39104581bf6a0b4f2ce4e84297e7ff98f12b9ab1..a72ba9d06e179026c88cb83d179026c782bbcc1b 100644 (file)
@@ -212,6 +212,22 @@ test_marker_check() {
     return $?
 }
 
+print_test_result() {
+    local ret=${1-1}
+    if [ "$ret" -eq 0 ]; then
+        rm -- test${TEST_RUN_ID:+-$TEST_RUN_ID}.log
+        echo -e "TEST: $TEST_DESCRIPTION " "$COLOR_SUCCESS" "[OK]" "$COLOR_NORMAL"
+    else
+        echo -e "TEST: $TEST_DESCRIPTION " "$COLOR_FAILURE" "[FAILED]" "$COLOR_NORMAL"
+        if [ "${V-}" == "2" ]; then
+            tail -c 1048576 "$(pwd)/server${TEST_RUN_ID:+-$TEST_RUN_ID}.log" "$(pwd)/test${TEST_RUN_ID:+-$TEST_RUN_ID}.log"
+            echo -e "TEST: $TEST_DESCRIPTION " "$COLOR_FAILURE" "[FAILED]" "$COLOR_NORMAL"
+        else
+            echo "see $(pwd)/test${TEST_RUN_ID:+-$TEST_RUN_ID}.log"
+        fi
+    fi
+}
+
 while (($# > 0)); do
     case $1 in
         --run)
@@ -267,18 +283,7 @@ while (($# > 0)); do
             fi
             ret=$?
             set +o pipefail
-            if [ $ret -eq 0 ]; then
-                rm -- test${TEST_RUN_ID:+-$TEST_RUN_ID}.log
-                echo -e "TEST: $TEST_DESCRIPTION " "$COLOR_SUCCESS" "[OK]" "$COLOR_NORMAL"
-            else
-                echo -e "TEST: $TEST_DESCRIPTION " "$COLOR_FAILURE" "[FAILED]" "$COLOR_NORMAL"
-                if [ "${V-}" == "2" ]; then
-                    tail -c 1048576 "$(pwd)/server${TEST_RUN_ID:+-$TEST_RUN_ID}.log" "$(pwd)/test${TEST_RUN_ID:+-$TEST_RUN_ID}.log"
-                    echo -e "TEST: $TEST_DESCRIPTION " "$COLOR_FAILURE" "[FAILED]" "$COLOR_NORMAL"
-                else
-                    echo "see $(pwd)/test${TEST_RUN_ID:+-$TEST_RUN_ID}.log"
-                fi
-            fi
+            print_test_result "$ret"
             exit $ret
             ;;
         *) break ;;