-
Notifications
You must be signed in to change notification settings - Fork 509
fix three plugin crash/UB bugs; test coverage for 14 plugins #5939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Alistair-Afton
wants to merge
13
commits into
DFHack:develop
Choose a base branch
from
Alistair-Afton:test-plugin-coverage-10
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0a192a7
fix strangemood crash on non-numeric --id value
Alistair-Afton 1db1882
test: add coverage for autodump, filltraffic, export-world-map, stran…
Alistair-Afton 1ae50a0
suspendmanager: fix out-of-bounds read on bare 'set'
Alistair-Afton d4e1c76
test: add coverage for liquids, tubefill, suspendmanager, 3dveins, cr…
Alistair-Afton 079d8b8
test: add coverage for flows, showmood, deramp, changelayer, changeitem
Alistair-Afton cb0b86b
fix 3dveins crash when a tile's biome cannot be resolved
Alistair-Afton 3c580f0
restore global state in test cleanup
Alistair-Afton 05b8137
use dfhack.world pause API instead of raw pause_state
Alistair-Afton 43a414a
strangemood test: validate mood job_items against vanilla request tables
Alistair-Afton 9787a8b
export-world-map: fix crash on sites with an owner of undefined race
Alistair-Afton cc0ef10
strangemood test: mirror STRANGE_MOODS caste check in unit picker
Alistair-Afton f8351ea
autodump test: use gui.dwarfmode cursor helpers
Alistair-Afton d310a26
remove duplicated timestream changelog entry
Alistair-Afton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| config.mode = 'fortress' | ||
| config.target = '3dveins' | ||
|
|
||
| function test.rewrites_veins() | ||
| local output, status = dfhack.run_command_silent('3dveins') | ||
| expect.eq(CR_OK, status) | ||
| expect.str_find('Writing tiles', output) | ||
| end | ||
|
|
||
| function test.verbose_option() | ||
| local _, status = dfhack.run_command_silent('3dveins', 'verbose') | ||
| expect.eq(CR_OK, status) | ||
| end | ||
|
|
||
| function test.bad_option_is_wrong_usage() | ||
| local _, status = dfhack.run_command_silent('3dveins', 'bogus') | ||
| expect.eq(CR_WRONG_USAGE, status) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| config.mode = 'fortress' | ||
| config.target = 'autodump' | ||
|
|
||
| local dwarfmode = require('gui.dwarfmode') | ||
|
|
||
| local function find_floor_pos() | ||
| for _, block in ipairs(df.global.world.map.map_blocks) do | ||
| for x = 0, 15 do | ||
| for y = 0, 15 do | ||
| local tt = block.tiletype[x][y] | ||
| local des = block.designation[x][y] | ||
| local occ = block.occupancy[x][y] | ||
| if df.tiletype.attrs[tt].shape == df.tiletype_shape.FLOOR | ||
| and not des.hidden and occ.building == 0 then | ||
| return block.map_pos.x + x, block.map_pos.y + y, | ||
| block.map_pos.z | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| local function set_cursor(x, y, z) | ||
| dwarfmode.setCursorPos(xyz2pos(x, y, z)) | ||
| end | ||
|
|
||
| local function clear_cursor() | ||
| dwarfmode.clearCursorPos() | ||
| end | ||
|
|
||
| local function find_dumpable_item() | ||
| for _, item in ipairs(df.global.world.items.other.IN_PLAY) do | ||
| if not item.flags.dump and not item.flags.construction | ||
| and not item.flags.in_building and not item.flags.artifact | ||
| and not item.flags.in_job and not item.flags.forbid | ||
| and not item.flags.owned and not item.flags.in_inventory then | ||
| return item | ||
| end | ||
| end | ||
| end | ||
|
|
||
| function test.dump_moves_item_to_cursor() | ||
| local x, y, z = find_floor_pos() | ||
| local item = find_dumpable_item() | ||
| expect.ne(nil, x, 'test needs a revealed floor tile') | ||
| expect.ne(nil, item, 'test needs a dumpable item') | ||
|
|
||
| return dfhack.with_finalize(function() | ||
| item.flags.dump = false | ||
| clear_cursor() | ||
| end, function() | ||
| set_cursor(x, y, z) | ||
| item.flags.dump = true | ||
|
|
||
| local _, status = dfhack.run_command_silent('autodump') | ||
| expect.eq(CR_OK, status) | ||
| -- item was teleported to the cursor and marked as dumped | ||
| expect.eq(x, item.pos.x) | ||
| expect.eq(y, item.pos.y) | ||
| expect.eq(z, item.pos.z) | ||
| expect.false_(item.flags.dump) | ||
| expect.true_(item.flags.forbid) | ||
| end) | ||
| end | ||
|
|
||
| function test.conflicting_filters_is_wrong_usage() | ||
| local output, status = dfhack.run_command_silent('autodump', 'visible', 'hidden') | ||
| expect.eq(CR_WRONG_USAGE, status) | ||
| expect.str_find("both hidden and visible", output) | ||
| end | ||
|
|
||
| function test.bad_option_is_wrong_usage() | ||
| local _, status = dfhack.run_command_silent('autodump', 'bogus') | ||
| expect.eq(CR_WRONG_USAGE, status) | ||
| end | ||
|
|
||
| function test.destroy_and_undestroy() | ||
| local item = find_dumpable_item() | ||
| expect.ne(nil, item, 'test needs a dumpable item') | ||
|
|
||
| local was_paused = dfhack.world.ReadPauseState() | ||
| return dfhack.with_finalize(function() | ||
| dfhack.world.SetPauseState(was_paused) | ||
| dfhack.run_command_silent('autodump', 'undestroy') | ||
| item.flags.dump = false | ||
| item.flags.garbage_collect = false | ||
| item.flags.forbid = false | ||
| item.flags.hidden = false | ||
| end, function() | ||
| item.flags.dump = true | ||
| -- undestroy only restores marks made in the same frame, so the | ||
| -- game must stay paused between destroy and undestroy | ||
| dfhack.world.SetPauseState(true) | ||
|
|
||
| local _, status = dfhack.run_command_silent('autodump', 'destroy') | ||
| expect.eq(CR_OK, status) | ||
| expect.true_(item.flags.garbage_collect) | ||
| expect.true_(item.flags.forbid) | ||
| expect.true_(item.flags.hidden) | ||
|
|
||
| local output, status2 = dfhack.run_command_silent('autodump', 'undestroy') | ||
| expect.eq(CR_OK, status2) | ||
| expect.str_find('unmarked for destruction', output) | ||
| expect.false_(item.flags.garbage_collect) | ||
| expect.false_(item.flags.forbid) | ||
| expect.false_(item.flags.hidden) | ||
| -- undestroy restores the pre-destroy flags, including the dump | ||
| -- flag we set ourselves | ||
| expect.true_(item.flags.dump) | ||
| end) | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| config.mode = 'fortress' | ||
| config.target = 'changeitem' | ||
|
|
||
| local function find_floor_item_pos() | ||
| for _, item in ipairs(df.global.world.items.other.IN_PLAY) do | ||
| if not item.flags.hidden and not item.flags.in_inventory | ||
| and not item.flags.in_job and not item.flags.construction then | ||
| local x, y, z = dfhack.items.getPosition(item) | ||
| if x then return item, x, y, z end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| local function set_cursor(x, y, z) | ||
| df.global.cursor:assign{x=x, y=y, z=z} | ||
| end | ||
|
|
||
| local function clear_cursor() | ||
| df.global.cursor:assign{x=-30000, y=-30000, z=-30000} | ||
| end | ||
|
|
||
| function test.here_quality_changes_item() | ||
| local item, x, y, z = find_floor_item_pos() | ||
| expect.ne(nil, item, 'test needs an item on the ground') | ||
| local orig_quality = item.quality | ||
|
|
||
| return dfhack.with_finalize(function() | ||
| item.quality = orig_quality | ||
| clear_cursor() | ||
| end, function() | ||
| set_cursor(x, y, z) | ||
| local output, status = dfhack.run_command_silent('changeitem', | ||
| 'here', 'q', '4') | ||
| expect.eq(CR_OK, status) | ||
| expect.str_find('items processed', output) | ||
| expect.eq(4, item.quality) | ||
| end) | ||
| end | ||
|
|
||
| function test.here_empty_tile_processes_nothing() | ||
| -- find a floor tile and put the cursor on it; if it happens to hold | ||
| -- items the count is still reported | ||
| local block = df.global.world.map.map_blocks[0] | ||
| local x, y, z = block.map_pos.x, block.map_pos.y, block.map_pos.z | ||
|
|
||
| return dfhack.with_finalize(clear_cursor, function() | ||
| set_cursor(x, y, z) | ||
| local output, status = dfhack.run_command_silent('changeitem', 'here') | ||
| expect.eq(CR_OK, status) | ||
| expect.str_find('items processed', output) | ||
| end) | ||
| end | ||
|
|
||
| function test.here_no_cursor_is_failure() | ||
| return dfhack.with_finalize(clear_cursor, function() | ||
| clear_cursor() | ||
| local output, status = dfhack.run_command_silent('changeitem', 'here') | ||
| expect.eq(CR_FAILURE, status) | ||
| expect.str_find('Cursor position not found', output) | ||
| end) | ||
| end | ||
|
|
||
| function test.no_selection_is_failure() | ||
| local output, status = dfhack.run_command_silent('changeitem') | ||
| expect.eq(CR_FAILURE, status) | ||
| expect.str_find('No item selected', output) | ||
| end | ||
|
|
||
| function test.material_missing_arg_is_wrong_usage() | ||
| local output, status = dfhack.run_command_silent('changeitem', 'm') | ||
| expect.eq(CR_WRONG_USAGE, status) | ||
| expect.str_find('no material specified', output) | ||
| end | ||
|
|
||
| function test.bad_quality_is_wrong_usage() | ||
| local _, status = dfhack.run_command_silent('changeitem', 'q', '9') | ||
| expect.eq(CR_WRONG_USAGE, status) | ||
| end | ||
|
|
||
| function test.bad_option_is_wrong_usage() | ||
| local _, status = dfhack.run_command_silent('changeitem', 'bogus') | ||
| expect.eq(CR_WRONG_USAGE, status) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| config.mode = 'fortress' | ||
| config.target = 'changelayer' | ||
|
|
||
| function test.no_material_is_wrong_usage() | ||
| local output, status = dfhack.run_command_silent('changelayer') | ||
| expect.eq(CR_WRONG_USAGE, status) | ||
| expect.str_find('specify a material', output) | ||
| end | ||
|
|
||
| function test.bad_material_is_failure() | ||
| local output, status = dfhack.run_command_silent('changelayer', 'BOGUSMAT') | ||
| expect.eq(CR_FAILURE, status) | ||
| expect.str_find('No such material', output) | ||
| end | ||
|
|
||
| function test.no_cursor_is_failure() | ||
| return dfhack.with_finalize(function() | ||
| df.global.cursor:assign{x=-30000, y=-30000, z=-30000} | ||
| end, function() | ||
| df.global.cursor:assign{x=-30000, y=-30000, z=-30000} | ||
| local output, status = dfhack.run_command_silent('changelayer', | ||
| 'GRANITE') | ||
| expect.eq(CR_FAILURE, status) | ||
| expect.str_find('No cursor', output) | ||
| end) | ||
| end | ||
|
|
||
| function test.help_is_wrong_usage() | ||
| local _, status = dfhack.run_command_silent('changelayer', '?') | ||
| expect.eq(CR_WRONG_USAGE, status) | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.