aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-07-29 05:09:47 +0200
committerJustin M. Keyes <justinkz@gmail.com>2017-07-29 23:50:29 +0200
commitcca6d40ed6fcc929a6d215479455da9f60673bcb (patch)
tree26c034ffff234f595726298b7b9b18caa3bdaec4
parentdc3c06e73dfd04948c59ea029daef1626e0386f8 (diff)
downloadrneovim-cca6d40ed6fcc929a6d215479455da9f60673bcb.tar.gz
rneovim-cca6d40ed6fcc929a6d215479455da9f60673bcb.tar.bz2
rneovim-cca6d40ed6fcc929a6d215479455da9f60673bcb.zip
test/busted: eager-flushing TAP.lua handler
This TAP.lua implementation was upstreamed: https://github.com/Olivine-Labs/busted/commit/f9db364291cfd7fe51b5c2b8132974fdc76aed73 but it has not been released yet. It avoids hangs, and helps debug hangs, on QuickBuild, so inline it until the next busted release.
-rw-r--r--busted/outputHandlers/TAP.lua92
1 files changed, 92 insertions, 0 deletions
diff --git a/busted/outputHandlers/TAP.lua b/busted/outputHandlers/TAP.lua
new file mode 100644
index 0000000000..ff93a7cc75
--- /dev/null
+++ b/busted/outputHandlers/TAP.lua
@@ -0,0 +1,92 @@
+-- TODO(jkeyes): remove this and use the upstream version as soon as it is
+-- available in a release of busted.
+
+local pretty = require 'pl.pretty'
+
+return function(options)
+ local busted = require 'busted'
+ local handler = require 'busted.outputHandlers.base'()
+
+ local success = 'ok %u - %s'
+ local failure = 'not ' .. success
+ local skip = 'ok %u - # SKIP %s'
+ local counter = 0
+
+ handler.suiteReset = function()
+ counter = 0
+ return nil, true
+ end
+
+ handler.suiteEnd = function()
+ print('1..' .. counter)
+ io.flush()
+ return nil, true
+ end
+
+ local function showFailure(t)
+ local message = t.message
+ local trace = t.trace or {}
+
+ if message == nil then
+ message = 'Nil error'
+ elseif type(message) ~= 'string' then
+ message = pretty.write(message)
+ end
+
+ print(failure:format(counter, t.name))
+ print('# ' .. t.element.trace.short_src .. ' @ ' .. t.element.trace.currentline)
+ if t.randomseed then print('# Random seed: ' .. t.randomseed) end
+ print('# Failure message: ' .. message:gsub('\n', '\n# '))
+ if options.verbose and trace.traceback then
+ print('# ' .. trace.traceback:gsub('^\n', '', 1):gsub('\n', '\n# '))
+ end
+ end
+
+ handler.testStart = function(element, parent)
+ local trace = element.trace
+ if options.verbose and trace and trace.short_src then
+ local fileline = trace.short_src .. ' @ ' .. trace.currentline .. ': '
+ local testName = fileline .. handler.getFullName(element)
+ print('# ' .. testName)
+ end
+ io.flush()
+
+ return nil, true
+ end
+
+ handler.testEnd = function(element, parent, status, trace)
+ counter = counter + 1
+ if status == 'success' then
+ local t = handler.successes[#handler.successes]
+ print(success:format(counter, t.name))
+ elseif status == 'pending' then
+ local t = handler.pendings[#handler.pendings]
+ print(skip:format(counter, (t.message or t.name)))
+ elseif status == 'failure' then
+ showFailure(handler.failures[#handler.failures])
+ elseif status == 'error' then
+ showFailure(handler.errors[#handler.errors])
+ end
+ io.flush()
+
+ return nil, true
+ end
+
+ handler.error = function(element, parent, message, debug)
+ if element.descriptor ~= 'it' then
+ counter = counter + 1
+ showFailure(handler.errors[#handler.errors])
+ end
+ io.flush()
+
+ return nil, true
+ end
+
+ busted.subscribe({ 'suite', 'reset' }, handler.suiteReset)
+ busted.subscribe({ 'suite', 'end' }, handler.suiteEnd)
+ busted.subscribe({ 'test', 'start' }, handler.testStart, { predicate = handler.cancelOnPending })
+ busted.subscribe({ 'test', 'end' }, handler.testEnd, { predicate = handler.cancelOnPending })
+ busted.subscribe({ 'error' }, handler.error)
+
+ return handler
+end