|
|
|
@ -13,7 +13,7 @@ local TestStatus = {
|
|
|
|
|
FAILED = 'failed',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local VALID_MODES = utils.invert{'none', 'fortress'}
|
|
|
|
|
local VALID_MODES = utils.invert{'none', 'title', 'fortress'}
|
|
|
|
|
|
|
|
|
|
expect = {}
|
|
|
|
|
function expect.true_(value, comment)
|
|
|
|
@ -69,6 +69,31 @@ function delay(frames)
|
|
|
|
|
script.sleep(frames, 'frames')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function ensure_title_screen()
|
|
|
|
|
if df.viewscreen_titlest:is_instance(dfhack.gui.getCurViewscreen()) then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
error('Could not find title screen')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local MODE_NAVIGATE_FNS = {
|
|
|
|
|
none = function() end,
|
|
|
|
|
title = ensure_title_screen,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function load_test_config(config_file)
|
|
|
|
|
local config = {}
|
|
|
|
|
if dfhack.filesystem.isfile(config_file) then
|
|
|
|
@ -166,7 +191,7 @@ function load_tests(file, tests)
|
|
|
|
|
return false
|
|
|
|
|
else
|
|
|
|
|
if not VALID_MODES[env.config.mode] then
|
|
|
|
|
dfhack.printerr('Invalid config.mode: ' .. env.config.mode)
|
|
|
|
|
dfhack.printerr('Invalid config.mode: ' .. tostring(env.config.mode))
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
for name, test_func in pairs(env.test) do
|
|
|
|
@ -184,6 +209,18 @@ function load_tests(file, tests)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function sort_tests(tests)
|
|
|
|
|
-- to make sort stable
|
|
|
|
|
local test_index = utils.invert(tests)
|
|
|
|
|
table.sort(tests, function(a, b)
|
|
|
|
|
if a.config.mode ~= b.config.mode then
|
|
|
|
|
return VALID_MODES[a.config.mode] < VALID_MODES[b.config.mode]
|
|
|
|
|
else
|
|
|
|
|
return test_index[a] < test_index[b]
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function run_test(test, status, counts)
|
|
|
|
|
test.private.checks = 0
|
|
|
|
|
test.private.checks_ok = 0
|
|
|
|
@ -217,20 +254,7 @@ function main()
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
ensure_title_screen()
|
|
|
|
|
|
|
|
|
|
print('Loading tests')
|
|
|
|
|
local tests = {}
|
|
|
|
@ -263,9 +287,11 @@ function main()
|
|
|
|
|
table.remove(tests, i)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
sort_tests(tests)
|
|
|
|
|
|
|
|
|
|
print('Running ' .. #tests .. ' tests')
|
|
|
|
|
for _, test in pairs(tests) do
|
|
|
|
|
MODE_NAVIGATE_FNS[test.config.mode]()
|
|
|
|
|
local passed = run_test(test, status, counts)
|
|
|
|
|
status[test.full_name] = passed and TestStatus.PASSED or TestStatus.FAILED
|
|
|
|
|
save_test_status(status)
|
|
|
|
|