diff --git a/docs/changelog.txt b/docs/changelog.txt index 5433e719e..fc1bf6e36 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -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 diff --git a/plugins/lua/workflow.lua b/plugins/lua/workflow.lua index 9122f290d..bdcd02bcb 100644 --- a/plugins/lua/workflow.lua +++ b/plugins/lua/workflow.lua @@ -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 @@ -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 diff --git a/test/main.lua b/test/main.lua index 83a35d165..be3993fb4 100644 --- a/test/main.lua +++ b/test/main.lua @@ -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 @@ -153,6 +163,7 @@ function build_test_env() }, expect = {}, delay = delay, + require = clean_require, } local private = { checks = 0, @@ -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 @@ -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 @@ -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)) diff --git a/test/plugins/workflow.lua b/test/plugins/workflow.lua new file mode 100644 index 000000000..af8d32793 --- /dev/null +++ b/test/plugins/workflow.lua @@ -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 diff --git a/test/test.lua b/test/test.lua new file mode 100644 index 000000000..11f038d66 --- /dev/null +++ b/test/test.lua @@ -0,0 +1,3 @@ +function test.internal_in_test() + expect.true_(dfhack.internal.IN_TEST) +end