From 7ef8f977b206f2f0db7b5700cb03807ad91acf4f Mon Sep 17 00:00:00 2001 From: Alistair-Afton Date: Thu, 17 Sep 2026 00:14:11 +0200 Subject: [PATCH] test: add coverage for spectate, preserve-rooms, infinite-sky, tweak, probe --- test/plugins/infinite-sky.lua | 29 +++++++++++++++++++ test/plugins/preserve-rooms.lua | 49 +++++++++++++++++++++++++++++++ test/plugins/probe.lua | 46 +++++++++++++++++++++++++++++ test/plugins/spectate.lua | 51 +++++++++++++++++++++++++++++++++ test/plugins/tweak.lua | 43 +++++++++++++++++++++++++++ 5 files changed, 218 insertions(+) create mode 100644 test/plugins/infinite-sky.lua create mode 100644 test/plugins/preserve-rooms.lua create mode 100644 test/plugins/probe.lua create mode 100644 test/plugins/spectate.lua create mode 100644 test/plugins/tweak.lua diff --git a/test/plugins/infinite-sky.lua b/test/plugins/infinite-sky.lua new file mode 100644 index 0000000000..a799f79ebd --- /dev/null +++ b/test/plugins/infinite-sky.lua @@ -0,0 +1,29 @@ +config.mode = 'fortress' +config.target = 'infinite-sky' + +function test.status() + local output = dfhack.run_command_silent('infinite-sky') + expect.str_find('Construction monitoring is', output) +end + +function test.help_shows_usage() + local output, status = dfhack.run_command_silent('infinite-sky', 'help') + expect.true_(output:find('infinite%-sky') ~= nil + or output:find('z%-level', 1, true) ~= nil + or output:find('Usage', 1, true) ~= nil + or output:find('usage', 1, true) ~= nil) +end + +function test.rejects_non_numeric() + local output, status = dfhack.run_command_silent('infinite-sky', 'bogus') + expect.true_(output:find('positive integer', 1, true) ~= nil + or output:find('invalid', 1, true) ~= nil + or status ~= 0) +end + +function test.rejects_non_positive() + local output, status = dfhack.run_command_silent('infinite-sky', '-3') + expect.true_(output:find('positive integer', 1, true) ~= nil + or output:find('invalid', 1, true) ~= nil + or status ~= 0) +end diff --git a/test/plugins/preserve-rooms.lua b/test/plugins/preserve-rooms.lua new file mode 100644 index 0000000000..47a350d91f --- /dev/null +++ b/test/plugins/preserve-rooms.lua @@ -0,0 +1,49 @@ +config.mode = 'fortress' +config.target = 'preserve-rooms' + +local pr = require('plugins.preserve-rooms') + +-- feature enabled state persists across sessions; restore it +local saved_features + +config.wrapper = function(test_fn) + local features = pr.preserve_rooms_getState() + saved_features = {} + for k, v in pairs(features) do + saved_features[k] = v + end + return dfhack.with_finalize(function() + for k, v in pairs(saved_features) do + pr.preserve_rooms_setFeature(v, k) + end + end, test_fn) +end + +function test.status_lists_features() + local output = dfhack.run_command_silent('preserve-rooms', 'status') + expect.str_find('track%-missions', output) + expect.str_find('track%-roles', output) +end + +function test.enable_disable_feature() + pr.preserve_rooms_setFeature(false, 'track-missions') + dfhack.run_command_silent('preserve-rooms', 'enable', 'track-missions') + local features = pr.preserve_rooms_getState() + expect.true_(features['track-missions']) + dfhack.run_command_silent('preserve-rooms', 'disable', 'track-missions') + features = pr.preserve_rooms_getState() + expect.false_(features['track-missions']) +end + +function test.enable_unknown_feature_errors() + local output, status = dfhack.run_command_silent('preserve-rooms', + 'enable', 'bogus-feature') + expect.true_(output:find('unknown feature', 1, true) ~= nil) +end + +function test.reset_feature() + dfhack.run_command_silent('preserve-rooms', 'reset', 'track-roles') + local output, status = dfhack.run_command_silent('preserve-rooms', + 'reset', 'bogus-feature') + expect.true_(output:find('unknown feature', 1, true) ~= nil) +end diff --git a/test/plugins/probe.lua b/test/plugins/probe.lua new file mode 100644 index 0000000000..bcee6a869e --- /dev/null +++ b/test/plugins/probe.lua @@ -0,0 +1,46 @@ +config.mode = 'fortress' +config.target = 'probe' + +local saved_cursor + +config.wrapper = function(test_fn) + saved_cursor = xyz2pos(df.global.cursor.x, df.global.cursor.y, + df.global.cursor.z) + return dfhack.with_finalize(function() + df.global.cursor.x = saved_cursor.x + df.global.cursor.y = saved_cursor.y + df.global.cursor.z = saved_cursor.z + end, test_fn) +end + +local function set_cursor(pos) + df.global.cursor.x = pos.x + df.global.cursor.y = pos.y + df.global.cursor.z = pos.z +end + +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.probe_requires_cursor() + set_cursor(xyz2pos(-30000, -30000, -30000)) + local output = dfhack.run_command_silent('probe') + expect.str_find('No cursor', output) +end + +function test.probe_reports_tiletype() + set_cursor(any_map_pos()) + local output = dfhack.run_command_silent('probe') + expect.str_find('tiletype', output) + expect.str_find('dig', output) +end + +function test.cprobe_requires_unit() + set_cursor(xyz2pos(-30000, -30000, -30000)) + local output = dfhack.run_command_silent('cprobe') + -- fails without a selected creature + expect.ne('', output) +end diff --git a/test/plugins/spectate.lua b/test/plugins/spectate.lua new file mode 100644 index 0000000000..e6887d1f6f --- /dev/null +++ b/test/plugins/spectate.lua @@ -0,0 +1,51 @@ +config.mode = 'fortress' +config.target = 'spectate' + +require('plugins.spectate') + +function test.status_shows_settings() + local output = dfhack.run_command_silent('spectate') + expect.true_(output:find('auto%-unpause') ~= nil + or output:find('follow%-seconds') ~= nil) +end + +function test.set_boolean() + dfhack.run_command_silent('spectate', 'set', 'auto-unpause', 'true') + local output = dfhack.run_command_silent('spectate') + expect.str_find('auto%-unpause.-true', output) + dfhack.run_command_silent('spectate', 'set', 'auto-unpause', 'false') + output = dfhack.run_command_silent('spectate') + expect.str_find('auto%-unpause.-false', output) +end + +function test.set_number() + dfhack.run_command_silent('spectate', 'set', 'follow-seconds', '42') + local output = dfhack.run_command_silent('spectate') + expect.str_find('follow%-seconds.-42', output) + dfhack.run_command_silent('spectate', 'set', 'follow-seconds', '10') +end + +function test.set_toggle_value() + dfhack.run_command_silent('spectate', 'set', 'auto-unpause', 'false') + dfhack.run_command_silent('spectate', 'set', 'auto-unpause', 'toggle') + local output = dfhack.run_command_silent('spectate') + expect.str_find('auto%-unpause.-true', output) +end + +function test.set_unknown_option() + local output, status = dfhack.run_command_silent('spectate', 'set', + 'bogus-key', '1') + expect.true_(output:find('unknown option', 1, true) ~= nil) +end + +function test.set_missing_key() + local output, status = dfhack.run_command_silent('spectate', 'set') + expect.true_(output:find('missing key', 1, true) ~= nil) +end + +function test.unknown_command_shows_usage() + local output, status = dfhack.run_command_silent('spectate', 'boguscmd') + expect.true_(output:find('status', 1, true) ~= nil + or output:find('Usage', 1, true) ~= nil + or output:find('usage', 1, true) ~= nil) +end diff --git a/test/plugins/tweak.lua b/test/plugins/tweak.lua new file mode 100644 index 0000000000..a34700e5a8 --- /dev/null +++ b/test/plugins/tweak.lua @@ -0,0 +1,43 @@ +config.mode = 'fortress' +config.target = 'tweak' + +local tweak = require('plugins.tweak') + +-- tweak enabled state is runtime-only; ensure test hooks end disabled +local touched_tweaks + +config.wrapper = function(test_fn) + touched_tweaks = {} + return dfhack.with_finalize(function() + for name in pairs(touched_tweaks) do + dfhack.run_command_silent('tweak', name, 'disable', 'quiet') + end + end, test_fn) +end + +function test.status_lists_tweaks() + local status = tweak.tweak_get_status() + expect.ne(nil, status['eggs-fertile']) + expect.ne(nil, status['fast-heat']) +end + +function test.list_output() + local output = dfhack.run_command_silent('tweak') + expect.str_find('eggs%-fertile', output) + expect.str_find('enabled', output) +end + +function test.enable_disable_tweak() + touched_tweaks['eggs-fertile'] = true + local output = dfhack.run_command_silent('tweak', 'eggs-fertile') + expect.str_find('Enabled tweak eggs%-fertile', output) + expect.true_(tweak.tweak_get_status()['eggs-fertile']) + output = dfhack.run_command_silent('tweak', 'eggs-fertile', 'disable') + expect.str_find('Disabled tweak eggs%-fertile', output) + expect.false_(tweak.tweak_get_status()['eggs-fertile']) +end + +function test.unknown_tweak_errors() + local output, status = dfhack.run_command_silent('tweak', 'bogus-tweak') + expect.str_find('Unrecognized tweak', output) +end