ensure active orders are restored after tests

develop
myk002 2021-07-19 10:50:16 -07:00
parent 37a8260c3b
commit 98b707d444
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
1 changed files with 22 additions and 2 deletions

@ -1,7 +1,27 @@
config.mode = 'fortress'
TMP_FILE_NAME = 'tmp-test'
TMP_FILE_PATH = ('dfhack-config/orders/%s.json'):format(TMP_FILE_NAME)
local FILE_PATH_PATTERN = 'dfhack-config/orders/%s.json'
local BACKUP_FILE_NAME = 'tmp-backup'
local BACKUP_FILE_PATH = FILE_PATH_PATTERN:format(BACKUP_FILE_NAME)
local TMP_FILE_NAME = 'tmp-test'
local TMP_FILE_PATH = FILE_PATH_PATTERN:format(TMP_FILE_NAME)
local function test_wrapper(test_fn)
-- save active orders
dfhack.run_command_silent{'orders', 'export', BACKUP_FILE_NAME}
return dfhack.with_finalize(
function()
-- clear test orders, restore original orders, remove temp file
dfhack.run_command_silent{'orders', 'clear'}
print('reimporting')
dfhack.run_command_silent{'orders', 'import', BACKUP_FILE_NAME}
os.remove(BACKUP_FILE_PATH)
end,
test_fn)
end
config.wrapper = test_wrapper
function run_orders_import(file_content)
local f = io.open(TMP_FILE_PATH, 'w')