Add stack traces to errors in failing tests

This commit is contained in:
Jason Perkins 2012-10-24 11:31:30 -04:00
parent 0e8915ec1d
commit 8a6bb2c837

View File

@ -201,8 +201,13 @@
-- --
local _OS_host = _OS local _OS_host = _OS
-- TODO: move this out to the test suite's premake4.lua so local function error_handler(err)
-- this file can be reused for other projects local msg = debug.traceback(err, 2)
msg = msg:sub(1, msg:find("[C]", 1, true) - 3)
return msg
end
local function test_setup(suite, fn) local function test_setup(suite, fn)
_ACTION = "test" _ACTION = "test"
_ARGS = { } _ARGS = { }
@ -221,7 +226,7 @@
test.value_closedfile = false test.value_closedfile = false
if suite.setup then if suite.setup then
return pcall(suite.setup) return xpcall(suite.setup, error_handler)
else else
return true return true
end end
@ -230,13 +235,13 @@
local function test_run(suite, fn) local function test_run(suite, fn)
io.capture() io.capture()
return pcall(fn) return xpcall(fn, error_handler)
end end
local function test_teardown(suite, fn) local function test_teardown(suite, fn)
if suite.teardown then if suite.teardown then
return pcall(suite.teardown) return xpcall(suite.teardown, error_handler)
else else
return true return true
end end