From 91fad90167b18c39fe26473236180b3d5f0b95e9 Mon Sep 17 00:00:00 2001 From: lethosor Date: Wed, 1 Apr 2020 00:26:51 -0400 Subject: [PATCH] Make test base folder customizable, clean up, stop always installing test folder --- CMakeLists.txt | 1 - test/main.lua | 24 +++++++++++++++++++++--- travis/run-tests.py | 13 +++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4eb8e5459..3c0344ec3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -413,7 +413,6 @@ file(WRITE "${CMAKE_BINARY_DIR}/dfhack_setarch.txt" ${DFHACK_SETARCH}) install(FILES "${CMAKE_BINARY_DIR}/dfhack_setarch.txt" DESTINATION "${DFHACK_DATA_DESTINATION}") install(DIRECTORY dfhack-config/ DESTINATION dfhack-config/default) -install(DIRECTORY test DESTINATION "${DFHACK_DATA_DESTINATION}") # build the plugins if(BUILD_PLUGINS) diff --git a/test/main.lua b/test/main.lua index 6dfed1d92..1f72fd723 100644 --- a/test/main.lua +++ b/test/main.lua @@ -5,6 +5,7 @@ local utils = require 'utils' local args = {...} local done_command = args[1] +local CONFIG_FILE = 'test_config.json' local STATUS_FILE = 'test_status.json' local TestStatus = { PENDING = 'pending', @@ -68,6 +69,22 @@ function delay(frames) script.sleep(frames, 'frames') end +function load_test_config(config_file) + local config = {} + if dfhack.filesystem.isfile(config_file) then + config = json.decode_file(config_file) + end + + if not config.test_dir then + config.test_dir = dfhack.getHackPath() .. 'scripts/test' + end + if not dfhack.filesystem.isdir(config.test_dir) then + error('Invalid test folder: ' .. config.test_dir) + end + + return config +end + function build_test_env() local env = { test = utils.OrderedTable(), @@ -107,9 +124,9 @@ function build_test_env() return env, private end -function get_test_files() +function get_test_files(test_dir) local files = {} - for _, entry in ipairs(dfhack.filesystem.listdir_recursive(dfhack.getHackPath() .. 'test')) do + for _, entry in ipairs(dfhack.filesystem.listdir_recursive(test_dir)) do if not entry.isdir and not entry.path:match('main.lua') then table.insert(files, entry.path) end @@ -188,7 +205,8 @@ function run_test(test, status, counts) end function main() - local files = get_test_files() + local config = load_test_config(CONFIG_FILE) + local files = get_test_files(config.test_dir) local counts = { tests = 0, diff --git a/travis/run-tests.py b/travis/run-tests.py index 029c48abd..fd15b5d93 100644 --- a/travis/run-tests.py +++ b/travis/run-tests.py @@ -15,12 +15,19 @@ parser.add_argument('--keep-status', action='store_true', help='Do not delete final status file') parser.add_argument('--no-quit', action='store_true', help='Do not quit DF when done') +parser.add_argument('--test-dir', '--test-folder', + help='Base test folder (default: df_folder/test)') args = parser.parse_args() if (not sys.stdin.isatty() or not sys.stdout.isatty() or not sys.stderr.isatty()) and not args.headless: print('WARN: no TTY detected, enabling headless mode') args.headless = True +if args.test_dir is not None: + args.test_dir = os.path.normpath(os.path.join(os.getcwd(), args.test_dir)) + if not os.path.isdir(args.test_dir): + print('ERROR: invalid test folder: %r' % args.test_dir) + MAX_TRIES = 5 dfhack = 'Dwarf Fortress.exe' if sys.platform == 'win32' else './dfhack' @@ -66,6 +73,12 @@ with open(test_init_file, 'w') as f: test/main "lua scr.breakdown_level=df.interface_breakdown_types.%s" ''' % ('NONE' if args.no_quit else 'QUIT')) +test_config_file = 'test_config.json' +with open(test_config_file, 'w') as f: + json.dump({ + 'test_dir': args.test_dir, + }, f) + try: with open(init_txt_path, 'w') as f: f.write(init_contents)