diff --git a/busted/core.lua b/busted/core.lua index a00912db..6250e108 100644 --- a/busted/core.lua +++ b/busted/core.lua @@ -79,7 +79,7 @@ return function() end info.traceback = debug.traceback('', level) - info.message = msg + info.message = tostring(msg) local file = busted.getFile(element) return file and file.getTrace(file.name, info) or trimTrace(info) diff --git a/busted/outputHandlers/json.lua b/busted/outputHandlers/json.lua index 880e639d..97a07f37 100644 --- a/busted/outputHandlers/json.lua +++ b/busted/outputHandlers/json.lua @@ -7,13 +7,21 @@ return function(options) local handler = require 'busted.outputHandlers.base'() handler.suiteEnd = function() - io_write(json.encode({ + local error_info = { pendings = handler.pendings, successes = handler.successes, failures = handler.failures, errors = handler.errors, duration = handler.getDuration() - })) + } + local ok, result = pcall(json.encode, error_info) + + if ok then + io_write(result) + else + io_write("Failed to encode test results to json: " .. result) + end + io_write("\n") io_flush()