Files
EVEngine/test/runtime_error_sink.cpp
T
西风逍遥游andCursor eb39d162b7 fix(runtime,voxel,graphics): script stacks, voxel pick, 3D present hitch
Surface throw-site file:line on caught Squirrel errors, skip empty deferred graphs that hitch orbit, and drive voxel place/break from a single Camera3D.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-11 01:23:32 +08:00

69 lines
2.3 KiB
C++

#include "common/Runtime.h"
#include "devtools/DevTool.hpp"
#include "zeroerr/assert.h"
#include "zeroerr/unittest.h"
using namespace eve;
// The Runtime error-handler sink wired by DevTool::attach(Runtime&) routes
// errors that the uncaught-error VM hook never sees (compile / reflect /
// unload) into the DevTool slicer/report, without double-reporting the
// uncaught runtime errors the hook already handled.
TEST_CASE("devtools.runtimeErrorSink.reportsCompileError") {
dev::DevTool::instance().detach();
Runtime runtime(256, ssq::Libs::ALL);
runtime.initialize();
dev::DevTool::instance().attach(runtime, /*sampleLocals=*/true);
bool caught = false;
try {
runtime.runSource("class Broken {", "broken.nut");
} catch (const ScriptException& error) {
caught = true;
CHECK_EQ(static_cast<int>(error.stage()), static_cast<int>(ScriptStage::Compile));
CHECK_EQ(error.source(), std::string("broken.nut"));
}
CHECK(caught);
// The Runtime error-handler sink must have routed the compile error into the
// DevTool report even though the VM error hook never fires for a compile
// failure.
const std::string report = dev::DevTool::instance().lastReport();
CHECK(!report.empty());
CHECK(report.find("broken.nut") != std::string::npos);
dev::DevTool::instance().detach();
}
TEST_CASE("devtools.runtimeErrorSink.noDoubleReportOnRuntimeError") {
dev::DevTool::instance().detach();
Runtime runtime(256, ssq::Libs::ALL);
runtime.initialize();
dev::DevTool::instance().attach(runtime, /*sampleLocals=*/true);
bool caught = false;
try {
runtime.runSource(R"SQ(
function boom() { throw "kaboom" }
boom();
)SQ", "boom.nut");
} catch (const ScriptException& error) {
caught = true;
// The VM hook only captures the live stack when Runtime is bound;
// the Runtime error sink reports it once after unwind.
CHECK(!error.reported());
CHECK(error.hasLocation());
CHECK(!error.stackTrace().empty());
}
CHECK(caught);
// Reported exactly once through the DevTool report pipeline.
const std::string report = dev::DevTool::instance().lastReport();
CHECK(!report.empty());
CHECK(report.find("kaboom") != std::string::npos);
dev::DevTool::instance().detach();
}