tests: move "busted" dir to "test" (#10518)

* tests: move "busted" dir to "test"

It is used for outputHandlers only, and clearly belongs to the tests.
Use the full module name with the `-o` option to `busted` then for
clarity.

* luacheck

* test/busted/outputHandlers/TAP.lua: use/extend upstream
Cette révision appartient à :
Daniel Hahler 2019-07-16 22:02:50 +02:00 révisé par GitHub
Parent 3a1d3e9ef1
révision 34c6e5beaf
Signature inconnue de Forgejo
ID de la clé GPG: 4AEE18F83AFDEB23
5 fichiers modifiés avec 23 ajouts et 107 suppressions

Voir le fichier

@ -11,6 +11,7 @@ cache = true
ignore = {
"631", -- max_line_length
"212/_.*", -- unused argument, for vars with "_" prefix
}
-- Global objects defined by the C code

Voir le fichier

@ -1,94 +0,0 @@
-- TODO(jkeyes): Use the upstream version when busted releases it. (But how to
-- inject our call to global_helpers.read_nvim_log() ?)
local pretty = require 'pl.pretty'
local global_helpers = require('test.helpers')
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()
io.write(global_helpers.read_nvim_log())
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

Voir le fichier

@ -43,7 +43,7 @@ execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory $ENV{TMPDIR})
set(ENV{SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_NAME}) # used by test/helpers.lua.
execute_process(
COMMAND ${BUSTED_PRG} -v -o ${BUSTED_OUTPUT_TYPE}
COMMAND ${BUSTED_PRG} -v -o test.busted.outputHandlers.${BUSTED_OUTPUT_TYPE}
--lazy --helper=${TEST_DIR}/${TEST_TYPE}/preload.lua
--lpath=${BUILD_DIR}/?.lua
--lpath=${WORKING_DIR}/runtime/lua/?.lua

Voir le fichier

@ -0,0 +1,14 @@
-- Extends the upstream TAP handler, to display the log with suiteEnd.
local global_helpers = require('test.helpers')
return function(options)
local handler = require 'busted.outputHandlers.TAP'(options)
handler.suiteEnd = function()
io.write(global_helpers.read_nvim_log())
return handler.suiteEnd()
end
return handler
end

Voir le fichier

@ -1,6 +1,4 @@
local s = require 'say'
local pretty = require 'pl.pretty'
local term = require 'term'
local global_helpers = require('test.helpers')
local colors
@ -65,8 +63,6 @@ return function(options)
},
}
c = nil
local fileCount = 0
local fileTestCount = 0
local testCount = 0
@ -76,7 +72,6 @@ return function(options)
local errorCount = 0
local pendingDescription = function(pending)
local name = pending.name
local string = ''
if type(pending.message) == 'string' then
@ -175,7 +170,7 @@ return function(options)
return nil, true
end
handler.suiteStart = function(suite, count, total, randomseed)
handler.suiteStart = function(_suite, count, total, randomseed)
if total > 1 then
io.write(repeatSuiteString:format(count, total))
end
@ -196,7 +191,7 @@ return function(options)
end
end
handler.suiteEnd = function(suite, count, total)
handler.suiteEnd = function(suite, _count, _total)
local elapsedTime_ms = getElapsedTime(suite)
local tests = (testCount == 1 and 'test' or 'tests')
local files = (fileCount == 1 and 'file' or 'files')
@ -225,14 +220,14 @@ return function(options)
return nil, true
end
handler.testStart = function(element, parent)
handler.testStart = function(element, _parent)
io.write(runString:format(handler.getFullName(element)))
io.flush()
return nil, true
end
handler.testEnd = function(element, parent, status, debug)
handler.testEnd = function(element, _parent, status, _debug)
local elapsedTime_ms = getElapsedTime(element)
local string
@ -263,7 +258,7 @@ return function(options)
return nil, true
end
handler.testFailure = function(element, parent, message, debug)
handler.testFailure = function(_element, _parent, _message, _debug)
io.write(failureString)
io.flush()
@ -272,7 +267,7 @@ return function(options)
return nil, true
end
handler.testError = function(element, parent, message, debug)
handler.testError = function(_element, _parent, _message, _debug)
io.write(errorString)
io.flush()
@ -281,7 +276,7 @@ return function(options)
return nil, true
end
handler.error = function(element, parent, message, debug)
handler.error = function(element, _parent, _message, _debug)
if element.descriptor ~= 'it' then
io.write(failureDescription(handler.errors[#handler.errors]))
io.flush()