Skip to content

Commit

Permalink
Set dfhack.internal.IN_TEST flag when running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lethosor committed Dec 16, 2020
1 parent cdfdfb0 commit d3aeca4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions test/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function test.internal_in_test()
expect.true_(dfhack.internal.IN_TEST)
end

0 comments on commit d3aeca4

Please sign in to comment.