From 98b707d44496ba7ff3b78e84f560527a4ec6d939 Mon Sep 17 00:00:00 2001 From: myk002 Date: Mon, 19 Jul 2021 10:50:16 -0700 Subject: [PATCH] ensure active orders are restored after tests --- test/plugins/orders.lua | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/test/plugins/orders.lua b/test/plugins/orders.lua index 53b084f18..e07bdc032 100644 --- a/test/plugins/orders.lua +++ b/test/plugins/orders.lua @@ -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')