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.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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)
|
||||
|
||||
+11
-18
@@ -3,9 +3,10 @@
|
||||
#include <sys/epoll.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user