|
|
@ -1,11 +1,12 @@
|
|
|
|
-- DFHack developer test harness
|
|
|
|
-- DFHack developer test harness
|
|
|
|
--@ module = true
|
|
|
|
--@ module = true
|
|
|
|
|
|
|
|
|
|
|
|
local expect = require 'test_util.expect'
|
|
|
|
local expect = require('test_util.expect')
|
|
|
|
local json = require 'json'
|
|
|
|
local helpdb = require('helpdb')
|
|
|
|
local mock = require 'test_util.mock'
|
|
|
|
local json = require('json')
|
|
|
|
local script = require 'gui.script'
|
|
|
|
local mock = require('test_util.mock')
|
|
|
|
local utils = require 'utils'
|
|
|
|
local script = require('gui.script')
|
|
|
|
|
|
|
|
local utils = require('utils')
|
|
|
|
|
|
|
|
|
|
|
|
local help_text =
|
|
|
|
local help_text =
|
|
|
|
[====[
|
|
|
|
[====[
|
|
|
@ -13,49 +14,59 @@ local help_text =
|
|
|
|
test
|
|
|
|
test
|
|
|
|
====
|
|
|
|
====
|
|
|
|
|
|
|
|
|
|
|
|
Run DFHack tests.
|
|
|
|
Tags: dev
|
|
|
|
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
Command: "test"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Run DFHack regression tests.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Discover DFHack functionality that has broken due to recent changes in DF or DFHack.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Usage
|
|
|
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
|
|
|
|
test [<options>] [<done_command>]
|
|
|
|
test [<options>] [<done_command>]
|
|
|
|
|
|
|
|
|
|
|
|
If a done_command is specified, it will be run after the tests complete.
|
|
|
|
If a done_command is specified, it will be run after the tests complete.
|
|
|
|
|
|
|
|
|
|
|
|
Options:
|
|
|
|
Options
|
|
|
|
|
|
|
|
-------
|
|
|
|
-h, --help display this help message and exit.
|
|
|
|
|
|
|
|
-d, --test_dir specifies which directory to look in for tests. defaults to
|
|
|
|
-d, --test_dir specifies which directory to look in for tests. defaults to
|
|
|
|
the "hack/scripts/test" folder in your DF installation.
|
|
|
|
the "hack/scripts/test" folder in your DF installation.
|
|
|
|
-m, --modes only run tests in the given comma separated list of modes.
|
|
|
|
-m, --modes only run tests in the given comma separated list of modes.
|
|
|
|
see the next section for a list of valid modes. if not
|
|
|
|
see the next section for a list of valid modes. if not
|
|
|
|
specified, the tests are not filtered by modes.
|
|
|
|
specified, the tests are not filtered by modes.
|
|
|
|
-r, --resume skip tests that have already been run. remove the
|
|
|
|
-r, --resume skip tests that have already been run. remove the
|
|
|
|
test_status.json file to reset the record.
|
|
|
|
test_status.json file to reset the record.
|
|
|
|
-s, --save_dir the save folder to load for "fortress" mode tests. this
|
|
|
|
-s, --save_dir the save folder to load for "fortress" mode tests. this
|
|
|
|
save is only loaded if a fort is not already loaded when
|
|
|
|
save is only loaded if a fort is not already loaded when
|
|
|
|
a "fortress" mode test is run. if not specified, defaults to
|
|
|
|
a "fortress" mode test is run. if not specified, defaults to
|
|
|
|
'region1'.
|
|
|
|
'region1'.
|
|
|
|
-t, --tests only run tests that match one of the comma separated list of
|
|
|
|
-t, --tests only run tests that match one of the comma separated list of
|
|
|
|
patterns. if not specified, no tests are filtered.
|
|
|
|
patterns. if not specified, no tests are filtered and all tessts
|
|
|
|
|
|
|
|
are run.
|
|
|
|
Modes:
|
|
|
|
|
|
|
|
|
|
|
|
Modes
|
|
|
|
none the test can be run on any screen
|
|
|
|
-----
|
|
|
|
title the test must be run on the DF title screen. note that if the game
|
|
|
|
|
|
|
|
has a map loaded, "title" mode tests cannot be run
|
|
|
|
none the test can be run on any screen
|
|
|
|
fortress the test must be run while a map is loaded. if the game is
|
|
|
|
title the test must be run on the DF title screen. note that if the game
|
|
|
|
currently on the title screen, the save specified by the save_dir
|
|
|
|
has a map loaded, "title" mode tests cannot be run
|
|
|
|
parameter will be loaded.
|
|
|
|
fortress the test must be run while a map is loaded. if the game is
|
|
|
|
|
|
|
|
currently on the title screen, the save specified by the save_dir
|
|
|
|
Examples:
|
|
|
|
parameter will be loaded.
|
|
|
|
|
|
|
|
|
|
|
|
test runs all tests
|
|
|
|
Examples
|
|
|
|
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 runs all tests
|
|
|
|
test -t quickfort runs quickfort tests
|
|
|
|
test -r runs all tests that haven't been run before
|
|
|
|
test -d /path/to/dfhack-scripts/repo/test
|
|
|
|
test -m none runs tests that don't need the game to be in a
|
|
|
|
runs tests in your dev scripts repo
|
|
|
|
specific mode
|
|
|
|
|
|
|
|
test -t quickfort runs quickfort tests
|
|
|
|
|
|
|
|
test -d /path/to/dfhack-scripts/repo/test
|
|
|
|
|
|
|
|
runs tests in your dev scripts repo
|
|
|
|
|
|
|
|
|
|
|
|
Default values for the options may be set in a file named test_config.json in
|
|
|
|
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
|
|
|
|
your DF folder. Options with comma-separated values should be written as json
|
|
|
@ -352,33 +363,46 @@ local function load_tests(file, tests)
|
|
|
|
if not code then
|
|
|
|
if not code then
|
|
|
|
dfhack.printerr('Failed to load file: ' .. tostring(err))
|
|
|
|
dfhack.printerr('Failed to load file: ' .. tostring(err))
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
else
|
|
|
|
end
|
|
|
|
dfhack.internal.IN_TEST = true
|
|
|
|
dfhack.internal.IN_TEST = true
|
|
|
|
local ok, err = dfhack.pcall(code)
|
|
|
|
local ok, err = dfhack.pcall(code)
|
|
|
|
dfhack.internal.IN_TEST = false
|
|
|
|
dfhack.internal.IN_TEST = false
|
|
|
|
if not ok then
|
|
|
|
if not ok then
|
|
|
|
dfhack.printerr('Error when running file: ' .. tostring(err))
|
|
|
|
dfhack.printerr('Error when running file: ' .. tostring(err))
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if not MODES[env.config.mode] then
|
|
|
|
|
|
|
|
dfhack.printerr('Invalid config.mode: ' .. tostring(env.config.mode))
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if not env.config.targets then
|
|
|
|
|
|
|
|
dfhack.printerr('Test target(s) not specified in ' .. file)
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
local targets = type(env.config.targets) == table and env.config.targets or {env.config.targets}
|
|
|
|
|
|
|
|
for _,target in ipairs(targets) do
|
|
|
|
|
|
|
|
if target == 'core' then goto continue end
|
|
|
|
|
|
|
|
if type(target) ~= 'string' or not helpdb.is_entry(target) or
|
|
|
|
|
|
|
|
helpdb.get_entry_tags(target).unavailable
|
|
|
|
|
|
|
|
then
|
|
|
|
|
|
|
|
dfhack.printerr('Skipping tests for unavailable target: ' .. target)
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
else
|
|
|
|
|
|
|
|
if not MODES[env.config.mode] then
|
|
|
|
|
|
|
|
dfhack.printerr('Invalid config.mode: ' .. tostring(env.config.mode))
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
for name, test_func in pairs(env.test) do
|
|
|
|
|
|
|
|
if env.config.wrapper then
|
|
|
|
|
|
|
|
local fn = test_func
|
|
|
|
|
|
|
|
test_func = function() env.config.wrapper(fn) end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
local test_data = {
|
|
|
|
|
|
|
|
full_name = short_filename .. ':' .. name,
|
|
|
|
|
|
|
|
func = test_func,
|
|
|
|
|
|
|
|
private = env_private,
|
|
|
|
|
|
|
|
config = env.config,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
test_data.name = test_data.full_name:gsub('test/', ''):gsub('.lua', '')
|
|
|
|
|
|
|
|
table.insert(tests, test_data)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
::continue::
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
for name, test_func in pairs(env.test) do
|
|
|
|
|
|
|
|
if env.config.wrapper then
|
|
|
|
|
|
|
|
local fn = test_func
|
|
|
|
|
|
|
|
test_func = function() env.config.wrapper(fn) end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
local test_data = {
|
|
|
|
|
|
|
|
full_name = short_filename .. ':' .. name,
|
|
|
|
|
|
|
|
func = test_func,
|
|
|
|
|
|
|
|
private = env_private,
|
|
|
|
|
|
|
|
config = env.config,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
test_data.name = test_data.full_name:gsub('test/', ''):gsub('.lua', '')
|
|
|
|
|
|
|
|
table.insert(tests, test_data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -575,7 +599,7 @@ local function dump_df_state()
|
|
|
|
enabler = {
|
|
|
|
enabler = {
|
|
|
|
fps = df.global.enabler.fps,
|
|
|
|
fps = df.global.enabler.fps,
|
|
|
|
gfps = df.global.enabler.gfps,
|
|
|
|
gfps = df.global.enabler.gfps,
|
|
|
|
fullscreen = df.global.enabler.fullscreen,
|
|
|
|
fullscreen_state = df.global.enabler.fullscreen_state.whole,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
gps = {
|
|
|
|
gps = {
|
|
|
|
dimx = df.global.gps.dimx,
|
|
|
|
dimx = df.global.gps.dimx,
|
|
|
|