2021-03-06 23:07:45 -07:00
|
|
|
-- DFHack developer test harness
|
|
|
|
--@ module = true
|
|
|
|
|
2021-03-23 22:48:52 -06:00
|
|
|
local expect = require 'test.expect'
|
2020-03-24 23:43:09 -06:00
|
|
|
local json = require 'json'
|
2018-07-19 09:26:38 -06:00
|
|
|
local script = require 'gui.script'
|
2018-07-19 10:40:25 -06:00
|
|
|
local utils = require 'utils'
|
2018-07-19 09:26:38 -06:00
|
|
|
|
2021-02-28 23:31:44 -07:00
|
|
|
local help_text =
|
2021-03-06 23:07:45 -07:00
|
|
|
[====[
|
|
|
|
|
2021-03-22 12:09:44 -06:00
|
|
|
test
|
|
|
|
====
|
2021-03-06 23:07:45 -07:00
|
|
|
|
2021-02-28 23:31:44 -07:00
|
|
|
Run DFHack tests.
|
|
|
|
|
|
|
|
Usage:
|
2021-03-07 03:51:29 -07:00
|
|
|
|
2021-03-22 12:09:44 -06:00
|
|
|
test [<options>] [<done_command>]
|
2021-03-07 03:51:29 -07:00
|
|
|
|
2021-03-07 09:51:02 -07:00
|
|
|
If a done_command is specified, it will be run after the tests complete.
|
2021-02-28 23:31:44 -07:00
|
|
|
|
|
|
|
Options:
|
2021-03-07 03:51:29 -07:00
|
|
|
|
2021-02-28 23:31:44 -07:00
|
|
|
-h, --help display this help message and exit.
|
2021-03-05 20:47:24 -07:00
|
|
|
-d, --test_dir specifies which directory to look in for tests. defaults to
|
|
|
|
the "hack/scripts/test" folder in your DF installation.
|
2021-02-28 23:31:44 -07:00
|
|
|
-m, --modes only run tests in the given comma separated list of modes.
|
2021-03-07 03:51:29 -07:00
|
|
|
valid modes are 'none' (test can be run on any screen) and
|
|
|
|
'title' (test must be run on the DF title screen). if not
|
|
|
|
specified, no modes are filtered.
|
2021-03-22 11:06:03 -06:00
|
|
|
-r, --resume skip tests that have already been run. remove the
|
|
|
|
test_status.json file to reset the record.
|
2021-02-28 23:31:44 -07:00
|
|
|
-t, --tests only run tests that match one of the comma separated list of
|
|
|
|
patterns. if not specified, no tests are filtered.
|
|
|
|
|
|
|
|
Examples:
|
2021-03-07 03:51:29 -07:00
|
|
|
|
2021-03-22 12:09:44 -06:00
|
|
|
test runs all tests
|
|
|
|
test -r runs all tests that haven't been run before
|
|
|
|
test -m none runs tests that don't need the game to be in a
|
|
|
|
specific mode
|
|
|
|
test -t quickfort runs quickfort tests
|
|
|
|
test -d /path/to/dfhack-scripts/repo/test
|
|
|
|
runs tests in your dev scripts repo
|
2021-03-07 03:51:29 -07:00
|
|
|
|
|
|
|
Default values for the options may be set in a file named test_config.json in
|
|
|
|
your DF folder. Options with comma-separated values should be written as json
|
|
|
|
arrays. For example:
|
|
|
|
|
|
|
|
{
|
|
|
|
"test_dir": "/home/myk/src/dfhack-scripts/test",
|
2021-03-07 09:51:02 -07:00
|
|
|
"modes": [ "none" ],
|
|
|
|
"tests": [ "quickfort", "devel" ],
|
2021-03-22 11:06:03 -06:00
|
|
|
"done_command": "devel/luacov -c"
|
2021-03-07 03:51:29 -07:00
|
|
|
}
|
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
]====]
|
2018-07-18 12:29:13 -06:00
|
|
|
|
2020-03-31 22:26:51 -06:00
|
|
|
local CONFIG_FILE = 'test_config.json'
|
2020-03-24 23:43:09 -06:00
|
|
|
local STATUS_FILE = 'test_status.json'
|
|
|
|
local TestStatus = {
|
|
|
|
PENDING = 'pending',
|
|
|
|
PASSED = 'passed',
|
|
|
|
FAILED = 'failed',
|
|
|
|
}
|
|
|
|
|
2020-04-05 21:12:31 -06:00
|
|
|
local VALID_MODES = utils.invert{'none', 'title', 'fortress'}
|
2020-03-26 22:34:44 -06:00
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
local function delay(frames)
|
2018-07-19 09:26:38 -06:00
|
|
|
frames = frames or 1
|
|
|
|
script.sleep(frames, 'frames')
|
|
|
|
end
|
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
local function clean_require(module)
|
2020-12-15 19:27:04 -07:00
|
|
|
-- wrapper around require() - forces a clean load of every module to ensure
|
|
|
|
-- that modules checking for dfhack.internal.IN_TEST at load time behave
|
|
|
|
-- properly
|
|
|
|
if package.loaded[module] then
|
|
|
|
reload(module)
|
|
|
|
end
|
|
|
|
return require(module)
|
|
|
|
end
|
|
|
|
|
2021-03-29 12:26:28 -06:00
|
|
|
-- forces clean load of scripts directly or indirectly included from the test
|
|
|
|
-- file. we use our own scripts table instead of the one in dfhack.internal so
|
|
|
|
-- we don't affect the state scripts that are used outside the test harness.
|
2021-03-29 13:28:19 -06:00
|
|
|
local test_scripts = {}
|
2021-03-29 12:26:28 -06:00
|
|
|
local test_envvars = {}
|
2021-03-22 14:29:47 -06:00
|
|
|
local function clean_reqscript(name)
|
2021-03-29 13:23:53 -06:00
|
|
|
local path = dfhack.findScript(name)
|
|
|
|
if test_scripts[path] then return test_scripts[path].env end
|
|
|
|
local _, env = dfhack.run_script_with_env(
|
|
|
|
test_envvars,
|
|
|
|
name,
|
|
|
|
{
|
|
|
|
scripts=test_scripts,
|
|
|
|
module=true,
|
|
|
|
module_strict=true
|
|
|
|
})
|
|
|
|
return env
|
2021-03-22 14:29:47 -06:00
|
|
|
end
|
2021-03-29 12:26:28 -06:00
|
|
|
test_envvars.require = clean_require
|
|
|
|
test_envvars.reqscript = clean_reqscript
|
2021-03-22 14:29:47 -06:00
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
local function ensure_title_screen()
|
2020-04-05 21:12:31 -06:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
local function load_test_config(config_file)
|
2020-03-31 22:26:51 -06:00
|
|
|
local config = {}
|
|
|
|
if dfhack.filesystem.isfile(config_file) then
|
|
|
|
config = json.decode_file(config_file)
|
|
|
|
end
|
|
|
|
|
|
|
|
if not config.test_dir then
|
|
|
|
config.test_dir = dfhack.getHackPath() .. 'scripts/test'
|
|
|
|
end
|
|
|
|
|
|
|
|
return config
|
|
|
|
end
|
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
local function build_test_env()
|
2018-07-18 12:29:13 -06:00
|
|
|
local env = {
|
2018-07-19 10:40:25 -06:00
|
|
|
test = utils.OrderedTable(),
|
2020-03-26 22:34:44 -06:00
|
|
|
config = {
|
|
|
|
mode = 'none',
|
|
|
|
},
|
2018-07-18 12:29:13 -06:00
|
|
|
expect = {},
|
2018-07-19 09:26:38 -06:00
|
|
|
delay = delay,
|
2020-12-15 19:27:04 -07:00
|
|
|
require = clean_require,
|
2021-03-22 14:29:47 -06:00
|
|
|
reqscript = clean_reqscript,
|
2018-07-18 12:29:13 -06:00
|
|
|
}
|
|
|
|
local private = {
|
|
|
|
checks = 0,
|
|
|
|
checks_ok = 0,
|
|
|
|
}
|
|
|
|
for name, func in pairs(expect) do
|
|
|
|
env.expect[name] = function(...)
|
|
|
|
private.checks = private.checks + 1
|
2018-07-19 10:40:25 -06:00
|
|
|
local ret = {func(...)}
|
|
|
|
local ok = table.remove(ret, 1)
|
|
|
|
local msg = ''
|
|
|
|
for _, part in pairs(ret) do
|
|
|
|
if part then
|
|
|
|
msg = msg .. ': ' .. tostring(part)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
msg = msg:sub(3) -- strip leading ': '
|
2018-07-18 12:29:13 -06:00
|
|
|
if ok then
|
|
|
|
private.checks_ok = private.checks_ok + 1
|
|
|
|
else
|
|
|
|
dfhack.printerr('Check failed! ' .. (msg or '(no message)'))
|
|
|
|
local info = debug.getinfo(2)
|
|
|
|
dfhack.printerr((' at %s:%d'):format(info.short_src, info.currentline))
|
|
|
|
print('')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
setmetatable(env, {__index = _G})
|
|
|
|
return env, private
|
|
|
|
end
|
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
local function get_test_files(test_dir)
|
2018-07-18 12:29:13 -06:00
|
|
|
local files = {}
|
2021-03-06 23:07:45 -07:00
|
|
|
print('Loading tests from ' .. test_dir)
|
2020-03-31 22:26:51 -06:00
|
|
|
for _, entry in ipairs(dfhack.filesystem.listdir_recursive(test_dir)) do
|
2021-03-22 12:09:44 -06:00
|
|
|
if not entry.isdir then
|
2018-07-18 12:29:13 -06:00
|
|
|
table.insert(files, entry.path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.sort(files)
|
|
|
|
return files
|
|
|
|
end
|
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
local function load_test_status()
|
|
|
|
if dfhack.filesystem.isfile(STATUS_FILE) then
|
2020-03-24 23:43:09 -06:00
|
|
|
return json.decode_file(STATUS_FILE)
|
|
|
|
end
|
2018-02-04 14:00:53 -07:00
|
|
|
end
|
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
local function save_test_status(status)
|
2020-03-24 23:43:09 -06:00
|
|
|
json.encode_file(status, STATUS_FILE)
|
|
|
|
end
|
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
local function finish_tests(done_command)
|
2020-12-15 19:24:38 -07:00
|
|
|
dfhack.internal.IN_TEST = false
|
2021-03-07 13:06:27 -07:00
|
|
|
if done_command and #done_command > 0 then
|
2018-07-18 12:29:13 -06:00
|
|
|
dfhack.run_command(done_command)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
local function load_tests(file, tests)
|
|
|
|
local short_filename = file:sub((file:find('test') or -4)+5, -1)
|
2020-03-26 21:26:43 -06:00
|
|
|
print('Loading file: ' .. short_filename)
|
|
|
|
local env, env_private = build_test_env()
|
|
|
|
local code, err = loadfile(file, 't', env)
|
|
|
|
if not code then
|
|
|
|
dfhack.printerr('Failed to load file: ' .. tostring(err))
|
|
|
|
return false
|
|
|
|
else
|
2020-12-15 19:24:38 -07:00
|
|
|
dfhack.internal.IN_TEST = true
|
2020-03-26 21:26:43 -06:00
|
|
|
local ok, err = pcall(code)
|
2020-12-15 19:24:38 -07:00
|
|
|
dfhack.internal.IN_TEST = false
|
2020-03-26 21:26:43 -06:00
|
|
|
if not ok then
|
|
|
|
dfhack.printerr('Error when running file: ' .. tostring(err))
|
|
|
|
return false
|
|
|
|
else
|
2020-03-26 22:34:44 -06:00
|
|
|
if not VALID_MODES[env.config.mode] then
|
2020-04-05 21:12:31 -06:00
|
|
|
dfhack.printerr('Invalid config.mode: ' .. tostring(env.config.mode))
|
2020-03-26 22:34:44 -06:00
|
|
|
return false
|
|
|
|
end
|
2020-03-26 21:26:43 -06:00
|
|
|
for name, test_func in pairs(env.test) do
|
|
|
|
local test_data = {
|
|
|
|
full_name = short_filename .. ':' .. name,
|
|
|
|
func = test_func,
|
|
|
|
private = env_private,
|
2020-03-26 22:34:44 -06:00
|
|
|
config = env.config,
|
2020-03-26 21:26:43 -06:00
|
|
|
}
|
|
|
|
test_data.name = test_data.full_name:gsub('test/', ''):gsub('.lua', '')
|
|
|
|
table.insert(tests, test_data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
local function sort_tests(tests)
|
2020-04-05 21:12:31 -06:00
|
|
|
-- 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
|
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
local function run_test(test, status, counts)
|
2020-03-26 22:49:34 -06:00
|
|
|
test.private.checks = 0
|
|
|
|
test.private.checks_ok = 0
|
|
|
|
counts.tests = counts.tests + 1
|
2020-12-15 19:24:38 -07:00
|
|
|
dfhack.internal.IN_TEST = true
|
2020-03-26 22:49:34 -06:00
|
|
|
local ok, err = pcall(test.func)
|
2020-12-15 19:24:38 -07:00
|
|
|
dfhack.internal.IN_TEST = false
|
2020-03-26 22:49:34 -06:00
|
|
|
local passed = false
|
|
|
|
if not ok then
|
|
|
|
dfhack.printerr('test errored: ' .. test.name .. ': ' .. tostring(err))
|
|
|
|
elseif test.private.checks ~= test.private.checks_ok then
|
|
|
|
dfhack.printerr('test failed: ' .. test.name)
|
2020-03-26 21:26:43 -06:00
|
|
|
else
|
2020-03-26 22:49:34 -06:00
|
|
|
print('test passed: ' .. test.name)
|
|
|
|
passed = true
|
|
|
|
counts.tests_ok = counts.tests_ok + 1
|
2020-03-26 21:26:43 -06:00
|
|
|
end
|
2020-03-26 22:49:34 -06:00
|
|
|
counts.checks = counts.checks + (tonumber(test.private.checks) or 0)
|
|
|
|
counts.checks_ok = counts.checks_ok + (tonumber(test.private.checks_ok) or 0)
|
|
|
|
return passed
|
2020-03-26 21:26:43 -06:00
|
|
|
end
|
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
local function get_tests(test_files, counts)
|
2020-03-24 23:43:09 -06:00
|
|
|
local tests = {}
|
2021-03-06 23:07:45 -07:00
|
|
|
for _, file in ipairs(test_files) do
|
2020-03-26 21:26:43 -06:00
|
|
|
if not load_tests(file, tests) then
|
2018-07-18 12:29:13 -06:00
|
|
|
counts.file_errors = counts.file_errors + 1
|
|
|
|
end
|
|
|
|
end
|
2021-03-06 23:07:45 -07:00
|
|
|
return tests
|
|
|
|
end
|
2018-07-18 12:29:13 -06:00
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
local function filter_tests(tests, config)
|
2021-02-28 23:31:44 -07:00
|
|
|
if config.tests or config.modes then
|
2021-03-07 03:51:29 -07:00
|
|
|
for _,filter in ipairs({{'tests', 'name pattern'},{'modes', 'mode'}}) do
|
|
|
|
if config[filter[1]] and #config[filter[1]] > 0 then
|
|
|
|
print(string.format('Filtering tests by %s:', filter[2]))
|
|
|
|
for _,v in ipairs(config[filter[1]]) do
|
|
|
|
print(string.format(' %s', v))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-04-01 00:15:27 -06:00
|
|
|
local orig_length = #tests
|
|
|
|
for i = #tests, 1, -1 do
|
2021-02-28 23:31:44 -07:00
|
|
|
local remove = false
|
|
|
|
if config.modes then
|
|
|
|
remove = true
|
|
|
|
-- allow test if it matches any of the given modes
|
|
|
|
for _, mode in pairs(config.modes) do
|
|
|
|
if tests[i].config.mode == mode then
|
|
|
|
remove = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if config.tests and not remove then
|
|
|
|
remove = true
|
|
|
|
-- allow test if it matches any of the given patterns
|
|
|
|
for _, pattern in pairs(config.tests) do
|
|
|
|
if tests[i].name:match(pattern) then
|
|
|
|
remove = false
|
|
|
|
break
|
|
|
|
end
|
2020-04-01 00:15:27 -06:00
|
|
|
end
|
|
|
|
end
|
2021-02-28 23:31:44 -07:00
|
|
|
if remove then table.remove(tests, i) end
|
2020-04-01 00:15:27 -06:00
|
|
|
end
|
|
|
|
print('Selected tests: ' .. #tests .. '/' .. orig_length)
|
|
|
|
end
|
2021-03-06 23:07:45 -07:00
|
|
|
|
|
|
|
local status = {}
|
2021-03-22 11:06:03 -06:00
|
|
|
if config.resume then
|
2021-03-06 23:07:45 -07:00
|
|
|
status = load_test_status() or status
|
|
|
|
for i = #tests, 1, -1 do
|
|
|
|
local test = tests[i]
|
|
|
|
if not status[test.full_name] then
|
|
|
|
status[test.full_name] = TestStatus.PENDING
|
|
|
|
elseif status[test.full_name] ~= TestStatus.PENDING then
|
2021-03-20 11:29:30 -06:00
|
|
|
print(('skipping test: %s: state = %s'):format(
|
2021-03-06 23:07:45 -07:00
|
|
|
test.name, status[test.full_name]))
|
|
|
|
table.remove(tests, i)
|
|
|
|
end
|
2020-03-24 23:43:09 -06:00
|
|
|
end
|
|
|
|
end
|
2021-03-06 23:07:45 -07:00
|
|
|
|
2020-04-05 21:12:31 -06:00
|
|
|
sort_tests(tests)
|
2021-03-06 23:07:45 -07:00
|
|
|
return status
|
|
|
|
end
|
2020-03-24 23:43:09 -06:00
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
local function run_tests(tests, status, counts)
|
2021-03-07 03:51:29 -07:00
|
|
|
print(('Running %d tests'):format(#tests))
|
2020-03-24 23:43:09 -06:00
|
|
|
for _, test in pairs(tests) do
|
2020-04-05 21:12:31 -06:00
|
|
|
MODE_NAVIGATE_FNS[test.config.mode]()
|
2020-03-26 22:49:34 -06:00
|
|
|
local passed = run_test(test, status, counts)
|
|
|
|
status[test.full_name] = passed and TestStatus.PASSED or TestStatus.FAILED
|
|
|
|
save_test_status(status)
|
2020-03-24 23:43:09 -06:00
|
|
|
end
|
|
|
|
|
2021-03-23 20:11:48 -06:00
|
|
|
local function print_summary_line(ok, message)
|
|
|
|
local print_fn = print
|
|
|
|
if not ok then
|
|
|
|
status['*'] = TestStatus.FAILED
|
|
|
|
print_fn = dfhack.printerr
|
|
|
|
end
|
|
|
|
print_fn(message)
|
|
|
|
end
|
|
|
|
|
|
|
|
status['*'] = status['*'] or TestStatus.PASSED
|
2018-07-18 12:29:13 -06:00
|
|
|
print('\nTest summary:')
|
2021-03-23 20:11:48 -06:00
|
|
|
print_summary_line(counts.tests_ok == counts.tests,
|
|
|
|
('%d/%d tests passed'):format(counts.tests_ok, counts.tests))
|
|
|
|
print_summary_line(counts.checks_ok == counts.checks,
|
|
|
|
('%d/%d checks passed'):format(counts.checks_ok, counts.checks))
|
|
|
|
print_summary_line(counts.file_errors == 0,
|
|
|
|
('%d test files failed to load'):format(counts.file_errors))
|
|
|
|
|
|
|
|
save_test_status(status)
|
2018-07-18 12:29:13 -06:00
|
|
|
end
|
|
|
|
|
2021-03-06 23:07:45 -07:00
|
|
|
local function main(args)
|
2021-03-22 11:06:03 -06:00
|
|
|
local help, resume, test_dir, mode_filter, test_filter =
|
2021-03-06 23:07:45 -07:00
|
|
|
false, false, nil, {}, {}
|
2021-03-07 03:51:29 -07:00
|
|
|
local other_args = utils.processArgsGetopt(args, {
|
2021-03-06 23:07:45 -07:00
|
|
|
{'h', 'help', handler=function() help = true end},
|
|
|
|
{'d', 'test_dir', hasArg=true,
|
|
|
|
handler=function(arg) test_dir = arg end},
|
|
|
|
{'m', 'modes', hasArg=true,
|
|
|
|
handler=function(arg) mode_filter = arg:split(',') end},
|
2021-03-22 11:06:03 -06:00
|
|
|
{'r', 'resume', handler=function() resume = true end},
|
2021-03-06 23:07:45 -07:00
|
|
|
{'t', 'tests', hasArg=true,
|
|
|
|
handler=function(arg) test_filter = arg:split(',') end},
|
|
|
|
})
|
|
|
|
|
|
|
|
if help then print(help_text) return end
|
|
|
|
|
2021-03-07 09:51:02 -07:00
|
|
|
local done_command = table.concat(other_args, ' ')
|
2021-03-06 23:07:45 -07:00
|
|
|
local config = load_test_config(CONFIG_FILE)
|
|
|
|
|
|
|
|
-- override config with any params specified on the commandline
|
|
|
|
if test_dir then config.test_dir = test_dir end
|
2021-03-22 11:06:03 -06:00
|
|
|
if resume then config.resume = true end
|
2021-03-06 23:07:45 -07:00
|
|
|
if #mode_filter > 0 then config.modes = mode_filter end
|
|
|
|
if #test_filter > 0 then config.tests = test_filter end
|
2021-03-07 09:51:02 -07:00
|
|
|
if #done_command > 0 then config.done_command = done_command end
|
2021-03-06 23:07:45 -07:00
|
|
|
|
|
|
|
if not dfhack.filesystem.isdir(config.test_dir) then
|
|
|
|
qerror(('Invalid test folder: "%s"'):format(config.test_dir))
|
|
|
|
end
|
|
|
|
|
|
|
|
local counts = {
|
|
|
|
tests = 0,
|
|
|
|
tests_ok = 0,
|
|
|
|
checks = 0,
|
|
|
|
checks_ok = 0,
|
|
|
|
file_errors = 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
local test_files = get_test_files(config.test_dir)
|
|
|
|
local tests = get_tests(test_files, counts)
|
|
|
|
local status = filter_tests(tests, config)
|
|
|
|
|
|
|
|
script.start(function()
|
|
|
|
dfhack.call_with_finalizer(1, true,
|
2021-03-07 09:51:02 -07:00
|
|
|
finish_tests, config.done_command,
|
2021-03-06 23:07:45 -07:00
|
|
|
run_tests, tests, status, counts)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
if not dfhack_flags.module then
|
|
|
|
main({...})
|
|
|
|
end
|