Skip to content

Commit

Permalink
test: more tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Oct 6, 2023
1 parent 2929386 commit ff01d34
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 272 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ stylua-check: stylua

.PHONY: stylua-run
stylua-run: stylua
./stylua lua/**/*.lua lua/*.lua
./stylua \
lua/**/*.lua lua/*.lua \
test/*.lua test/**/*.lua

.PHONY: build
build: gen_help stylua-run
Expand Down
4 changes: 2 additions & 2 deletions test/actions_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ local setup_gitsigns = helpers.setup_gitsigns
local feed = helpers.feed
local test_file = helpers.test_file
local edit = helpers.edit
local command = helpers.command
local command = helpers.api.nvim_command
local check = helpers.check
local exec_lua = helpers.exec_lua
local fn = helpers.funcs
local fn = helpers.fn
local system = fn.system
local test_config = helpers.test_config
local clear = helpers.clear
Expand Down
67 changes: 29 additions & 38 deletions test/busted/output_handler.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
local pretty = require('pl.pretty')
local global_helpers = require('test.helpers')

-- Colors are disabled by default. #15610
local colors = require('term.colors')

return function(options)
local busted = require('busted')
local handler = require('busted.outputHandlers.base')()
local colors = require('term.colors')
local pretty = require('pl.pretty')

