这些测试用 throw 报告断言失败,但 13 个测试的 main 没有顶层 try,异常一路逃出去就会 走 std::terminate -> abort。abort 不做栈展开,ScopedDataDirectoryCleanup 的析构不执行, 测试建的临时目录和用户词库句柄留在原地;失败原因也不会打到 stderr,ctest 只能看到一段 崩溃,排查时得先猜是哪个断言。 按仓里已有的写法把函数体挪进 run_test(),main 变成一层薄包装,catch 里打 what() 再返回 1。 fuzzy_pinyin 的 create_directories 原本落在 try 之前,一并挪进去。 只是给失败换一条能读到的出口,没有改任何断言或阈值。
44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
#include "validator.h"
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <iterator>
|
|
#include <cstdio>
|
|
|
|
int run_test(int argc, char **argv)
|
|
{
|
|
if (argc != 2)
|
|
return 2;
|
|
std::ifstream input(argv[1]);
|
|
if (!input)
|
|
return 2;
|
|
const std::string text((std::istreambuf_iterator<char>(input)), {});
|
|
const auto fixtures = boost::json::parse(text);
|
|
for (const auto &fixture : fixtures.as_array())
|
|
{
|
|
const auto &test = fixture.as_object();
|
|
const auto *surface = test.if_contains("surface");
|
|
if (metasequoia::webview::Validate(test.at("message"), test.at("direction").as_string(),
|
|
surface ? std::string(surface->as_string()) : "") !=
|
|
test.at("valid").as_bool())
|
|
{
|
|
std::cerr << test.at("name") << '\n';
|
|
return 1;
|
|
}
|
|
}
|
|
std::cout << fixtures.as_array().size() << " shared fixtures passed\n";
|
|
return 0;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
try
|
|
{
|
|
return run_test(argc, argv);
|
|
}
|
|
catch (const std::exception &error)
|
|
{
|
|
std::fprintf(stderr, "%s\n", error.what());
|
|
return 1;
|
|
}
|
|
}
|