aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport/selftest.cc
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2021-09-23 13:09:48 -0600
committerTom Tromey <tromey@adacore.com>2021-10-19 12:58:50 -0600
commitd7c68312bdeca52e242326e5cf155e0aa63268bb (patch)
tree8daa0e71c0de29b9bee9f0a8376dc431b65af861 /gdbsupport/selftest.cc
parent4a2f674a688df474639066922f4ce70ce97b30d2 (diff)
downloadfsf-binutils-gdb-d7c68312bdeca52e242326e5cf155e0aa63268bb.zip
fsf-binutils-gdb-d7c68312bdeca52e242326e5cf155e0aa63268bb.tar.gz
fsf-binutils-gdb-d7c68312bdeca52e242326e5cf155e0aa63268bb.tar.bz2
Always use std::function for self-tests
Now that there is a register_test variant that accepts std::function, it seems to me that the 'selftest' struct and accompanying code is obsolete -- simply always using std::function is simpler. This patch implements this idea.
Diffstat (limited to 'gdbsupport/selftest.cc')
-rw-r--r--gdbsupport/selftest.cc37
1 files changed, 6 insertions, 31 deletions
diff --git a/gdbsupport/selftest.cc b/gdbsupport/selftest.cc
index 589ef1e..d650638 100644
--- a/gdbsupport/selftest.cc
+++ b/gdbsupport/selftest.cc
@@ -29,43 +29,18 @@ namespace selftests
the order of tests stable and easily looking up whether a test name
exists. */
-static std::map<std::string, std::unique_ptr<selftest>> tests;
+static std::map<std::string, std::function<void(void)>> tests;
/* See selftest.h. */
void
-register_test (const std::string &name, selftest *test)
+register_test (const std::string &name,
+ std::function<void(void)> function)
{
/* Check that no test with this name already exist. */
gdb_assert (tests.find (name) == tests.end ());
- tests[name] = std::unique_ptr<selftest> (test);
-}
-
-/* A selftest that calls the test function without arguments. */
-
-struct lambda_selftest : public selftest
-{
- lambda_selftest (std::function<void(void)> function_)
- {
- function = function_;
- }
-
- void operator() () const override
- {
- function ();
- }
-
- std::function<void(void)> function;
-};
-
-/* See selftest.h. */
-
-void
-register_test (const std::string &name,
- std::function<void(void)> function)
-{
- register_test (name, new lambda_selftest (function));
+ tests[name] = function;
}
/* See selftest.h. */
@@ -91,7 +66,7 @@ run_tests (gdb::array_view<const char *const> filters, bool verbose)
for (const auto &pair : tests)
{
const std::string &name = pair.first;
- const std::unique_ptr<selftest> &test = pair.second;
+ const auto &test = pair.second;
bool run = false;
if (filters.empty ())
@@ -112,7 +87,7 @@ run_tests (gdb::array_view<const char *const> filters, bool verbose)
{
debug_printf (_("Running selftest %s.\n"), name.c_str ());
++ran;
- (*test) ();
+ test ();
}
catch (const gdb_exception_error &ex)
{