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
@@ -3,6 +3,7 @@
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <stdexcept>
|
||||
#include <cstdio>
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -19,7 +20,7 @@ void set_data_directory(const std::filesystem::path &path)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
int run_test()
|
||||
{
|
||||
const std::filesystem::path expected =
|
||||
std::filesystem::temp_directory_path() / std::filesystem::u8path("metasequoia-ime-词库");
|
||||
@@ -39,3 +40,16 @@ int main()
|
||||
}
|
||||
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