summaryrefslogtreecommitdiff
path: root/asl/testing
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2025-03-06 22:56:56 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2025-03-06 22:56:56 +0100
commitf0cccbe3285c039553e1fd8b5a5c7830d6087974 (patch)
tree57a0902484ec5c8ba3b9a8e7089ed42f58b6a580 /asl/testing
parent54affafd86e2b7f387345c08e8c7285c775d75e5 (diff)
Replace ASL_MOVE, ASL_FWD, and ASL_FWD_LIKE by their std:: equivalent
This is because some compiler stuff and diagnostics tools rely on those symboles being what they are.
Diffstat (limited to 'asl/testing')
-rw-r--r--asl/testing/testing.cpp42
-rw-r--r--asl/testing/testing.hpp5
2 files changed, 31 insertions, 16 deletions
diff --git a/asl/testing/testing.cpp b/asl/testing/testing.cpp
index 4e62002..53e2bb0 100644
--- a/asl/testing/testing.cpp
+++ b/asl/testing/testing.cpp
@@ -4,37 +4,51 @@
#include "asl/testing/testing.hpp"
+#include "asl/base/assert.hpp"
+#include "asl/base/meta.hpp"
+#include "asl/base/utility.hpp"
#include "asl/io/print.hpp"
-static asl::testing::Test* g_head = nullptr;
-static asl::testing::Test* g_tail = nullptr;
+namespace
+{
+
+struct TestingState
+{
+ asl::testing::Test* head = nullptr;
+ asl::testing::Test* tail = nullptr;
+
+ bool current_test_fail = false;
+};
+
+} // namespace
+
+// NOLINTNEXTLINE(*-avoid-non-const-global-variables)
+static TestingState g_state{};
void asl::testing::register_test(Test* test)
{
- if (g_head == nullptr && g_tail == nullptr)
+ if (g_state.head == nullptr && g_state.tail == nullptr)
{
- g_head = test;
- g_tail = test;
+ g_state.head = test;
+ g_state.tail = test;
}
else
{
- g_tail->m_next = test;
- test->m_prev = asl::exchange(g_tail, test);
+ g_state.tail->m_next = test;
+ test->m_prev = asl::exchange(g_state.tail, test);
}
}
-static bool g_current_test_fail = false;
-
void asl::testing::report_failure(const char* msg, const asl::source_location& sl)
{
asl::eprint("--------------------------------------------------------------\n");
asl::eprint("Test assertion failed at {}, line {}:\n", sl.file, sl.line);
asl::eprint(" {}\n", msg);
asl::eprint("--------------------------------------------------------------\n");
- g_current_test_fail = true;
+ g_state.current_test_fail = true;
}
-static void report_assert_failure(const char* msg, const asl::source_location& sl, void*)
+static void report_assert_failure(const char* msg, const asl::source_location& sl, void* /* userdata */)
{
asl::eprint("------------------------------------------------------------\n");
asl::eprint("Assertion failure at {}, line {}:\n", sl.file, sl.line);
@@ -55,14 +69,14 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
asl::testing::Test* failed_head = nullptr;
- for (auto* it = g_head; it != nullptr; it = it->m_next)
+ for (auto* it = g_state.head; it != nullptr; it = it->m_next)
{
asl::eprint(GREEN("[ RUN ]") " {}\n", it->m_case_name);
- g_current_test_fail = false;
+ g_state.current_test_fail = false;
it->m_fn();
- if (!g_current_test_fail)
+ if (!g_state.current_test_fail)
{
asl::eprint(GREEN("[ OK ]") " {}\n", it->m_case_name);
pass += 1;
diff --git a/asl/testing/testing.hpp b/asl/testing/testing.hpp
index 849c4fd..3b4a421 100644
--- a/asl/testing/testing.hpp
+++ b/asl/testing/testing.hpp
@@ -4,7 +4,7 @@
#pragma once
-#include "asl/base/utility.hpp"
+#include "asl/base/meta.hpp"
namespace asl::testing
{
@@ -35,7 +35,8 @@ struct Test
} // namespace asl::testing
#define ASL_TEST(CASE) \
- static void asl_test_fn_##CASE(); \
+ static void asl_test_fn_##CASE(); /* NOLINT */ \
+ /* NOLINTNEXTLINE */ \
static ::asl::testing::Test asl_test_##CASE( \
#CASE, \
asl_test_fn_##CASE); \