Merge pull request #3625 from myk002/myk_tests

re-enable unit tests
develop
Myk 2023-08-04 12:20:11 -07:00 committed by GitHub
commit f2a56cc1e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 65 additions and 21 deletions

@ -379,7 +379,7 @@ local function load_tests(file, tests)
dfhack.printerr('Skipping tests for unspecified target in ' .. file) dfhack.printerr('Skipping tests for unspecified target in ' .. file)
return true -- TODO: change to false once existing tests have targets specified return true -- TODO: change to false once existing tests have targets specified
end end
local targets = type(env.config.targets) == table and env.config.targets or {env.config.targets} local targets = type(env.config.target) == 'table' and env.config.target or {env.config.target}
for _,target in ipairs(targets) do for _,target in ipairs(targets) do
if target == 'core' then goto continue end if target == 'core' then goto continue end
if type(target) ~= 'string' or not helpdb.is_entry(target) or if type(target) ~= 'string' or not helpdb.is_entry(target) or

@ -992,7 +992,7 @@ function Scrollbar:onInput(keys)
return false return false
end end
if self.parent_view:getMousePos() then if self.parent_view and self.parent_view:getMousePos() then
if keys.CONTEXT_SCROLL_UP then if keys.CONTEXT_SCROLL_UP then
self.on_scroll('up_small') self.on_scroll('up_small')
return true return true

@ -789,7 +789,7 @@ function ls(filter_str, skip_tags, show_dev_commands, exclude_strs)
end end
if not show_dev_commands then if not show_dev_commands then
local dev_tags = {'dev', 'unavailable'} local dev_tags = {'dev', 'unavailable'}
if dfhack.getHideArmokTools() then if filter_str ~= 'armok' and dfhack.getHideArmokTools() then
table.insert(dev_tags, 'armok') table.insert(dev_tags, 'armok')
end end
table.insert(excludes, {tag=dev_tags}) table.insert(excludes, {tag=dev_tags})

@ -1,4 +1,4 @@
config.targets = 'core' config.target = 'core'
local function clean_path(p) local function clean_path(p)
-- todo: replace with dfhack.filesystem call? -- todo: replace with dfhack.filesystem call?

@ -1,4 +1,4 @@
config.targets = 'core' config.target = 'core'
function test.toSearchNormalized() function test.toSearchNormalized()
expect.eq(dfhack.toSearchNormalized(''), '') expect.eq(dfhack.toSearchNormalized(''), '')

@ -1,3 +1,5 @@
config.target = 'core'
function test.getCurViewscreen() function test.getCurViewscreen()
local scr = dfhack.gui.getCurViewscreen() local scr = dfhack.gui.getCurViewscreen()
local scr2 = df.global.gview.view local scr2 = df.global.gview.view
@ -18,7 +20,7 @@ function test.getViewscreenByType()
local bad_type = df.viewscreen_titlest local bad_type = df.viewscreen_titlest
if scr._type == bad_type then if scr._type == bad_type then
bad_type = df.viewscreen_optionst bad_type = df.viewscreen_dwarfmodest
end end
local scr_bad = dfhack.gui.getViewscreenByType(bad_type) local scr_bad = dfhack.gui.getViewscreenByType(bad_type)
expect.eq(scr_bad, nil) expect.eq(scr_bad, nil)

@ -1,3 +1,5 @@
config.target = 'core'
local argparse = require('argparse') local argparse = require('argparse')
local guidm = require('gui.dwarfmode') local guidm = require('gui.dwarfmode')

