Skip to content

Commit

Permalink
Merge remote-tracking branch 'lethosor/fix-workflow-mill' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
lethosor committed Dec 16, 2020
2 parents e671e57 + d437cfe commit c5816fd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- `embark-assistant`: fixed an issue causing incursion resource matching (e.g. sand/clay) to skip some tiles if those resources were provided only through incursions
- `embark-assistant`: corrected river size determination by performing it at the MLT level rather than the world tile one
- `search`: fixed an issue where search options might not display if screens were destroyed and recreated programmatically (e.g. with `quickfort`)
- `workflow`: fixed an error when creating constraints on "mill plants" jobs and some other plant-related jobs
- `zone`: fixed an issue causing the ``enumnick`` subcommand to run when attempting to run ``assign``, ``unassign``, or ``slaughter``

## Misc Improvements
Expand Down
19 changes: 11 additions & 8 deletions plugins/lua/workflow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,27 +196,24 @@ function job_outputs.MakeCrafts(callback, job)
end

local plant_products = {
BrewDrink = 'DRINK',
MillPlants = 'MILL',
ProcessPlants = 'THREAD',
ProcessPlantsBag = 'LEAVES',
ProcessPlantsBarrel = 'EXTRACT_BARREL',
ProcessPlantsVial = 'EXTRACT_VIAL',
ExtractFromPlants = 'EXTRACT_STILL_VIAL',
}

for job,flag in pairs(plant_products) do
local ttag = 'type_'..string.lower(flag)
local itag = 'idx_'..string.lower(flag)
local tag = string.lower(flag)
job_outputs[job] = function(callback, job)
local mat_type, mat_index = -1, -1
local seed_type, seed_index = -1, -1
local mat = dfhack.matinfo.decode(job.job_items[0])
if mat and mat.plant and mat.plant.flags[flag] then
mat_type = mat.plant.material_defs[ttag]
mat_index = mat.plant.material_defs[itag]
seed_type = mat.plant.material_defs['type_seed']
seed_index = mat.plant.material_defs['idx_seed']
mat_type = mat.plant.material_defs.type[tag]
mat_index = mat.plant.material_defs.idx[tag]
seed_type = mat.plant.material_defs.type.seed
seed_index = mat.plant.material_defs.idx.seed
end
local mat_mask = { }
if flag ~= 'LEAVES' then
Expand Down Expand Up @@ -358,4 +355,10 @@ function listWeakenedConstraints(outputs)
return variants
end

if dfhack.internal.IN_TEST then
test_data = {
job_outputs = job_outputs,
}
end

return _ENV
16 changes: 16 additions & 0 deletions test/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ function delay(frames)
script.sleep(frames, 'frames')
end

function clean_require(module)
-- wrapper around require() - forces a clean load of every module to ensure
-- that modules checking for dfhack.internal.IN_TEST at load time behave
-- properly
if package.loaded[module] then
reload(module)
end
return require(module)
end

function ensure_title_screen()
if df.viewscreen_titlest:is_instance(dfhack.gui.getCurViewscreen()) then
return
Expand Down Expand Up @@ -153,6 +163,7 @@ function build_test_env()
},
expect = {},
delay = delay,
require = clean_require,
}
local private = {
checks = 0,
Expand Down Expand Up @@ -206,6 +217,7 @@ function save_test_status(status)
end

function finish_tests()
dfhack.internal.IN_TEST = false
if done_command then
dfhack.run_command(done_command)
end
Expand All @@ -220,7 +232,9 @@ function load_tests(file, tests)
dfhack.printerr('Failed to load file: ' .. tostring(err))
return false
else
dfhack.internal.IN_TEST = true
local ok, err = pcall(code)
dfhack.internal.IN_TEST = false
if not ok then
dfhack.printerr('Error when running file: ' .. tostring(err))
return false
Expand Down Expand Up @@ -260,7 +274,9 @@ function run_test(test, status, counts)
test.private.checks = 0
test.private.checks_ok = 0
counts.tests = counts.tests + 1
dfhack.internal.IN_TEST = true
local ok, err = pcall(test.func)
dfhack.internal.IN_TEST = false
local passed = false
if not ok then
dfhack.printerr('test errored: ' .. test.name .. ': ' .. tostring(err))
Expand Down
7 changes: 7 additions & 0 deletions test/plugins/workflow.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
local workflow = require('plugins.workflow')

function test.job_outputs()
for job_type in pairs(workflow.test_data.job_outputs) do
expect.true_(df.job_type[job_type], "Found unrecognized job type: " .. tostring(job_type))
end
end
3 changes: 3 additions & 0 deletions test/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function test.internal_in_test()
expect.true_(dfhack.internal.IN_TEST)
end

0 comments on commit c5816fd

Please sign in to comment.