Merge remote-tracking branch 'lethosor/fix-workflow-mill' into develop

develop
lethosor 2020-12-16 13:15:22 -05:00
commit c5816fd29f
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
5 changed files with 38 additions and 8 deletions

@ -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`: 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 - `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`) - `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`` - `zone`: fixed an issue causing the ``enumnick`` subcommand to run when attempting to run ``assign``, ``unassign``, or ``slaughter``
## Misc Improvements ## Misc Improvements

@ -196,27 +196,24 @@ function job_outputs.MakeCrafts(callback, job)
end end
local plant_products = { local plant_products = {
BrewDrink = 'DRINK',
MillPlants = 'MILL', MillPlants = 'MILL',
ProcessPlants = 'THREAD', ProcessPlants = 'THREAD',
ProcessPlantsBag = 'LEAVES',
ProcessPlantsBarrel = 'EXTRACT_BARREL', ProcessPlantsBarrel = 'EXTRACT_BARREL',
ProcessPlantsVial = 'EXTRACT_VIAL', ProcessPlantsVial = 'EXTRACT_VIAL',
ExtractFromPlants = 'EXTRACT_STILL_VIAL', ExtractFromPlants = 'EXTRACT_STILL_VIAL',
} }
for job,flag in pairs(plant_products) do for job,flag in pairs(plant_products) do
local ttag = 'type_'..string.lower(flag) local tag = string.lower(flag)
local itag = 'idx_'..string.lower(flag)
job_outputs[job] = function(callback, job) job_outputs[job] = function(callback, job)
local mat_type, mat_index = -1, -1 local mat_type, mat_index = -1, -1
local seed_type, seed_index = -1, -1 local seed_type, seed_index = -1, -1
local mat = dfhack.matinfo.decode(job.job_items[0]) local mat = dfhack.matinfo.decode(job.job_items[0])
if mat and mat.plant and mat.plant.flags[flag] then if mat and mat.plant and mat.plant.flags[flag] then
mat_type = mat.plant.material_defs[ttag] mat_type = mat.plant.material_defs.type[tag]
mat_index = mat.plant.material_defs[itag] mat_index = mat.plant.material_defs.idx[tag]
seed_type = mat.plant.material_defs['type_seed'] seed_type = mat.plant.material_defs.type.seed
seed_index = mat.plant.material_defs['idx_seed'] seed_index = mat.plant.material_defs.idx.seed
end end
local mat_mask = { } local mat_mask = { }
if flag ~= 'LEAVES' then if flag ~= 'LEAVES' then
@ -358,4 +355,10 @@ function listWeakenedConstraints(outputs)
return variants return variants
end end
if dfhack.internal.IN_TEST then
test_data = {
job_outputs = job_outputs,
}
end
return _ENV return _ENV

@ -104,6 +104,16 @@ function delay(frames)
script.sleep(frames, 'frames') script.sleep(frames, 'frames')
end 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() function ensure_title_screen()
if df.viewscreen_titlest:is_instance(dfhack.gui.getCurViewscreen()) then if df.viewscreen_titlest:is_instance(dfhack.gui.getCurViewscreen()) then
return return
@ -153,6 +163,7 @@ function build_test_env()
}, },
expect = {}, expect = {},
delay = delay, delay = delay,
require = clean_require,
} }
local private = { local private = {
checks = 0, checks = 0,
@ -206,6 +217,7 @@ function save_test_status(status)
end end
function finish_tests() function finish_tests()
dfhack.internal.IN_TEST = false
if done_command then if done_command then
dfhack.run_command(done_command) dfhack.run_command(done_command)
end end
@ -220,7 +232,9 @@ function load_tests(file, tests)
dfhack.printerr('Failed to load file: ' .. tostring(err)) dfhack.printerr('Failed to load file: ' .. tostring(err))
return false return false
else else
dfhack.internal.IN_TEST = true
local ok, err = pcall(code) local ok, err = pcall(code)
dfhack.internal.IN_TEST = false
if not ok then if not ok then
dfhack.printerr('Error when running file: ' .. tostring(err)) dfhack.printerr('Error when running file: ' .. tostring(err))
return false return false
@ -260,7 +274,9 @@ function run_test(test, status, counts)
test.private.checks = 0 test.private.checks = 0
test.private.checks_ok = 0 test.private.checks_ok = 0
counts.tests = counts.tests + 1 counts.tests = counts.tests + 1
dfhack.internal.IN_TEST = true
local ok, err = pcall(test.func) local ok, err = pcall(test.func)
dfhack.internal.IN_TEST = false
local passed = false local passed = false
if not ok then if not ok then
dfhack.printerr('test errored: ' .. test.name .. ': ' .. tostring(err)) dfhack.printerr('test errored: ' .. test.name .. ': ' .. tostring(err))

@ -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

@ -0,0 +1,3 @@
function test.internal_in_test()
expect.true_(dfhack.internal.IN_TEST)
end