diff options
-rw-r--r-- | gdb/maint.c | 11 | ||||
-rw-r--r-- | gdb/testsuite/gdb.gdb/unittest.exp | 15 | ||||
-rw-r--r-- | gdbsupport/selftest.h | 4 |
3 files changed, 27 insertions, 3 deletions
diff --git a/gdb/maint.c b/gdb/maint.c index 4e75e47..85fa18c 100644 --- a/gdb/maint.c +++ b/gdb/maint.c @@ -1176,8 +1176,15 @@ maintenance_selftest_completer (cmd_list_element *cmd, { auto grp = make_maintenance_selftest_option_group (nullptr); - gdb::option::complete_options - (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp); + if (gdb::option::complete_options + (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp)) + return; + + selftests::for_each_selftest ([&tracker, text] (const std::string &name) + { + if (startswith (name.c_str (), text)) + tracker.add_completion (make_unique_xstrdup (name.c_str ())); + }); } static void diff --git a/gdb/testsuite/gdb.gdb/unittest.exp b/gdb/testsuite/gdb.gdb/unittest.exp index 670205f..0ddd206 100644 --- a/gdb/testsuite/gdb.gdb/unittest.exp +++ b/gdb/testsuite/gdb.gdb/unittest.exp @@ -20,6 +20,8 @@ if [gdb_debug_enabled] { return 0 } +load_lib completion-support.exp + set do_xml_test [expr ![gdb_skip_xml_test]] standard_testfile @@ -59,6 +61,17 @@ proc run_selftests { binfile } { } } +# Test completion of command "maintenance selftest". + +proc_with_prefix test_completion {} { + clean_restart + test_gdb_complete_tab_multiple "maintenance selftest string_v" "" \ + {string_vappendf string_view string_vprintf} + test_gdb_complete_tab_unique "maintenance selftest string_vie" "maintenance selftest string_view" " " + test_gdb_complete_tab_unique "maintenance selftest -ver" "maintenance selftest -verbose" " " + test_gdb_complete_tab_none "maintenance selftest name_that_does_not_exist" +} + with_test_prefix "no executable loaded" { run_selftests "" } @@ -67,6 +80,8 @@ with_test_prefix "executable loaded" { run_selftests ${binfile} } +test_completion + if { ![is_remote host] && $do_xml_test } { gdb_test "maintenance check xml-descriptions ${srcdir}/../features" \ "Tested $decimal XML files, 0 failed" \ diff --git a/gdbsupport/selftest.h b/gdbsupport/selftest.h index 2326eba..7275126 100644 --- a/gdbsupport/selftest.h +++ b/gdbsupport/selftest.h @@ -20,6 +20,7 @@ #define COMMON_SELFTEST_H #include "gdbsupport/array-view.h" +#include "gdbsupport/function-view.h" /* A test is just a function that does some checks and throws an exception if something has gone wrong. */ @@ -48,7 +49,8 @@ extern void run_tests (gdb::array_view<const char *const> filters, /* Reset GDB or GDBserver's internal state. */ extern void reset (); -typedef void for_each_selftest_ftype (const std::string &name); +using for_each_selftest_ftype + = gdb::function_view<void(const std::string &name)>; /* Call FUNC for each registered selftest. */ |