gdbsupport/selftest: Replace for_each_selftest with an iterator_range

Remove the callback-based selftests::for_each_selftest function and use
an iterator_range instead.

Also use this iterator range in run_tests so all iterations over the
selftests are done in a consistent way.  This will become useful in a
later commit.

Change-Id: I0b3a5349a7987fbcb0071f11c394e353df986583
This commit is contained in:
Lancelot SIX 2022-03-23 15:29:53 +00:00
parent 2aaee75f81
commit c57207c15c
3 changed files with 42 additions and 29 deletions

View file

@ -1181,11 +1181,11 @@ maintenance_selftest_completer (cmd_list_element *cmd,
return;
#if GDB_SELF_TEST
selftests::for_each_selftest ([&tracker, text] (const std::string &name)
for (const auto &test : selftests::all_selftests ())
{
if (startswith (name.c_str (), text))
tracker.add_completion (make_unique_xstrdup (name.c_str ()));
});
if (startswith (test.name.c_str (), text))
tracker.add_completion (make_unique_xstrdup (test.name.c_str ()));
}
#endif
}
@ -1194,9 +1194,8 @@ maintenance_info_selftests (const char *arg, int from_tty)
{
#if GDB_SELF_TEST
gdb_printf ("Registered selftests:\n");
selftests::for_each_selftest ([] (const std::string &name) {
gdb_printf (" - %s\n", name.c_str ());
});
for (const auto &test : selftests::all_selftests ())
gdb_printf (" - %s\n", test.name.c_str ());
#else
gdb_printf (_("\
Selftests have been disabled for this build.\n"));