only run tests for registered and available targets

develop
Myk Taylor 2023-08-03 20:16:48 -07:00
parent 6c4662d12c
commit 43a1fdc69c
No known key found for this signature in database
1 changed files with 92 additions and 68 deletions

@ -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,48 +14,58 @@ 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 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 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 has a map loaded, "title" mode tests cannot be run
fortress the test must be run while a map is loaded. if the game is 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 currently on the title screen, the save specified by the save_dir
parameter will be loaded. parameter will be loaded.
Examples: Examples
--------
test runs all tests test runs all tests
test -r runs all tests that haven't been run before 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 test -m none runs tests that don't need the game to be in a
specific mode specific mode
test -t quickfort runs quickfort tests test -t quickfort runs quickfort tests
test -d /path/to/dfhack-scripts/repo/test test -d /path/to/dfhack-scripts/repo/test
runs tests in your dev scripts repo 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
@ -352,18 +363,33 @@ 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 return false
else end
if not MODES[env.config.mode] then if not MODES[env.config.mode] then
dfhack.printerr('Invalid config.mode: ' .. tostring(env.config.mode)) dfhack.printerr('Invalid config.mode: ' .. tostring(env.config.mode))
return false return false
end 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
end
::continue::
end
for name, test_func in pairs(env.test) do for name, test_func in pairs(env.test) do
if env.config.wrapper then if env.config.wrapper then
local fn = test_func local fn = test_func
@ -378,8 +404,6 @@ local function load_tests(file, tests)
test_data.name = test_data.full_name:gsub('test/', ''):gsub('.lua', '') test_data.name = test_data.full_name:gsub('test/', ''):gsub('.lua', '')
table.insert(tests, test_data) table.insert(tests, test_data)
end end
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,