diff --git a/gdbsupport/selftest.cc b/gdbsupport/selftest.cc index 589ef1e6797..d65063820ac 100644 --- a/gdbsupport/selftest.cc +++ b/gdbsupport/selftest.cc @@ -29,35 +29,7 @@ namespace selftests the order of tests stable and easily looking up whether a test name exists. */ -static std::map> tests; - -/* See selftest.h. */ - -void -register_test (const std::string &name, selftest *test) -{ - /* Check that no test with this name already exist. */ - gdb_assert (tests.find (name) == tests.end ()); - - tests[name] = std::unique_ptr (test); -} - -/* A selftest that calls the test function without arguments. */ - -struct lambda_selftest : public selftest -{ - lambda_selftest (std::function function_) - { - function = function_; - } - - void operator() () const override - { - function (); - } - - std::function function; -}; +static std::map> tests; /* See selftest.h. */ @@ -65,7 +37,10 @@ void register_test (const std::string &name, std::function function) { - register_test (name, new lambda_selftest (function)); + /* Check that no test with this name already exist. */ + gdb_assert (tests.find (name) == tests.end ()); + + tests[name] = function; } /* See selftest.h. */ @@ -91,7 +66,7 @@ run_tests (gdb::array_view filters, bool verbose) for (const auto &pair : tests) { const std::string &name = pair.first; - const std::unique_ptr &test = pair.second; + const auto &test = pair.second; bool run = false; if (filters.empty ()) @@ -112,7 +87,7 @@ run_tests (gdb::array_view filters, bool verbose) { debug_printf (_("Running selftest %s.\n"), name.c_str ()); ++ran; - (*test) (); + test (); } catch (const gdb_exception_error &ex) { diff --git a/gdbsupport/selftest.h b/gdbsupport/selftest.h index d76fc4b37d3..2326ebad495 100644 --- a/gdbsupport/selftest.h +++ b/gdbsupport/selftest.h @@ -24,29 +24,15 @@ /* A test is just a function that does some checks and throws an exception if something has gone wrong. */ -typedef void self_test_function (void); - namespace selftests { -/* Interface for the various kinds of selftests. */ - -struct selftest -{ - virtual ~selftest () = default; - virtual void operator() () const = 0; -}; - /* True if selftest should run verbosely. */ extern bool run_verbose (); /* Register a new self-test. */ -extern void register_test (const std::string &name, selftest *test); - -/* Register a new self-test. */ - extern void register_test (const std::string &name, std::function function);