-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
85 lines (64 loc) · 1.8 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
if not os.getenv("BLTUnit") then return end
log("/-------------------------------------\\")
log("| BLT UNIT |")
log("\\-------------------------------------/")
log("Running tests...")
local run_test
local function test_dir(path)
local tests = {}
for _, t in pairs(file.GetFiles(path)) do
if t:sub(-4) == ".lua" then
table.insert(tests, path .. "/" .. t)
end
end
if #tests > 0 then
log("Running tests in " .. path)
end
local result = ""
local success = true
for _, path in pairs(tests) do
local tsuccess, tresult = run_test(path)
result = result .. tresult
success = success and tsuccess
end
for _, t in pairs(file.GetDirectories(path)) do
local ssuccess, sresult = test_dir(path .. "/" .. t)
success = success and ssuccess
result = result .. " " .. sresult
end
return success, result
end
run_test = function(file)
local test, err = vm.loadfile(file)
if not test then
log("Error loading test " .. file .. ": " .. err)
return false, "!"
end
local env = {}
setmetatable(env, {
__index = _G
})
setfenv(test, env)
env.f = string.gsub(file, "(.*/)(.*)", "%1")
local luaerror = false
local success = vm.xpcall(test, function(msg)
log(debug.traceback(tostring(msg), 2))
luaerror = true
end)
if not success and not luaerror then
log("Test " .. file .. " mysteriously failed - maybe a error in C?")
end
return success, success and "." or (luaerror and "E" or "@")
end
local success, result = test_dir(ModPath .. "tests")
log("Test Results: " .. result)
log("/-------------------------------------\\")
if success then
log("| Completed - Success |")
else
log("| !!!!!!!! Completed - Error !!!!!!!! |")
end
log("\\-------------------------------------/")
-- Quit - right now
core:import("CoreEngineAccess")
CoreEngineAccess._quit()