mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-18 12:24:38 +08:00
gdb: add selftest name completion
After the previous commit, it is easy to add completion for selftest names. Again, this is not particularly high value, but I rarely touched completion, so it served as a simple example to get some practice. Change the for_each_selftest_ftype parameter to gdb::function_view, so that we can pass a lambda that captures things. Change-Id: I87cac299ddca9ca7eb0ffab78342e850a98d954c
This commit is contained in:
parent
8c2999954b
commit
c0492bea7c
11
gdb/maint.c
11
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
|
||||
|
@ -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" \
|
||||
|
@ -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. */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user