From bb79755efd62489f98f69c0401645d1b019f2ad5 Mon Sep 17 00:00:00 2001 From: lethosor Date: Thu, 31 Aug 2023 17:41:52 -0400 Subject: [PATCH] Add test that removeJob() actually removes jobs --- test/modules/job.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/modules/job.lua diff --git a/test/modules/job.lua b/test/modules/job.lua new file mode 100644 index 000000000..518cb26a3 --- /dev/null +++ b/test/modules/job.lua @@ -0,0 +1,19 @@ +config.target = 'core' +config.mode = 'title' -- alters world state, not safe when a world is loaded + +function test.removeJob() + -- removeJob() calls DF code, so ensure that that DF code is actually running + + -- for an explanation of why this is necessary to check, + -- see https://github.com/DFHack/dfhack/pull/3713 and Job.cpp:removeJob() + + expect.nil_(df.global.world.jobs.list.next, 'job list is not empty') + + local job = df.job:new() -- will be deleted by removeJob() if the test passes + dfhack.job.linkIntoWorld(job) + expect.true_(df.global.world.jobs.list.next, 'job list is empty') + expect.eq(df.global.world.jobs.list.next.item, job, 'expected job not found in list') + + expect.true_(dfhack.job.removeJob(job)) + expect.nil_(df.global.world.jobs.list.next, 'job list is not empty after removeJob()') +end