fix(engine): 让测试的 main 接住逃逸的异常
这些测试用 throw 报告断言失败,但 13 个测试的 main 没有顶层 try,异常一路逃出去就会 走 std::terminate -> abort。abort 不做栈展开,ScopedDataDirectoryCleanup 的析构不执行, 测试建的临时目录和用户词库句柄留在原地;失败原因也不会打到 stderr,ctest 只能看到一段 崩溃,排查时得先猜是哪个断言。 按仓里已有的写法把函数体挪进 run_test(),main 变成一层薄包装,catch 里打 what() 再返回 1。 fuzzy_pinyin 的 create_directories 原本落在 try 之前,一并挪进去。 只是给失败换一条能读到的出口,没有改任何断言或阈值。
This commit is contained in:
1 parent
2e19365124
commit
74e0a16776
15 files changed
+215
-15
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
#include <cstdio>
|
||||
|
||||
#ifdef _WIN32
|
||||
static_assert(std::is_same_v<decltype(KeyStroke::vk), UINT>);
|
||||
@@ -16,8 +17,21 @@ static_assert(std::is_same_v<decltype(KeyStroke::wch), char16_t>);
|
||||
|
||||
void test_public_session_interface();
|
||||
|
||||
int main()
|
||||
int run_test()
|
||||
{
|
||||
test_public_session_interface();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
return run_test();
|
||||
}
|
||||
catch (const std::exception &error)
|
||||
{
|
||||
std::fprintf(stderr, "%s\n", error.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user