源码都改用Xmake

This commit is contained in:
mzx committed 2026-11-17 21:24:27 +08:00
1 parent d723b34c05
commit ec9332826a
24 files changed
+612 -348

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
// Copyright 2026 sentry_nav_dev
//
// 极简测试框架(不引入 gtest / catch2)。
//
// 为什么不用 gtest:这一层的目标就是「零外部依赖、xmake 一条命令就能跑」。
// 引入 gtest 要走网络拉包,队友离线环境会卡住。
// 这里的断言已经够覆盖纯算法逻辑了。
#ifndef SENTRY_NAV_CORE_TESTS_TEST_UTIL_HPP_
#define SENTRY_NAV_CORE_TESTS_TEST_UTIL_HPP_
#include <cmath>
#include <cstdio>
namespace sentry_nav_test {
inline int g_checks = 0;
inline int g_failures = 0;
inline void Report(bool ok, const char* expr, const char* file, int line) {
++g_checks;
if (!ok) {
++g_failures;
std::fprintf(stderr, " FAIL %s:%d\n %s\n", file, line, expr);
}
}
// 在每个测试程序的 main 末尾调用;返回 0 表示全过。
inline int Summary(const char* suite) {
if (g_failures == 0) {
std::printf("[PASS] %s (%d 项检查)\n", suite, g_checks);
return 0;
}
std::printf("[FAIL] %s (%d 项检查, %d 项失败)\n", suite, g_checks, g_failures);
return 1;
}
} // namespace sentry_nav_test
#define EXPECT_TRUE(cond) \
::sentry_nav_test::Report((cond), #cond, __FILE__, __LINE__)
#define EXPECT_FALSE(cond) \
::sentry_nav_test::Report(!(cond), "!(" #cond ")", __FILE__, __LINE__)
#define EXPECT_EQ(actual, expected) \
::sentry_nav_test::Report((actual) == (expected), \
#actual " == " #expected, \
__FILE__, __LINE__)
#define EXPECT_NEAR(actual, expected, tol) \
::sentry_nav_test::Report(std::fabs((actual) - (expected)) <= (tol), \
#actual " ~= " #expected, \
__FILE__, __LINE__)
#endif // SENTRY_NAV_CORE_TESTS_TEST_UTIL_HPP_