只接 std::exception 的话,第三方库或跨 FFI 边界抛出来的东西照样会逃出 main 走 abort, 和上一个 commit 修掉的是同一类故障:ctest 看不到原因,栈也不展开。引擎内现有的抛出确实 都是 std::exception 派生,但这一层缺的是「无论什么异常都到不了 terminate」的保证,补上它 才让 main 的边界真正闭合。 只加 catch 分支,输出通道沿用各文件原来那一个(fprintf / cerr / fmt::println), 不改任何断言。
49 lines
1.3 KiB
C++
49 lines
1.3 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;
|
|
}
|
|
catch (...)
|
|
{
|
|
std::fprintf(stderr, "An exception escaped the test body.\n");
|
|
return 1;
|
|
}
|
|
}
|