|
|
@ -13,14 +13,20 @@ local TestStatus = {
|
|
|
|
FAILED = 'failed',
|
|
|
|
FAILED = 'failed',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
local VALID_MODES = utils.invert{'none', 'fortress'}
|
|
|
|
local VALID_MODES = utils.invert{'none', 'title', 'fortress'}
|
|
|
|
|
|
|
|
|
|
|
|
expect = {}
|
|
|
|
expect = {}
|
|
|
|
function expect.true_(value, comment)
|
|
|
|
function expect.true_(value, comment)
|
|
|
|
return not not value, comment, 'expected true'
|
|
|
|
return not not value, comment, 'expected true, got ' .. tostring(value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
function expect.false_(value, comment)
|
|
|
|
function expect.false_(value, comment)
|
|
|
|
return not value, comment, 'expected false'
|
|
|
|
return not value, comment, 'expected false, got ' .. tostring(value)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function expect.fail(comment)
|
|
|
|
|
|
|
|
return false, comment or 'check failed, no reason provided'
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function expect.nil_(value, comment)
|
|
|
|
|
|
|
|
return value == nil, comment, 'expected nil, got ' .. tostring(value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
function expect.eq(a, b, comment)
|
|
|
|
function expect.eq(a, b, comment)
|
|
|
|
return a == b, comment, ('%s ~= %s'):format(a, b)
|
|
|
|
return a == b, comment, ('%s ~= %s'):format(a, b)
|
|
|
@ -63,12 +69,53 @@ function expect.error(func, ...)
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function expect.pairs_contains(table, key, comment)
|
|
|
|
|
|
|
|
for k, v in pairs(table) do
|
|
|
|
|
|
|
|
if k == key then
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return false, comment, ('could not find key "%s" in table'):format(key)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
function expect.not_pairs_contains(table, key, comment)
|
|
|
|
|
|
|
|
for k, v in pairs(table) do
|
|
|
|
|
|
|
|
if k == key then
|
|
|
|
|
|
|
|
return false, comment, ('found key "%s" in table'):format(key)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function delay(frames)
|
|
|
|
function delay(frames)
|
|
|
|
frames = frames or 1
|
|
|
|
frames = frames or 1
|
|
|
|
script.sleep(frames, 'frames')
|
|
|
|
script.sleep(frames, 'frames')
|
|
|
|
end
|
|
|
|
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)
|
|
|
|
function load_test_config(config_file)
|
|
|
|
local config = {}
|
|
|
|
local config = {}
|
|
|
|
if dfhack.filesystem.isfile(config_file) then
|
|
|
|
if dfhack.filesystem.isfile(config_file) then
|
|
|
@ -166,7 +213,7 @@ function load_tests(file, tests)
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
else
|
|
|
|
else
|
|
|
|
if not VALID_MODES[env.config.mode] then
|
|
|
|
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
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for name, test_func in pairs(env.test) do
|
|
|
|
for name, test_func in pairs(env.test) do
|
|
|
@ -184,6 +231,18 @@ function load_tests(file, tests)
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
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)
|
|
|
|
function run_test(test, status, counts)
|
|
|
|
test.private.checks = 0
|
|
|
|
test.private.checks = 0
|
|
|
|
test.private.checks_ok = 0
|
|
|
|
test.private.checks_ok = 0
|
|
|
@ -217,20 +276,7 @@ function main()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
local passed = true
|
|
|
|
local passed = true
|
|
|
|
|
|
|
|
|
|
|
|
print('Looking for title screen...')
|
|
|
|
ensure_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')
|
|
|
|
print('Loading tests')
|
|
|
|
local tests = {}
|
|
|
|
local tests = {}
|
|
|
@ -263,9 +309,11 @@ function main()
|
|
|
|
table.remove(tests, i)
|
|
|
|
table.remove(tests, i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
sort_tests(tests)
|
|
|
|
|
|
|
|
|
|
|
|
print('Running ' .. #tests .. ' tests')
|
|
|
|
print('Running ' .. #tests .. ' tests')
|
|
|
|
for _, test in pairs(tests) do
|
|
|
|
for _, test in pairs(tests) do
|
|
|
|
|
|
|
|
MODE_NAVIGATE_FNS[test.config.mode]()
|
|
|
|
local passed = run_test(test, status, counts)
|
|
|
|
local passed = run_test(test, status, counts)
|
|
|
|
status[test.full_name] = passed and TestStatus.PASSED or TestStatus.FAILED
|
|
|
|
status[test.full_name] = passed and TestStatus.PASSED or TestStatus.FAILED
|
|
|
|
save_test_status(status)
|
|
|
|
save_test_status(status)
|
|
|
|