Regularized unit testing framework.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
@@ -320,3 +321,38 @@ LuaDefine(source_rebuild, "c") {
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
LuaDefine(source_run_unittests, "c") {
|
||||
LuaVar unittests, name, func, err;
|
||||
LuaRet rescode;
|
||||
LuaStack LS(L, unittests, name, func, err, rescode);
|
||||
|
||||
LS.getfield(unittests, LuaGlobals, "unittests");
|
||||
|
||||
// Sort the unit test names.
|
||||
std::set<std::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 std::string &name : names) {
|
||||
std::cerr << "Running unittests." << name << std::endl;
|
||||
LS.rawget(func, unittests, name);
|
||||
|
||||
lua_pushvalue(L, func.index());
|
||||
if (traceback_pcall(L, 0, 0) != 0) {
|
||||
lua_replace(L, err.index());
|
||||
std::cerr << LS.ckstring(err);
|
||||
any = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Return 1 if any errors.
|
||||
LS.set(rescode, any ? 1 : 0);
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user