From 37900a62656a2a027d4a9c4ddf48efa6a7229e32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 27 Aug 2026 13:13:15 +0200 Subject: [PATCH] tests: convert manual test binaries to VERB_COMMAND and --introspect-cli The last five hand-written help() functions are replaced by COMMAND() descriptions: test-homectl-prompts, test-libudev, test-modem-manager-mock, test-chase-manual, and test-journal-append (which open-coded the help inside the option parsing loop). None of the binaries are installed, so no man pages are referenced and they are not added to the introspection smoke test. --- src/home/test-homectl-prompts.c | 38 +++++-------------- .../sd-journal/test-journal-append.c | 32 +++++++--------- src/libudev/test-libudev.c | 29 ++++++-------- src/network/test-modem-manager-mock.c | 27 +++++-------- src/test/test-chase-manual.c | 32 ++++++---------- 5 files changed, 56 insertions(+), 102 deletions(-) diff --git a/src/home/test-homectl-prompts.c b/src/home/test-homectl-prompts.c index 5429eaaa5e..8e65c864e0 100644 --- a/src/home/test-homectl-prompts.c +++ b/src/home/test-homectl-prompts.c @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-json.h" + #include "alloc-util.h" -#include "format-table.h" -#include "help-util.h" #include "homectl-prompts.h" #include "main-func.h" #include "options.h" @@ -11,31 +11,10 @@ #include "tests.h" #include "verbs.h" -static int help(void) { - _cleanup_(table_unrefp) Table *options = NULL, *verbs = NULL; - int r; - - r = option_parser_get_help_table(&options); - if (r < 0) - return r; - - r = verbs_get_help_table(&verbs); - if (r < 0) - return r; - - (void) table_sync_column_widths(0, options, verbs); - - help_cmdline("[OPTIONS...] VERB [USERNAME]"); - help_abstract("Exercise homectl prompt functions in isolation."); - - help_section("Verbs"); - r = table_print_or_warn(verbs); - if (r < 0) - return r; - - help_section("Options"); - return table_print_or_warn(options); -} +COMMAND( + "test-homectl-prompts\0", + "Exercise homectl prompt functions in isolation.", +); VERB(verb_groups, "groups", "[USER]\0", VERB_ANY, 2, 0, "Select groups"); static int verb_groups(int argc, char *argv[], uintptr_t _data, void *userdata) { @@ -83,7 +62,10 @@ static int parse_argv(int argc, char **argv, char ***remaining_args) { switch (c) { OPTION_COMMON_HELP: - return help(); + return command_print_help(); + + OPTION_COMMON_INTROSPECT_CLI: + return introspect_cli(SD_JSON_FORMAT_OFF); } *remaining_args = option_parser_get_args(&opts); diff --git a/src/libsystemd/sd-journal/test-journal-append.c b/src/libsystemd/sd-journal/test-journal-append.c index 1905c570f2..abdb06b9ef 100644 --- a/src/libsystemd/sd-journal/test-journal-append.c +++ b/src/libsystemd/sd-journal/test-journal-append.c @@ -4,8 +4,9 @@ #include #include +#include "sd-json.h" + #include "chattr-util.h" -#include "format-table.h" #include "iovec-util.h" #include "journal-file-util.h" #include "log.h" @@ -18,6 +19,12 @@ #include "tests.h" #include "time-util.h" #include "tmpfile-util.h" +#include "verbs.h" + +COMMAND( + "test-journal-append\0", + "Append entries to journal files and check corruption handling.", +); static int journal_append_message(JournalFile *mj, const char *message) { struct iovec iovec; @@ -157,24 +164,8 @@ static int run(int argc, char *argv[]) { FOREACH_OPTION_OR_RETURN(c, &opts) switch (c) { - OPTION_COMMON_HELP: { - _cleanup_(table_unrefp) Table *options = NULL; - - r = option_parser_get_help_table(&options); - if (r < 0) - return r; - - printf("Syntax:\n" - " %s [OPTION...]\n" - "\nOptions:\n", - program_invocation_short_name); - - r = table_print_or_warn(options); - if (r < 0) - return r; - - return 0; - } + OPTION_COMMON_HELP: + return command_print_help(); OPTION_LONG("start-offset", "OFFSET", "Offset at which to start corrupting the journal " @@ -221,6 +212,9 @@ static int run(int argc, char *argv[]) { run_one = true; break; + + OPTION_COMMON_INTROSPECT_CLI: + return introspect_cli(SD_JSON_FORMAT_OFF); } if (run_one) diff --git a/src/libudev/test-libudev.c b/src/libudev/test-libudev.c index 06feb1ffbc..2c09e59d62 100644 --- a/src/libudev/test-libudev.c +++ b/src/libudev/test-libudev.c @@ -3,9 +3,10 @@ #include #include +#include "sd-json.h" + #include "devnum-util.h" #include "fd-util.h" -#include "format-table.h" #include "libudev-list-internal.h" #include "log.h" #include "main-func.h" @@ -13,6 +14,7 @@ #include "options.h" #include "string-util.h" #include "tests.h" +#include "verbs.h" #include "version.h" static bool arg_monitor = false; @@ -405,22 +407,10 @@ static void test_list(void) { assert_se(!udev_list_entry_get_by_name(e, "ccc")); } -static int help(void) { - _cleanup_(table_unrefp) Table *options = NULL; - int r; - - r = option_parser_get_help_table(&options); - if (r < 0) - return r; - - printf("%s [OPTIONS...]\n\n", program_invocation_short_name); - - r = table_print_or_warn(options); - if (r < 0) - return r; - - return 0; -} +COMMAND( + "test-libudev\0", + "Test libudev functions.", +); static int parse_args(int argc, char *argv[], const char **syspath, const char **subsystem) { assert(argc >= 0); @@ -434,7 +424,7 @@ static int parse_args(int argc, char *argv[], const char **syspath, const char * switch (c) { OPTION_COMMON_HELP: - return help(); + return command_print_help(); OPTION('V', "version", NULL, "Show package version"): printf("%s\n", GIT_VERSION); @@ -455,6 +445,9 @@ static int parse_args(int argc, char *argv[], const char **syspath, const char * OPTION('m', "monitor", NULL, "Run monitor test"): arg_monitor = true; break; + + OPTION_COMMON_INTROSPECT_CLI: + return introspect_cli(SD_JSON_FORMAT_OFF); } return 1; diff --git a/src/network/test-modem-manager-mock.c b/src/network/test-modem-manager-mock.c index c38a7a43cc..820e22c640 100644 --- a/src/network/test-modem-manager-mock.c +++ b/src/network/test-modem-manager-mock.c @@ -13,16 +13,16 @@ #include "sd-bus.h" #include "sd-daemon.h" #include "sd-event.h" +#include "sd-json.h" #include "alloc-util.h" #include "build.h" -#include "format-table.h" -#include "help-util.h" #include "log.h" #include "main-func.h" #include "options.h" #include "parse-util.h" #include "string-util.h" +#include "verbs.h" static char *arg_ifname = NULL; static char *arg_ipv4_address = NULL; @@ -364,20 +364,10 @@ static int filter_handler(sd_bus_message *m, void *userdata, sd_bus_error *error return 0; } -static int help(void) { - _cleanup_(table_unrefp) Table *options = NULL; - int r; - - r = option_parser_get_help_table(&options); - if (r < 0) - return r; - - help_cmdline("[OPTIONS...]"); - help_abstract("Mock ModemManager D-Bus service for testing."); - - help_section("Options"); - return table_print_or_warn(options); -} +COMMAND( + "test-modem-manager-mock\0", + "Mock ModemManager D-Bus service for testing.", +); static int parse_argv(int argc, char *argv[]) { int r; @@ -391,7 +381,7 @@ static int parse_argv(int argc, char *argv[]) { switch (c) { OPTION_COMMON_HELP: - return help(); + return command_print_help(); OPTION_COMMON_VERSION: return version(); @@ -432,6 +422,9 @@ static int parse_argv(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to parse IPv6 prefix length: %m"); break; + + OPTION_COMMON_INTROSPECT_CLI: + return introspect_cli(SD_JSON_FORMAT_OFF); } if (!arg_ifname) diff --git a/src/test/test-chase-manual.c b/src/test/test-chase-manual.c index 410522ceb1..e3d83a6026 100644 --- a/src/test/test-chase-manual.c +++ b/src/test/test-chase-manual.c @@ -1,36 +1,25 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-json.h" + #include "chase.h" #include "fd-util.h" -#include "format-table.h" #include "log.h" #include "main-func.h" #include "options.h" #include "strv.h" #include "tests.h" +#include "verbs.h" static const char *arg_root = NULL; static int arg_flags = 0; static bool arg_open = false; -static int help(void) { - _cleanup_(table_unrefp) Table *options = NULL; - int r; - - r = option_parser_get_help_table(&options); - if (r < 0) - return r; - - printf("%s [OPTIONS...] path...\n" - "\nExercise chase() function on specified paths.\n\n", - program_invocation_short_name); - - r = table_print_or_warn(options); - if (r < 0) - return r; - - return 0; -} +COMMAND( + "test-chase-manual\0", + "Exercise chase() function on specified paths.", + .argspec = "PATH…\0", +); static int parse_argv(int argc, char *argv[], char ***ret_args) { assert(argc >= 0); @@ -43,7 +32,7 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) { switch (c) { OPTION_COMMON_HELP: - return help(); + return command_print_help(); OPTION_LONG("root", "PATH", "Operate below specified root directory"): arg_root = opts.arg; @@ -64,6 +53,9 @@ static int parse_argv(int argc, char *argv[], char ***ret_args) { OPTION_LONG_DATA("warn", NULL, CHASE_WARN, "Emit a warning on error"): arg_flags |= opts.opt->data; break; + + OPTION_COMMON_INTROSPECT_CLI: + return introspect_cli(SD_JSON_FORMAT_OFF); } *ret_args = option_parser_get_args(&opts);