Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions test/plugins/infinite-sky.lua
Original file line number Diff line number Diff line change
@@ -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
49 changes: 49 additions & 0 deletions test/plugins/preserve-rooms.lua
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 additions & 0 deletions test/plugins/probe.lua
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions test/plugins/spectate.lua
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions test/plugins/tweak.lua
Original file line number Diff line number Diff line change
@@ -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
Loading