Set dfhack.internal.IN_TEST flag when running tests

develop
lethosor 2020-12-15 21:24:38 -05:00
parent cdfdfb0eb1
commit d3aeca495f
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
2 changed files with 8 additions and 0 deletions

@ -206,6 +206,7 @@ function save_test_status(status)
end
function finish_tests()
dfhack.internal.IN_TEST = false
if done_command then
dfhack.run_command(done_command)
end
@ -220,7 +221,9 @@ function load_tests(file, tests)
dfhack.printerr('Failed to load file: ' .. tostring(err))
return false
else
dfhack.internal.IN_TEST = true
local ok, err = pcall(code)
dfhack.internal.IN_TEST = false
if not ok then
dfhack.printerr('Error when running file: ' .. tostring(err))
return false
@ -260,7 +263,9 @@ function run_test(test, status, counts)
test.private.checks = 0
test.private.checks_ok = 0
counts.tests = counts.tests + 1
dfhack.internal.IN_TEST = true
local ok, err = pcall(test.func)
dfhack.internal.IN_TEST = false
local passed = false
if not ok then
dfhack.printerr('test errored: ' .. test.name .. ': ' .. tostring(err))

@ -0,0 +1,3 @@
function test.internal_in_test()
expect.true_(dfhack.internal.IN_TEST)
end