From a021a74bbb5ff632d51b96a74443717f480ac9d6 Mon Sep 17 00:00:00 2001 From: Alistair-Afton Date: Thu, 17 Sep 2026 16:29:48 +0200 Subject: [PATCH] test: add in-game regression tests for five more plugins Covers fastdwarf, pet-uncapper, work-now, getplants, and lair: status/config round-trips, enable/disable toggling, argument validation, plant id listing filters, and lair occupancy flags. --- test/plugins/fastdwarf.lua | 60 ++++++++++++++++++++++++++++ test/plugins/getplants.lua | 50 +++++++++++++++++++++++ test/plugins/lair.lua | 27 +++++++++++++ test/plugins/pet-uncapper.lua | 74 +++++++++++++++++++++++++++++++++++ test/plugins/work-now.lua | 29 ++++++++++++++ 5 files changed, 240 insertions(+) create mode 100644 test/plugins/fastdwarf.lua create mode 100644 test/plugins/getplants.lua create mode 100644 test/plugins/lair.lua create mode 100644 test/plugins/pet-uncapper.lua create mode 100644 test/plugins/work-now.lua diff --git a/test/plugins/fastdwarf.lua b/test/plugins/fastdwarf.lua new file mode 100644 index 0000000000..c03011b921 --- /dev/null +++ b/test/plugins/fastdwarf.lua @@ -0,0 +1,60 @@ +config.mode = 'fortress' +config.target = 'fastdwarf' + +local function status_output() + local output, status = dfhack.run_command_silent('fastdwarf', 'status') + expect.eq(CR_OK, status) + return output +end + +function test.status_reports_state() + expect.str_find('Current state: fast = %d, teleport = %d%.', status_output()) +end + +function test.set_fast_and_tele() + local original = status_output() + + local output, status = dfhack.run_command_silent('fastdwarf', '1', '0') + expect.eq(CR_OK, status) + expect.str_find('fast = 1, teleport = 0', status_output()) + + output, status = dfhack.run_command_silent('fastdwarf', '0', '1') + expect.eq(CR_OK, status) + expect.str_find('fast = 0, teleport = 1', status_output()) + + output, status = dfhack.run_command_silent('fastdwarf', '0', '0') + expect.eq(CR_OK, status) + expect.str_find('fast = 0, teleport = 0', status_output()) + + -- restore the original speed level + local fast, tele = original:match('fast = (%d), teleport = (%d)') + dfhack.run_command_silent('fastdwarf', fast, tele) +end + +function test.tele_without_fast_arg() + -- a single argument sets fast mode only; tele defaults to 0 + dfhack.run_command_silent('fastdwarf', '1') + expect.str_find('fast = 1, teleport = 0', status_output()) + dfhack.run_command_silent('fastdwarf', '0', '0') +end + +function test.out_of_range_fast_value() + -- fast mode only goes up to 2; a rejected value must not change state + dfhack.run_command_silent('fastdwarf', '0', '0') + local _, status = dfhack.run_command_silent('fastdwarf', '3') + expect.eq(CR_WRONG_USAGE, status) + expect.str_find('fast = 0', status_output()) +end + +function test.out_of_range_tele_value() + -- tele mode is a boolean; a rejected value must not change state + dfhack.run_command_silent('fastdwarf', '0', '0') + local _, status = dfhack.run_command_silent('fastdwarf', '0', '2') + expect.eq(CR_WRONG_USAGE, status) + expect.str_find('teleport = 0', status_output()) +end + +function test.too_many_params() + local _, status = dfhack.run_command_silent('fastdwarf', '1', '0', 'extra') + expect.eq(CR_WRONG_USAGE, status) +end diff --git a/test/plugins/getplants.lua b/test/plugins/getplants.lua new file mode 100644 index 0000000000..d9535e4c99 --- /dev/null +++ b/test/plugins/getplants.lua @@ -0,0 +1,50 @@ +config.mode = 'fortress' +config.target = 'getplants' + +function test.lists_plant_ids() + local output, status = dfhack.run_command_silent('getplants') + expect.eq(CR_OK, status) + expect.str_find('Valid plant IDs:', output) + -- listings are tagged by growth form + expect.true_(output:find('%(tree%)') ~= nil or output:find('%(shrub%)') ~= nil) +end + +function test.trees_only_listing() + local output, status = dfhack.run_command_silent('getplants', '-t') + expect.eq(CR_OK, status) + expect.str_find('%(tree%)', output) + expect.nil_(output:find('%(shrub%)')) +end + +function test.shrubs_only_listing() + local output, status = dfhack.run_command_silent('getplants', '-s') + expect.eq(CR_OK, status) + expect.str_find('%(shrub%)', output) + expect.nil_(output:find('%(tree%)')) +end + +function test.conflicting_type_options() + local _, status = dfhack.run_command_silent('getplants', '-t', '-s') + expect.eq(CR_WRONG_USAGE, status) +end + +function test.conflicting_farm_options() + local _, status = dfhack.run_command_silent('getplants', '-t', '-f') + expect.eq(CR_WRONG_USAGE, status) +end + +function test.conflicting_select_options() + local _, status = dfhack.run_command_silent('getplants', '-a', '-x') + expect.eq(CR_WRONG_USAGE, status) +end + +function test.invalid_plant_id() + local output, status = dfhack.run_command_silent('getplants', 'NOT_A_REAL_PLANT') + expect.eq(CR_FAILURE, status) + expect.str_find('Invalid plant ID%(s%):', output) +end + +function test.all_with_ids_is_wrong_usage() + local _, status = dfhack.run_command_silent('getplants', '-a', 'DWARF') + expect.eq(CR_WRONG_USAGE, status) +end diff --git a/test/plugins/lair.lua b/test/plugins/lair.lua new file mode 100644 index 0000000000..2ef43db09e --- /dev/null +++ b/test/plugins/lair.lua @@ -0,0 +1,27 @@ +config.mode = 'fortress' +config.target = 'lair' + +local function any_lair_tile() + for _, block in ipairs(df.global.world.map.map_blocks) do + for x = 0, 15 do + for y = 0, 15 do + if block.occupancy[x][y].monster_lair then + return true + end + end + end + end + return false +end + +function test.set_and_reset() + local output, status = dfhack.run_command_silent('lair') + expect.eq(CR_OK, status) + expect.str_find('Map marked as lair%.', output) + expect.true_(any_lair_tile()) + + output, status = dfhack.run_command_silent('lair', 'reset') + expect.eq(CR_OK, status) + expect.str_find('Map no longer marked as lair%.', output) + expect.false_(any_lair_tile()) +end diff --git a/test/plugins/pet-uncapper.lua b/test/plugins/pet-uncapper.lua new file mode 100644 index 0000000000..ff6adec605 --- /dev/null +++ b/test/plugins/pet-uncapper.lua @@ -0,0 +1,74 @@ +config.mode = 'fortress' +config.target = 'pet-uncapper' + +local function status_output() + local output, status = dfhack.run_command_silent('pet-uncapper', 'status') + expect.eq(CR_OK, status) + return output +end + +local function get_config() + local output = status_output() + local cap = tonumber(output:match('population cap per species: (%-?%d+)')) + local freq = tonumber(output:match('updating pregnancies every (%-?%d+) ticks')) + local pregtime = tonumber(output:match('pregancies last (%-?%d+) ticks')) + return cap, freq, pregtime +end + +function test.status_reports_config() + local cap, freq, pregtime = get_config() + expect.ne(nil, cap) + expect.ne(nil, freq) + expect.ne(nil, pregtime) +end + +function test.set_cap() + local cap = get_config() + local _, status = dfhack.run_command_silent('pet-uncapper', 'cap', '42') + expect.eq(CR_OK, status) + expect.eq(42, get_config()) + dfhack.run_command_silent('pet-uncapper', 'cap', tostring(cap)) +end + +function test.set_every() + local _, freq = get_config() + local _, status = dfhack.run_command_silent('pet-uncapper', 'every', '77') + expect.eq(CR_OK, status) + local _, new_freq = get_config() + expect.eq(77, new_freq) + dfhack.run_command_silent('pet-uncapper', 'every', tostring(freq)) +end + +function test.set_pregtime() + local _, _, pregtime = get_config() + local _, status = dfhack.run_command_silent('pet-uncapper', 'pregtime', '999') + expect.eq(CR_OK, status) + local _, _, new_pregtime = get_config() + expect.eq(999, new_pregtime) + dfhack.run_command_silent('pet-uncapper', 'pregtime', tostring(pregtime)) +end + +function test.negative_values_clamp_to_zero() + local cap = get_config() + local _, status = dfhack.run_command_silent('pet-uncapper', 'cap', '-5') + expect.eq(CR_OK, status) + expect.eq(0, get_config()) + dfhack.run_command_silent('pet-uncapper', 'cap', tostring(cap)) +end + +function test.bad_command() + local _, status = dfhack.run_command_silent('pet-uncapper', 'bogus', '1') + expect.eq(CR_WRONG_USAGE, status) +end + +function test.enable_disable() + dfhack.run_command_silent('disable', 'pet-uncapper') + local output, status = dfhack.run_command_silent('pet-uncapper') + expect.eq(CR_OK, status) + expect.str_find('pet%-uncapper is not enabled', output) + + dfhack.run_command_silent('enable', 'pet-uncapper') + output = status_output() + expect.str_find('population cap per species:', output) + dfhack.run_command_silent('disable', 'pet-uncapper') +end diff --git a/test/plugins/work-now.lua b/test/plugins/work-now.lua new file mode 100644 index 0000000000..6a6155dec3 --- /dev/null +++ b/test/plugins/work-now.lua @@ -0,0 +1,29 @@ +config.mode = 'fortress' +config.target = 'work-now' + +local function status_output() + local output, status = dfhack.run_command_silent('work-now') + expect.eq(CR_OK, status) + return output +end + +function test.status_reports_enabled_state() + dfhack.run_command_silent('disable', 'work-now') + expect.str_find('work_now is not actively poking', status_output()) + + dfhack.run_command_silent('enable', 'work-now') + expect.str_find('work_now is actively poking', status_output()) + + dfhack.run_command_silent('disable', 'work-now') +end + +function test.status_subcommand() + local output, status = dfhack.run_command_silent('work-now', 'status') + expect.eq(CR_OK, status) + expect.str_find('work_now is ', output) +end + +function test.unknown_command_is_wrong_usage() + local _, status = dfhack.run_command_silent('work-now', 'bogus') + expect.eq(CR_WRONG_USAGE, status) +end