Make test base folder customizable, clean up, stop always installing test folder

develop
lethosor 2020-04-01 00:26:51 -04:00
parent 4844ff5071
commit 91fad90167
3 changed files with 34 additions and 4 deletions

@ -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(FILES "${CMAKE_BINARY_DIR}/dfhack_setarch.txt" DESTINATION "${DFHACK_DATA_DESTINATION}")
install(DIRECTORY dfhack-config/ DESTINATION dfhack-config/default) install(DIRECTORY dfhack-config/ DESTINATION dfhack-config/default)
install(DIRECTORY test DESTINATION "${DFHACK_DATA_DESTINATION}")
# build the plugins # build the plugins
if(BUILD_PLUGINS) if(BUILD_PLUGINS)

@ -5,6 +5,7 @@ local utils = require 'utils'
local args = {...} local args = {...}
local done_command = args[1] local done_command = args[1]
local CONFIG_FILE = 'test_config.json'
local STATUS_FILE = 'test_status.json' local STATUS_FILE = 'test_status.json'
local TestStatus = { local TestStatus = {
PENDING = 'pending', PENDING = 'pending',
@ -68,6 +69,22 @@ function delay(frames)
script.sleep(frames, 'frames') script.sleep(frames, 'frames')
end 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() function build_test_env()
local env = { local env = {
test = utils.OrderedTable(), test = utils.OrderedTable(),
@ -107,9 +124,9 @@ function build_test_env()
return env, private return env, private
end end
function get_test_files() function get_test_files(test_dir)
local files = {} 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 if not entry.isdir and not entry.path:match('main.lua') then
table.insert(files, entry.path) table.insert(files, entry.path)
end end
@ -188,7 +205,8 @@ function run_test(test, status, counts)
end end
function main() function main()
local files = get_test_files() local config = load_test_config(CONFIG_FILE)
local files = get_test_files(config.test_dir)
local counts = { local counts = {
tests = 0, tests = 0,

@ -15,12 +15,19 @@ parser.add_argument('--keep-status', action='store_true',
help='Do not delete final status file') help='Do not delete final status file')
parser.add_argument('--no-quit', action='store_true', parser.add_argument('--no-quit', action='store_true',
help='Do not quit DF when done') 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() args = parser.parse_args()
if (not sys.stdin.isatty() or not sys.stdout.isatty() or not sys.stderr.isatty()) and not args.headless: 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') print('WARN: no TTY detected, enabling headless mode')
args.headless = True 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 MAX_TRIES = 5
dfhack = 'Dwarf Fortress.exe' if sys.platform == 'win32' else './dfhack' 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" test/main "lua scr.breakdown_level=df.interface_breakdown_types.%s"
''' % ('NONE' if args.no_quit else 'QUIT')) ''' % ('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: try:
with open(init_txt_path, 'w') as f: with open(init_txt_path, 'w') as f:
f.write(init_contents) f.write(init_contents)