]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: don't leak TESTFUNCS count into run_test_table() exit code
authorPaul Meyer <katexochen0@gmail.com>
Sun, 7 Jun 2026 12:01:05 +0000 (14:01 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sun, 7 Jun 2026 18:23:48 +0000 (19:23 +0100)
strv_split_full() returns the number of parsed entries, which was
assigned to r, the variable that also holds the run's exit status.
With TESTFUNCS set, a passing run of only void tests then exited with
the entry count (e.g. 1) instead of EXIT_SUCCESS. Use a separate
variable for the split result.

Before:
$ env TESTFUNCS=test_copy_tree meson test -C build -v test-copy
1/1 test - systemd:test-copy FAIL            0.01s   exit status 1

$ env TESTFUNCS=test_copy_tree:test_copy_file_fd meson test -C build -v test-copy
1/1 test - systemd:test-copy FAIL            0.01s   exit status 2

Now:
$ env TESTFUNCS=test_copy_tree:test_copy_file_fd meson test -C build -v test-copy
1/1 test - systemd:test-copy OK              0.01s

Co-developed-by: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Paul Meyer <katexochen0@gmail.com>
src/shared/tests.c

index 176c7fb13f3737c123547cf14b08d820cbeff636..1dc54318fa2f555446833905e99222da8f4d1133 100644 (file)
@@ -386,9 +386,9 @@ int run_test_table(const TestFunc *start, const TestFunc *end) {
 
         const char *e = getenv("TESTFUNCS");
         if (e) {
-                r = strv_split_full(&tests, e, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to parse $TESTFUNCS: %m");
+                int n = strv_split_full(&tests, e, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
+                if (n < 0)
+                        return log_error_errno(n, "Failed to parse $TESTFUNCS: %m");
         }
 
         for (const TestFunc *t = start; t + 1 <= end; t++) {