forked from lunarmodules/busted
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2bdcac3
commit eb1d967
Showing
8 changed files
with
497 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
local pretty = require 'pl.pretty' | ||
|
||
return function(options, busted) | ||
local language = require('busted.languages.' .. options.language) | ||
|
||
-- options.language, options.deferPrint, options.suppressPending, options.verbose | ||
local handler = {} | ||
local tests = {} | ||
|
||
local getFullName = function(context) | ||
local parent = context.parent | ||
local names = { (context.name or context.descriptor) } | ||
|
||
while parent and (parent.name or parent.descriptor) and | ||
parent.descriptor ~= 'file' do | ||
|
||
current_context = context.parent | ||
table.insert(names, 1, parent.name or parent.descriptor) | ||
parent = busted.context.parent(parent) | ||
end | ||
|
||
return table.concat(names, ' ') | ||
end | ||
|
||
handler.testStart = function(name, parent) | ||
return nil, true | ||
end | ||
|
||
handler.testEnd = function(element, parent, status) | ||
if status == 'success' then | ||
table.insert(tests, { | ||
name = getFullName(element), | ||
success = true | ||
}) | ||
end | ||
|
||
return nil, true | ||
end | ||
|
||
handler.fileStart = function(name, parent) | ||
return nil, true | ||
end | ||
|
||
handler.fileEnd = function(name, parent) | ||
return nil, true | ||
end | ||
|
||
handler.suiteStart = function(name, parent) | ||
return nil, true | ||
end | ||
|
||
handler.suiteEnd = function(name, parent) | ||
print('1..' .. #tests) | ||
|
||
local success = 'ok %u - %s' | ||
local failure = 'not ' .. success | ||
|
||
for i,t in pairs(tests) do | ||
if t.success then | ||
print(success:format(i, t.name)) | ||
else | ||
local message = t.message | ||
|
||
if message == nil then | ||
message = 'Nil error' | ||
elseif type(message) ~= 'string' then | ||
message = pretty.write(message) | ||
end | ||
|
||
print(failure:format(i, t.name)) | ||
print('# ' .. t.elementTrace.short_src .. ' @ ' .. t.elementTrace.currentline) | ||
print('# ' .. message:gsub('\n', '\n# ' )) | ||
end | ||
end | ||
|
||
return nil, true | ||
end | ||
|
||
handler.error = function(element, parent, message, debug) | ||
table.insert(tests, { | ||
elementTrace = element.trace, | ||
name = getFullName(element), | ||
message = message, | ||
success = false | ||
}) | ||
|
||
return nil, true | ||
end | ||
|
||
return handler | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
local pretty = require 'pl.pretty' | ||
local json = require 'dkjson' | ||
|
||
return function(options, busted) | ||
-- options.language, options.deferPrint, options.suppressPending, options.verbose | ||
local handler = {} | ||
local tests = {} | ||
|
||
local getFullName = function(context) | ||
local parent = context.parent | ||
local names = { (context.name or context.descriptor) } | ||
|
||
while parent and (parent.name or parent.descriptor) and | ||
parent.descriptor ~= 'file' do | ||
|
||
current_context = context.parent | ||
table.insert(names, 1, parent.name or parent.descriptor) | ||
parent = busted.context.parent(parent) | ||
end | ||
|
||
return table.concat(names, ' ') | ||
end | ||
|
||
handler.testStart = function(name, parent) | ||
return nil, true | ||
end | ||
|
||
handler.testEnd = function(element, parent, status) | ||
table.insert(tests, { | ||
name = getFullName(element), | ||
status = status, | ||
trace = element.trace | ||
}) | ||
|
||
print(json.encode(tests[#tests])) | ||
|
||
return nil, true | ||
end | ||
|
||
handler.fileStart = function(name, parent) | ||
return nil, true | ||
end | ||
|
||
handler.fileEnd = function(name, parent) | ||
return nil, true | ||
end | ||
|
||
handler.suiteStart = function(name, parent) | ||
return nil, true | ||
end | ||
|
||
handler.suiteEnd = function(name, parent) | ||
return nil, true | ||
end | ||
|
||
handler.error = function(element, parent, message, debug) | ||
table.insert(tests, { | ||
elementTrace = element.trace, | ||
name = getFullName(element), | ||
message = message, | ||
success = false | ||
}) | ||
|
||
return nil, true | ||
end | ||
|
||
return handler | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
local xml = require 'pl.xml' | ||
local hostname = assert(io.popen('uname -n')):read('*l') | ||
|
||
return function(options, busted) | ||
-- options.language, options.deferPrint, options.suppressPending, options.verbose | ||
local node | ||
local startTime, endTime | ||
local handler = {} | ||
|
||
local getFullName = function(context) | ||
local parent = context.parent | ||
local names = { (context.name or context.descriptor) } | ||
|
||
while parent and (parent.name or parent.descriptor) and | ||
parent.descriptor ~= 'file' do | ||
|
||
current_context = context.parent | ||
table.insert(names, 1, parent.name or parent.descriptor) | ||
parent = busted.context.parent(parent) | ||
end | ||
|
||
return table.concat(names, ' ') | ||
end | ||
|
||
handler.testStart = function(name, parent) | ||
return nil, true | ||
end | ||
|
||
handler.testEnd = function(element, parent, status) | ||
node.attr.tests = node.attr.tests + 1 | ||
|
||
node:addtag('testcase', { | ||
classname = element.trace.short_src .. ':' .. element.trace.currentline, | ||
name = element.name | ||
}) | ||
|
||
if status == 'failure' then | ||
node.attr.failures = node.attr.failures + 1 | ||
end | ||
|
||
return nil, true | ||
end | ||
|
||
handler.fileStart = function(name, parent) | ||
return nil, true | ||
end | ||
|
||
handler.fileEnd = function(name, parent) | ||
return nil, true | ||
end | ||
|
||
handler.suiteStart = function(name, parent) | ||
startTime = os.clock() | ||
|
||
node = xml.new('testsuite', { | ||
tests = 0, | ||
errors = 0, | ||
failures = 0, | ||
skip = 0, | ||
header = 'Busted Suite', | ||
hostname = hostname, | ||
timestamp = os.time() | ||
}) | ||
|
||
return nil, true | ||
end | ||
|
||
handler.suiteEnd = function(name, parent) | ||
endTime = os.clock() | ||
|
||
local ms = (endTime - startTime) * 1000 | ||
node.attr.time = ms | ||
|
||
print(xml.tostring(node, '', '\t')) | ||
|
||
return nil, true | ||
end | ||
|
||
handler.error = function(element, parent, message, trace) | ||
if status == 'failure' then | ||
node.attr.errors = node.attr.errors + 1 | ||
end | ||
|
||
node:addtag('failure', { | ||
message = message | ||
}):text(trace.traceback):up() | ||
|
||
return nil, true | ||
end | ||
|
||
return handler | ||
end |
Oops, something went wrong.