From 569edf439585c54353b424219d4fb81569c8dea8 Mon Sep 17 00:00:00 2001 From: Alistair-Afton Date: Thu, 17 Sep 2026 13:47:11 +0200 Subject: [PATCH] test: add coverage for autolabor, cursecheck, fix-occupancy, preserve-tombs, nestboxes --- test/plugins/autolabor.lua | 37 ++++++++++++++++++++++++++++ test/plugins/cursecheck.lua | 20 +++++++++++++++ test/plugins/fix-occupancy.lua | 30 +++++++++++++++++++++++ test/plugins/nestboxes.lua | 43 +++++++++++++++++++++++++++++++++ test/plugins/preserve-tombs.lua | 34 ++++++++++++++++++++++++++ 5 files changed, 164 insertions(+) create mode 100644 test/plugins/autolabor.lua create mode 100644 test/plugins/cursecheck.lua create mode 100644 test/plugins/fix-occupancy.lua create mode 100644 test/plugins/nestboxes.lua create mode 100644 test/plugins/preserve-tombs.lua diff --git a/test/plugins/autolabor.lua b/test/plugins/autolabor.lua new file mode 100644 index 0000000000..bca5aa04f0 --- /dev/null +++ b/test/plugins/autolabor.lua @@ -0,0 +1,37 @@ +config.mode = 'fortress' +config.target = 'autolabor' + +-- autolabor enabled state and labor configs persist; leave it off and +-- restore the test labor's defaults +config.wrapper = function(test_fn) + return dfhack.with_finalize(function() + dfhack.run_command_silent('autolabor', 'MINE', 'reset') + dfhack.run_command_silent('autolabor', 'disable') + end, test_fn) +end + +function test.no_args_shows_help() + local output = dfhack.run_command_silent('autolabor') + expect.ne('', output) +end + +function test.labor_command_requires_enable() + dfhack.run_command_silent('autolabor', 'disable') + local output = dfhack.run_command_silent('autolabor', 'MINE', 'haulers') + expect.str_find('not enabled', output) +end + +function test.set_labor_mode() + dfhack.run_command_silent('autolabor', 'enable') + local output = dfhack.run_command_silent('autolabor', 'MINE', 'haulers') + expect.str_find('MINE.-haulers', output) + output = dfhack.run_command_silent('autolabor', 'MINE', 'reset') + expect.str_find('MINE.-minimum', output) +end + +function test.unknown_labor_errors() + dfhack.run_command_silent('autolabor', 'enable') + local output = dfhack.run_command_silent('autolabor', 'BOGUS_LABOR', + 'haulers') + expect.str_find('Could not find labor', output) +end diff --git a/test/plugins/cursecheck.lua b/test/plugins/cursecheck.lua new file mode 100644 index 0000000000..bd701c071a --- /dev/null +++ b/test/plugins/cursecheck.lua @@ -0,0 +1,20 @@ +config.mode = 'fortress' +config.target = 'cursecheck' + +function test.reports_map_curse_count() + local output = dfhack.run_command_silent('cursecheck') + expect.str_find('%d+ cursed creatures on map', output) +end + +function test.help_shows_usage() + local output, status = dfhack.run_command_silent('cursecheck', 'help') + expect.true_(output:find('cursecheck', 1, true) ~= nil + or output:find('Usage', 1, true) ~= nil + or output:find('usage', 1, true) ~= nil + or status ~= 0) +end + +function test.detail_still_reports_count() + local output = dfhack.run_command_silent('cursecheck', 'detail') + expect.str_find('cursed creatures on map', output) +end diff --git a/test/plugins/fix-occupancy.lua b/test/plugins/fix-occupancy.lua new file mode 100644 index 0000000000..d91b4b943d --- /dev/null +++ b/test/plugins/fix-occupancy.lua @@ -0,0 +1,30 @@ +config.mode = 'fortress' +config.target = 'fix-occupancy' + +local fo = require('plugins.fix-occupancy') + +local function any_map_pos() + local block = df.global.world.map.map_blocks[0] + return xyz2pos(block.map_pos.x + 8, block.map_pos.y + 8, + block.map_pos.z) +end + +function test.fix_map_dry_run_leaves_occupancy() + local pos = any_map_pos() + local block = dfhack.maps.getTileBlock(pos) + local before = block.occupancy[pos.x % 16][pos.y % 16].whole + fo.fix_map(true) + expect.eq(before, block.occupancy[pos.x % 16][pos.y % 16].whole) +end + +function test.fix_tile_dry_run() + local pos = any_map_pos() + fo.fix_tile(pos, true) + -- smoke: ran without error + expect.true_(true) +end + +function test.fix_map_run() + fo.fix_map(false) + expect.true_(true) +end diff --git a/test/plugins/nestboxes.lua b/test/plugins/nestboxes.lua new file mode 100644 index 0000000000..86a3f42265 --- /dev/null +++ b/test/plugins/nestboxes.lua @@ -0,0 +1,43 @@ +config.mode = 'fortress' +config.target = 'nestboxes' + +-- burrow config is persisted to the site; restore whatever was set +local saved_burrow_name + +config.wrapper = function(test_fn) + local output = dfhack.run_command_silent('nestboxes') + saved_burrow_name = output:match('inside burrow: ([^\n]+)') + return dfhack.with_finalize(function() + if saved_burrow_name then + dfhack.run_command_silent('nestboxes', 'burrow', + saved_burrow_name) + else + dfhack.run_command_silent('nestboxes', 'all') + end + end, test_fn) +end + +function test.status_reports_protection_scope() + local output = dfhack.run_command_silent('nestboxes') + expect.true_(output:find('nestboxes is', 1, true) ~= nil) + expect.true_(output:find('protecting', 1, true) ~= nil + or output:find('disabled', 1, true) ~= nil) +end + +function test.burrow_unknown_name_clears_scope() + dfhack.run_command_silent('nestboxes', 'burrow', + 'dfhack-test-nonexistent-burrow') + local output = dfhack.run_command_silent('nestboxes') + expect.true_(output:find('inside burrow', 1, true) == nil) +end + +function test.all_clears_burrow_scope() + dfhack.run_command_silent('nestboxes', 'all') + local output = dfhack.run_command_silent('nestboxes') + expect.true_(output:find('inside burrow', 1, true) == nil) +end + +function test.unknown_command_shows_usage() + local output, status = dfhack.run_command_silent('nestboxes', 'bogus') + expect.true_(output:find('nestboxes', 1, true) ~= nil or status ~= 0) +end diff --git a/test/plugins/preserve-tombs.lua b/test/plugins/preserve-tombs.lua new file mode 100644 index 0000000000..d5dfbb4dbc --- /dev/null +++ b/test/plugins/preserve-tombs.lua @@ -0,0 +1,34 @@ +config.mode = 'fortress' +config.target = 'preserve-tombs' + +-- enabled state persists; capture it and restore afterwards +local was_enabled + +config.wrapper = function(test_fn) + local output = dfhack.run_command_silent('preserve-tombs') + was_enabled = output:find('currently enabled', 1, true) ~= nil + return dfhack.with_finalize(function() + dfhack.run_command_silent(was_enabled and 'enable' or 'disable', + 'preserve-tombs') + end, test_fn) +end + +function test.status_reports_state() + dfhack.run_command_silent('disable', 'preserve-tombs') + local output = dfhack.run_command_silent('preserve-tombs') + expect.str_find('preserve%-tombs is currently disabled', output) +end + +function test.now_requires_enable() + dfhack.run_command_silent('disable', 'preserve-tombs') + local output = dfhack.run_command_silent('preserve-tombs', 'now') + expect.str_find('Cannot update', output) +end + +function test.enable_then_now() + dfhack.run_command_silent('enable', 'preserve-tombs') + local output = dfhack.run_command_silent('preserve-tombs') + expect.str_find('preserve%-tombs is currently enabled', output) + output = dfhack.run_command_silent('preserve-tombs', 'now') + expect.str_find('Updated tomb assignments', output) +end