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
37 changes: 37 additions & 0 deletions test/plugins/autolabor.lua
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions test/plugins/cursecheck.lua
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions test/plugins/fix-occupancy.lua
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions test/plugins/nestboxes.lua
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions test/plugins/preserve-tombs.lua
Original file line number Diff line number Diff line change
@@ -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
Loading