@ -1,3 +1,5 @@
config.target = 'core'
local gui = require('gui') local gui = require('gui')
function test.getKeyDisplay() function test.getKeyDisplay()
@ -10,6 +12,7 @@ end
function test.clear_pen() function test.clear_pen()
expect.table_eq(gui.CLEAR_PEN, { expect.table_eq(gui.CLEAR_PEN, {
tile = df.global.init.texpos_border_interior,
ch = string.byte(' '), ch = string.byte(' '),
fg = COLOR_BLACK, fg = COLOR_BLACK,
bg = COLOR_BLACK, bg = COLOR_BLACK,

@ -1,3 +1,5 @@
--config.target = 'core'
local gui = require('gui') local gui = require('gui')
local function send_keys(...) local function send_keys(...)
local keys = {...} local keys = {...}

@ -1,3 +1,5 @@
config.target = 'core'
local widgets = require('gui.widgets') local widgets = require('gui.widgets')
function test.editfield_cursor() function test.editfield_cursor()
@ -20,18 +22,18 @@ function test.editfield_cursor()
expect.eq('ones two threes', e.text) expect.eq('ones two threes', e.text)
expect.eq(5, e.cursor) expect.eq(5, e.cursor)
e:onInput{CURSOR_LEFT=true} e:onInput{KEYBOARD_CURSOR_LEFT=true}
expect.eq(4, e.cursor) expect.eq(4, e.cursor)
e:onInput{CURSOR_RIGHT=true} e:onInput{KEYBOARD_CURSOR_RIGHT=true}
expect.eq(5, e.cursor) expect.eq(5, e.cursor)
e:onInput{A_CARE_MOVE_W=true} -- e:onInput{A_CARE_MOVE_W=true}
expect.eq(1, e.cursor, 'interpret alt-left as home') -- expect.eq(1, e.cursor, 'interpret alt-left as home') -- uncomment when we have a home key
e:onInput{A_MOVE_E_DOWN=true} e:onInput{CUSTOM_CTRL_F=true}
expect.eq(6, e.cursor, 'interpret ctrl-right as goto beginning of next word') expect.eq(6, e.cursor, 'interpret Ctrl-f as goto beginning of next word')
e:onInput{A_CARE_MOVE_E=true} e:onInput{CUSTOM_CTRL_E=true}
expect.eq(16, e.cursor, 'interpret alt-right as end') expect.eq(16, e.cursor, 'interpret Ctrl-e as end')
e:onInput{A_MOVE_W_DOWN=true} e:onInput{CUSTOM_CTRL_B=true}
expect.eq(9, e.cursor, 'interpret ctrl-left as goto end of previous word') expect.eq(9, e.cursor, 'interpret Ctrl-b as goto end of previous word')
end end
function test.editfield_click() function test.editfield_click()

@ -1,3 +1,5 @@
config.target = 'core'
local gui = require('gui') local gui = require('gui')
local widgets = require('gui.widgets') local widgets = require('gui.widgets')

@ -1,3 +1,5 @@
config.target = 'core'
local gui = require('gui') local gui = require('gui')
local widgets = require('gui.widgets') local widgets = require('gui.widgets')
@ -10,7 +12,7 @@ function test.update()
expect.eq(1, s.elems_per_page) expect.eq(1, s.elems_per_page)
expect.eq(1, s.num_elems) expect.eq(1, s.num_elems)
expect.eq(0, s.bar_offset) expect.eq(0, s.bar_offset)
expect.eq(1, s.bar_height) expect.eq(2, s.bar_height)
-- top_elem, elems_per_page, num_elems -- top_elem, elems_per_page, num_elems
s:update(1, 10, 0) s:update(1, 10, 0)
@ -18,7 +20,7 @@ function test.update()
expect.eq(10, s.elems_per_page) expect.eq(10, s.elems_per_page)
expect.eq(0, s.num_elems) expect.eq(0, s.num_elems)
expect.eq(0, s.bar_offset) expect.eq(0, s.bar_offset)
expect.eq(1, s.bar_height) expect.eq(2, s.bar_height)
-- first 10 of 50 shown -- first 10 of 50 shown
s:update(1, 10, 50) s:update(1, 10, 50)

@ -1,3 +1,5 @@
config.target = 'core'
local widgets = require('gui.widgets') local widgets = require('gui.widgets')
function test.hotkeylabel_click() function test.hotkeylabel_click()

@ -1,3 +1,5 @@
config.target = 'core'
local h = require('helpdb') local h = require('helpdb')
local mock_plugin_db = { local mock_plugin_db = {

@ -1,5 +1,7 @@
-- tests misc functions added by dfhack.lua -- tests misc functions added by dfhack.lua
config.target = 'core'
function test.safe_pairs() function test.safe_pairs()
for k,v in safe_pairs(nil) do for k,v in safe_pairs(nil) do
expect.fail('nil should not be iterable') expect.fail('nil should not be iterable')

@ -1,5 +1,7 @@
-- tests print-related functions added by dfhack.lua -- tests print-related functions added by dfhack.lua
config.target = 'core'
local dfhack = dfhack local dfhack = dfhack
local mock_print = mock.func() local mock_print = mock.func()

@ -1,5 +1,7 @@
-- tests string functions added by dfhack.lua -- tests string functions added by dfhack.lua
config.target = 'core'
function test.startswith() function test.startswith()
expect.true_(('abcd'):startswith('')) expect.true_(('abcd'):startswith(''))
expect.true_(('abcd'):startswith('abc')) expect.true_(('abcd'):startswith('abc'))

@ -1,3 +1,5 @@
config.target = 'core'
local expect_raw = require('test_util.expect') local expect_raw = require('test_util.expect')
function test.str_find() function test.str_find()

@ -1,3 +1,5 @@
config.target = 'core'
local mock = require('test_util.mock') local mock = require('test_util.mock')
local test_table = { local test_table = {

@ -1,3 +1,5 @@
config.target = 'core'
local utils = require 'utils' local utils = require 'utils'
function test.OrderedTable() function test.OrderedTable()
@ -102,7 +104,7 @@ function test.df_expr_to_ref()
expect.eq(df.reinterpret_cast(df.world, utils.df_expr_to_ref('unit[0]').value), df.global.world) expect.eq(df.reinterpret_cast(df.world, utils.df_expr_to_ref('unit[0]').value), df.global.world)
expect.eq(utils.df_expr_to_ref('unit[1]'), utils.df_expr_to_ref('unit.1')) expect.eq(utils.df_expr_to_ref('unit[1]'), utils.df_expr_to_ref('unit.1'))
expect.eq(df.reinterpret_cast(df.ui, utils.df_expr_to_ref('unit[1]').value), df.global.plotinfo) expect.eq(df.reinterpret_cast(df.plotinfost, utils.df_expr_to_ref('unit[1]').value), df.global.plotinfo)
expect.error_match('index out of bounds', function() utils.df_expr_to_ref('unit.2') end) expect.error_match('index out of bounds', function() utils.df_expr_to_ref('unit.2') end)
expect.error_match('index out of bounds', function() utils.df_expr_to_ref('unit[2]') end) expect.error_match('index out of bounds', function() utils.df_expr_to_ref('unit[2]') end)

@ -1,4 +1,5 @@
config.mode = 'title' config.mode = 'title'
config.target = 'core'
local function clean_vec(vec) local function clean_vec(vec)
while #vec > 0 do while #vec > 0 do

@ -1,6 +1,8 @@
config.target = 'core'
function test.overlappingGlobals() function test.overlappingGlobals()
local globals = {} local globals = {}
for name, _ in pairs(df.global) do for name in pairs(df.global) do
local gvar = df.global:_field(name) local gvar = df.global:_field(name)
local size, addr = gvar:sizeof() local size, addr = gvar:sizeof()
table.insert(globals, { table.insert(globals, {

@ -1,3 +1,5 @@
config.target = 'core'
function test.index_name() function test.index_name()
for _, k in ipairs(df.units_other_id) do for _, k in ipairs(df.units_other_id) do
expect.eq(df.global.world.units.other[k]._kind, 'container') expect.eq(df.global.world.units.other[k]._kind, 'container')

@ -1,3 +1,5 @@
config.target = 'core'
utils = require('utils') utils = require('utils')
function with_temp_ref(...) function with_temp_ref(...)

@ -1,3 +1,5 @@
config.target = 'core'
function test.get() function test.get()
dfhack.with_temp_object(df.unit:new(), function(unit) dfhack.with_temp_object(df.unit:new(), function(unit)
expect.eq(unit:_field('hist_figure_id').ref_target, df.historical_figure) expect.eq(unit:_field('hist_figure_id').ref_target, df.historical_figure)

@ -1,3 +1,5 @@
config.target = 'core'
function test.struct() function test.struct()
expect.eq(df.coord._kind, 'struct-type') expect.eq(df.coord._kind, 'struct-type')
expect.eq(tostring(df.coord), '<type: coord>') expect.eq(tostring(df.coord), '<type: coord>')

@ -1,3 +1,5 @@
config.target = 'core'
local utils = require('utils') local utils = require('utils')
function test.unit_action_fields() function test.unit_action_fields()

@ -1,4 +1,4 @@
config.targets = 'core' config.target = 'core'
function test.internal_in_test() function test.internal_in_test()
expect.true_(dfhack.internal.IN_TEST) expect.true_(dfhack.internal.IN_TEST)