--- @type table<string,fun(s:string): string>
local c = {
succ = function(s)
return colors.bright(colors.green(s))
Expand Down Expand Up @@ -49,14 +46,13 @@ return function(options)
.. c.time('(%.2f ms total)')
.. '\n\n'
local globalTeardown = c.sect('--------') .. ' Global test environment teardown.\n'
local suiteEndString = c.sect('========')
.. ' '
.. c.nmbr('%d')
.. ' %s from '
.. c.nmbr('%d')
.. ' test %s ran. '
.. c.time('(%.2f ms total)')
.. '\n'
local suiteEndString = string.format(
'%s %s %%s from %s test %%s ran. %s\n',
c.sect('========'),
c.nmbr('%d'),
c.nmbr('%d'),
c.time('(%.2f ms total)')
)
local successStatus = c.succ('PASSED ') .. ' ' .. c.nmbr('%d') .. ' %s.\n'
local timeString = c.time('%.2f ms')

Expand Down Expand Up @@ -151,30 +147,29 @@ return function(options)
end

local getSummary = function(status, count)
local string = ''
local footer = summaryStrings[status].footer
if count > 0 and footer then
local tests = (count == 1 and 'TEST' or 'TESTS')
local errors = (count == 1 and 'ERROR' or 'ERRORS')
string = footer:format(count, status == 'error' and errors or tests)
return footer:format(count, status == 'error' and errors or tests)
end
return string
return ''
end

local getSummaryString = function()
local tests = (successCount == 1 and 'test' or 'tests')
local string = successStatus:format(successCount, tests)

string = string .. getTestList('skipped', skippedCount, handler.pendings, pendingDescription)
string = string .. getTestList('failure', failureCount, handler.failures, failureDescription)
string = string .. getTestList('error', errorCount, handler.errors, failureDescription)

string = string .. ((skippedCount + failureCount + errorCount) > 0 and '\n' or '')
string = string .. getSummary('skipped', skippedCount)
string = string .. getSummary('failure', failureCount)
string = string .. getSummary('error', errorCount)

return string
return table.concat({
successStatus:format(successCount, tests),

getTestList('skipped', skippedCount, handler.pendings, pendingDescription),
getTestList('failure', failureCount, handler.failures, failureDescription),
getTestList('error', errorCount, handler.errors, failureDescription),

((skippedCount + failureCount + errorCount) > 0 and '\n' or ''),
getSummary('skipped', skippedCount),
getSummary('failure', failureCount),
getSummary('error', errorCount),
})
end

handler.suiteReset = function()
Expand Down Expand Up @@ -212,14 +207,11 @@ return function(options)

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')
local tests = testCount == 1 and 'test' or 'tests'
local files = fileCount == 1 and 'file' or 'files'
io.write(globalTeardown)
io.write(suiteEndString:format(testCount, tests, fileCount, files, elapsedTime_ms))
io.write(getSummaryString())
if failureCount > 0 or errorCount > 0 then
io.write(global_helpers.read_nvim_log(nil, true))
end
io.flush()

return nil, true
Expand All @@ -234,7 +226,7 @@ return function(options)

handler.fileEnd = function(file)
local elapsedTime_ms = getElapsedTime(file)
local tests = (fileTestCount == 1 and 'test' or 'tests')
local tests = fileTestCount == 1 and 'test' or 'tests'
fileCount = fileCount + 1
io.write(
fileEndString:format(fileTestCount, tests, vim.fs.normalize(file.name), elapsedTime_ms)
Expand All @@ -244,8 +236,7 @@ return function(options)
end

handler.testStart = function(element, _parent)
local testid = _G._nvim_test_id or ''
local desc = ('%s %s'):format(testid, handler.getFullName(element))
local desc = (' %s'):format(handler.getFullName(element))
io.write(runString:format(desc))
io.flush()

Expand All @@ -258,7 +249,7 @@ return function(options)
end

handler.testEnd = function(element, _parent, status, _debug)
local string
local string --- @type string

fileTestCount = fileTestCount + 1
testCount = testCount + 1
Expand Down
24 changes: 16 additions & 8 deletions test/gitdir_watcher_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local edit = helpers.edit
local eq = helpers.eq
local setup_test_repo = helpers.setup_test_repo
local cleanup = helpers.cleanup
local command = helpers.command
local command = helpers.api.nvim_command
local test_config = helpers.test_config
local match_debug_messages = helpers.match_debug_messages
local match_dag = helpers.match_dag
Expand All @@ -19,8 +19,8 @@ helpers.env()

local function get_bufs()
local bufs = {}
for _, b in ipairs(helpers.meths.list_bufs()) do
bufs[b.id] = helpers.meths.buf_get_name(b)
for _, b in ipairs(helpers.api.nvim_list_bufs()) do
bufs[b.id] = helpers.api.nvim_buf_get_name(b)
end
return bufs
end
Expand All @@ -31,7 +31,7 @@ describe('gitdir_watcher', function()

-- Make gitisigns available
exec_lua('package.path = ...', package.path)
command('cd ' .. helpers.funcs.system({ 'dirname', os.tmpname() }))
command('cd ' .. helpers.fn.system({ 'dirname', os.tmpname() }))
end)

after_each(function()
Expand All @@ -47,7 +47,9 @@ describe('gitdir_watcher', function()
match_debug_messages({
'attach(1): Attaching (trigger=BufReadPost)',
np('run_job: git .* config user.name'),
np('run_job: git .* rev%-parse %-%-show%-toplevel %-%-absolute%-git%-dir %-%-abbrev%-ref HEAD'),
np(
'run_job: git .* rev%-parse %-%-show%-toplevel %-%-absolute%-git%-dir %-%-abbrev%-ref HEAD'
),
np('run_job: git .* ls%-files .* ' .. vim.pesc(test_file)),
n('watch_gitdir(1): Watching git dir'),
np('run_job: git .* show :0:dummy.txt'),
Expand All @@ -68,7 +70,9 @@ describe('gitdir_watcher', function()
})

match_debug_messages({
np('run_job: git .* rev%-parse %-%-show%-toplevel %-%-absolute%-git%-dir %-%-abbrev%-ref HEAD'),
np(
'run_job: git .* rev%-parse %-%-show%-toplevel %-%-absolute%-git%-dir %-%-abbrev%-ref HEAD'
),
np('run_job: git .* ls%-files .* ' .. vim.pesc(test_file)),
np('run_job: git .* diff %-%-name%-status %-C %-%-cached'),
n('handle_moved(1): File moved to dummy.txt2'),
Expand All @@ -93,7 +97,9 @@ describe('gitdir_watcher', function()
})

match_debug_messages({
p('run_job: git .* rev%-parse %-%-show%-toplevel %-%-absolute%-git%-dir %-%-abbrev%-ref HEAD'),
p(
'run_job: git .* rev%-parse %-%-show%-toplevel %-%-absolute%-git%-dir %-%-abbrev%-ref HEAD'
),
np('run_job: git .* ls%-files .* ' .. vim.pesc(test_file2)),
np('run_job: git .* diff %-%-name%-status %-C %-%-cached'),
n('handle_moved(1): File moved to dummy.txt3'),
Expand All @@ -116,7 +122,9 @@ describe('gitdir_watcher', function()
})

match_debug_messages({
p('run_job: git .* rev%-parse %-%-show%-toplevel %-%-absolute%-git%-dir %-%-abbrev%-ref HEAD'),
p(
'run_job: git .* rev%-parse %-%-show%-toplevel %-%-absolute%-git%-dir %-%-abbrev%-ref HEAD'
),
np('run_job: git .* ls%-files .* ' .. vim.pesc(test_file3)),
np('run_job: git .* diff %-%-name%-status %-C %-%-cached'),
np('run_job: git .* ls%-files .* ' .. vim.pesc(test_file)),
Expand Down
Loading

0 comments on commit ff01d34

Please sign in to comment.