Skip to content

Commit

Permalink
Fixed issue where json fails to encode and then no errors are output
Browse files Browse the repository at this point in the history
  • Loading branch information
svermeulen committed Sep 18, 2023
1 parent 0c5dcb1 commit 8b0a5d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion busted/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 12 additions & 2 deletions busted/outputHandlers/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ 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(function()
return json.encode(error_info)
end)

if ok then
io_write(result)
else
io_write("Failed to encode test results to json: " .. result)
end

io_write("\n")
io_flush()

Expand Down

0 comments on commit 8b0a5d0

Please sign in to comment.