srctree

Robin Linden parent 4e234edd cc02f47d
etest: Simplify action-handling in old API

inlinesplit
etest/etest.cpp added: 5, removed: 10, total 0
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2021-2023 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
@@ -20,12 +20,7 @@ Suite &registry() {
return test_registry;
}
 
struct DummyActions : public IActions {
void expect(bool, std::optional<std::string_view>, etest::source_location const &) noexcept override {}
void require(bool, std::optional<std::string_view>, etest::source_location const &) override {}
};
DummyActions dummy_actions;
std::reference_wrapper<IActions> current_actions{dummy_actions};
std::optional<std::reference_wrapper<IActions>> current_actions{};
} // namespace
 
int run_all_tests(RunOptions const &opts) noexcept {
@@ -47,11 +42,11 @@ void disabled_test(std::string name, std::function<void()> body) noexcept {
}
 
void expect(bool b, std::optional<std::string_view> log_message, etest::source_location const &loc) noexcept {
current_actions.get().expect(b, std::move(log_message), loc);
current_actions.value().get().expect(b, std::move(log_message), loc);
}
 
void require(bool b, std::optional<std::string_view> log_message, etest::source_location const &loc) {
current_actions.get().require(b, std::move(log_message), loc);
current_actions.value().get().require(b, std::move(log_message), loc);
}
 
} // namespace etest