Add stack traces to test error messages

Also reorder for consistency with "test failed:" messages, which are at the end
of a test's output.
develop
lethosor 2021-04-12 00:48:10 -04:00
parent 855ab1a0a3
commit 909efe71a0
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
1 changed files with 4 additions and 3 deletions

@ -243,7 +243,7 @@ local function load_tests(file, tests)
return false return false
else else
dfhack.internal.IN_TEST = true dfhack.internal.IN_TEST = true
local ok, err = pcall(code) local ok, err = dfhack.pcall(code)
dfhack.internal.IN_TEST = false dfhack.internal.IN_TEST = false
if not ok then if not ok then
dfhack.printerr('Error when running file: ' .. tostring(err)) dfhack.printerr('Error when running file: ' .. tostring(err))
@ -296,7 +296,7 @@ local function wrap_test(func)
{dfhack, 'reqscript', clean_reqscript}, {dfhack, 'reqscript', clean_reqscript},
}, },
function() function()
local ok, err = pcall(func) local ok, err = dfhack.pcall(func)
if printerr_called then if printerr_called then
return false, return false,
"dfhack.printerr was called outside of" .. "dfhack.printerr was called outside of" ..
@ -317,7 +317,8 @@ local function run_test(test, status, counts)
dfhack.internal.IN_TEST = false dfhack.internal.IN_TEST = false
local passed = false local passed = false
if not ok then if not ok then
dfhack.printerr('test errored: ' .. test.name .. ': ' .. tostring(err)) dfhack.printerr('error: ' .. tostring(err) .. '\n')
dfhack.printerr('test errored: ' .. test.name)
elseif test.private.checks ~= test.private.checks_ok then elseif test.private.checks ~= test.private.checks_ok then
dfhack.printerr('test failed: ' .. test.name) dfhack.printerr('test failed: ' .. test.name)
else else