Consolidate unit testing code

This commit is contained in:
2026-02-24 23:15:02 -05:00
parent a7027873ab
commit 2c2d4e44bb
12 changed files with 74 additions and 88 deletions

View File

@@ -433,43 +433,6 @@ eng::string SourceDB::rebuild_module(const eng::string &mod) {
}
}
void SourceDB::run_unittests() {
lua_State *L = lua_state_;
LuaVar unittests, name, func, err, globtab;
LuaExtStack LS(L, unittests, name, func, err, globtab);
LS.getglobaltable(globtab);
LS.rawget(unittests, globtab, "unittests");
// Sort the unit test names.
eng::set<eng::string> names;
LS.set(name, LuaNil);
while (LS.next(unittests, name, func) != 0) {
if (LS.isfunction(func) && LS.isstring(name)) {
names.insert(LS.ckstring(name));
}
}
// Run the functions in order
bool any = false;
for (const eng::string &name : names) {
util::dprint("Running unittests: ", name);
LS.rawget(func, unittests, name);
lua_pushvalue(L, func.index());
eng::string msg = traceback_pcall(L, 0, 0);
if (!msg.empty()) {
LS.set(err, msg);
util::dprint(msg);
any = true;
}
}
if (any) {
exit(1);
}
}
void SourceDB::init(lua_State *L) {
lua_state_ = L;
LuaVar globtab, persist, unpersist, classname, classtab, funcname, funcp, rawfunc, nullstring;