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
end end
function main() function load_tests(file, tests)
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
local short_filename = file:sub(file:find('test'), -1) local short_filename = file:sub(file:find('test'), -1)
print('Loading file: ' .. short_filename) print('Loading file: ' .. short_filename)
local env, env_private = build_test_env() local env, env_private = build_test_env()
local code, err = loadfile(file, 't', env) local code, err = loadfile(file, 't', env)
if not code then if not code then
passed = false
counts.file_errors = counts.file_errors + 1
dfhack.printerr('Failed to load file: ' .. tostring(err)) dfhack.printerr('Failed to load file: ' .. tostring(err))
return false
else else
local ok, err = pcall(code) local ok, err = pcall(code)
if not ok then if not ok then
passed = false
counts.file_errors = counts.file_errors + 1
dfhack.printerr('Error when running file: ' .. tostring(err)) dfhack.printerr('Error when running file: ' .. tostring(err))
return false
else else
for name, test_func in pairs(env.test) do for name, test_func in pairs(env.test) do
local test_data = { local test_data = {
@ -158,17 +127,10 @@ function main()
end end
end end
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') function run_test(test, status, counts)
for _, test in pairs(tests) do
if status[test.full_name] == TestStatus.PENDING then if status[test.full_name] == TestStatus.PENDING then
test.private.checks = 0 test.private.checks = 0
test.private.checks_ok = 0 test.private.checks_ok = 0
@ -191,6 +153,54 @@ function main()
else else
print('test skipped: ' .. test.name .. ' (state = ' .. status[test.full_name] .. ')') print('test skipped: ' .. test.name .. ' (state = ' .. status[test.full_name] .. ')')
end 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 end
print('\nTest summary:') print('\nTest summary:')