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
60 changes: 60 additions & 0 deletions test/plugins/fastdwarf.lua
Original file line number Diff line number Diff line change
@@ -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
50 changes: 50 additions & 0 deletions test/plugins/getplants.lua
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions test/plugins/lair.lua
Original file line number Diff line number Diff line change
@@ -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
74 changes: 74 additions & 0 deletions test/plugins/pet-uncapper.lua
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions test/plugins/work-now.lua
Original file line number Diff line number Diff line change
@@ -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
Loading