清理废弃模块并完善测试基础设施

This commit is contained in:
2026-07-17 23:49:45 +08:00
parent d0d1de4d00
commit 90262aaf6d
102 changed files with 1711 additions and 8175 deletions
+68
View File
@@ -0,0 +1,68 @@
#pragma once
#include <functional>
#include <sstream>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
namespace Qa
{
struct TestCase
{
std::string name;
std::function<void()> function;
};
inline std::vector<TestCase> &registry()
{
static std::vector<TestCase> tests;
return tests;
}
class Registrar
{
public:
Registrar(const char *name, std::function<void()> function)
{
registry().push_back({name, std::move(function)});
}
};
[[noreturn]] inline void fail(const char *expression, const char *file, int line)
{
std::ostringstream stream;
stream << file << ':' << line << ": expectation failed: " << expression;
throw std::runtime_error(stream.str());
}
}
#define QA_JOIN_IMPL(left, right) left##right
#define QA_JOIN(left, right) QA_JOIN_IMPL(left, right)
#define QA_TEST(suiteName, testName) \
static void QA_JOIN(qa_test_function_, __LINE__)(); \
static Qa::Registrar QA_JOIN(qa_test_registrar_, __LINE__)( \
#suiteName "." #testName, QA_JOIN(qa_test_function_, __LINE__)); \
static void QA_JOIN(qa_test_function_, __LINE__)()
#define QA_EXPECT(expression) \
do \
{ \
if (!(expression)) \
{ \
Qa::fail(#expression, __FILE__, __LINE__); \
} \
} while (false)
#define QA_EXPECT_EQ(actual, expected) \
do \
{ \
const auto qaActualValue = (actual); \
const auto qaExpectedValue = (expected); \
if (!(qaActualValue == qaExpectedValue)) \
{ \
Qa::fail(#actual " == " #expected, __FILE__, __LINE__); \
} \
} while (false)