Split up test runner funcs

develop
lethosor 2020-03-26 23:26:43 -04:00
parent f784fdc8b7
commit 2e352408c2
1 changed files with 55 additions and 45 deletions

@ -102,50 +102,19 @@ function finish_tests()
end
end
function main()
local files = get_test_files()
local counts = {
tests = 0,
tests_ok = 0,
checks = 0,
checks_ok = 0,
file_errors = 0,
}
local passed = true
print('Looking for title screen...')
for i = 0, 100 do
local scr = dfhack.gui.getCurViewscreen()
if df.viewscreen_titlest:is_instance(scr) then
print('Found title screen')
break
else
scr:feed_key(df.interface_key.LEAVESCREEN)
delay(10)
end
end
if not df.viewscreen_titlest:is_instance(dfhack.gui.getCurViewscreen()) then
qerror('Could not find title screen')
end
print('Loading tests')
local tests = {}
for _, file in ipairs(files) do
function load_tests(file, tests)
local short_filename = file:sub(file:find('test'), -1)
print('Loading file: ' .. short_filename)
local env, env_private = build_test_env()
local code, err = loadfile(file, 't', env)
if not code then
passed = false
counts.file_errors = counts.file_errors + 1
dfhack.printerr('Failed to load file: ' .. tostring(err))
return false
else
local ok, err = pcall(code)
if not ok then
passed = false
counts.file_errors = counts.file_errors + 1
dfhack.printerr('Error when running file: ' .. tostring(err))
return false
else
for name, test_func in pairs(env.test) do
local test_data = {
@ -158,17 +127,10 @@ function main()
end
end
end
return true
end
local status = load_test_status() or {}
for _, test in pairs(tests) do
if not status[test.full_name] then
status[test.full_name] = TestStatus.PENDING
end
end
print('Running tests')
for _, test in pairs(tests) do
function run_test(test, status, counts)
if status[test.full_name] == TestStatus.PENDING then
test.private.checks = 0
test.private.checks_ok = 0
@ -193,6 +155,54 @@ function main()
end
end
function main()
local files = get_test_files()
local counts = {
tests = 0,
tests_ok = 0,
checks = 0,
checks_ok = 0,
file_errors = 0,
}
local passed = true
print('Looking for title screen...')
for i = 0, 100 do
local scr = dfhack.gui.getCurViewscreen()
if df.viewscreen_titlest:is_instance(scr) then
print('Found title screen')
break
else
scr:feed_key(df.interface_key.LEAVESCREEN)
delay(10)
end
end
if not df.viewscreen_titlest:is_instance(dfhack.gui.getCurViewscreen()) then
qerror('Could not find title screen')
end
print('Loading tests')
local tests = {}
for _, file in ipairs(files) do
if not load_tests(file, tests) then
passed = false
counts.file_errors = counts.file_errors + 1
end
end
local status = load_test_status() or {}
for _, test in pairs(tests) do
if not status[test.full_name] then
status[test.full_name] = TestStatus.PENDING
end
end
print('Running tests')
for _, test in pairs(tests) do
run_test(test, status, counts)
end
print('\nTest summary:')
print(('%d/%d tests passed'):format(counts.tests_ok, counts.tests))
print(('%d/%d checks passed'):format(counts.checks_ok, counts.checks))