From 8a6bb2c8370b1fbe8fde6df3f36751d56c5b2e3a Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Wed, 24 Oct 2012 11:31:30 -0400 Subject: [PATCH] Add stack traces to errors in failing tests --- tests/testfx.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/testfx.lua b/tests/testfx.lua index d7b9fa37..ce281240 100644 --- a/tests/testfx.lua +++ b/tests/testfx.lua @@ -201,8 +201,13 @@ -- local _OS_host = _OS - -- TODO: move this out to the test suite's premake4.lua so - -- this file can be reused for other projects + local function error_handler(err) + 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) _ACTION = "test" _ARGS = { } @@ -221,7 +226,7 @@ test.value_closedfile = false if suite.setup then - return pcall(suite.setup) + return xpcall(suite.setup, error_handler) else return true end @@ -230,13 +235,13 @@ local function test_run(suite, fn) io.capture() - return pcall(fn) + return xpcall(fn, error_handler) end local function test_teardown(suite, fn) if suite.teardown then - return pcall(suite.teardown) + return xpcall(suite.teardown, error_handler) else return true end