Make tests busted compatible

This commit is contained in:
Mathias Fussenegger 2024-05-30 16:18:13 +02:00 committed by Mathias Fußenegger
parent 30799ffbf6
commit fa3a8f75e7
5 changed files with 66 additions and 61 deletions

View file

@ -40,12 +40,19 @@ function M.wait_for_response(server, command)
end
---@param conf dap.Configuration
---@param server table?
---@return dap.Session
function M.run_and_wait_until_initialized(conf, server)
dap.run(conf)
vim.wait(1000, function()
local session = dap.session()
-- wait for initialize and launch requests
return (session and session.initialized and #server.spy.requests == 2 or false)
return (
session ~= nil
and session.initialized == true
and (server == nil or #server.spy.requests == 2)
)
end, 100)
return assert(dap.session(), "Must have session after run")
end

View file

@ -126,7 +126,7 @@ describe('dap with fake server', function()
end_lnum = 0,
lnum = 0,
message = 'Thread stopped due to exception (unhandled)',
namespace = 1,
namespace = session.ns,
severity = 1,
source = 'nvim-dap',
}
@ -1087,6 +1087,9 @@ describe("on_output", function()
dap.terminate()
wait(function() return dap.session() == nil end, "Session should become nil after terminate")
assert.are.same(0, vim.tbl_count(dap.sessions()), "Sessions should go down to 0 after terminate/stop")
dap.defaults.fallback.on_output = nil
assert.are.is_nil(dap.defaults.fallback.on_output)
end)
it("can override output handling", function()

View file

@ -3,14 +3,14 @@ describe('progress', function()
after_each(progress.reset)
it('Polling on empty buffer returns nil', function()
it('Polling on empty buffer returns nil, report and poll after', function()
assert.are.same(nil, progress.poll_msg())
assert.are.same(nil, progress.poll_msg())
it('Can report and poll afterwards', function()
progress.report('hello')
assert.are.same('hello', progress.poll_msg())
end)
progress.report('hello')
assert.are.same('hello', progress.poll_msg())
end)
it('Interleave report and poll', function()
progress.report('one')
progress.report('two')

View file

@ -1,73 +1,68 @@
local helpers = require("tests.helpers")
local wait = helpers.wait
local run_and_wait_until_initialized = helpers.run_and_wait_until_initialized
local dap = require('dap')
dap.adapters.dummy = {
type = 'server',
port = '${port}',
executable = {
command = vim.v.progpath,
args = {
'-Es',
'-u', 'NONE',
'--headless',
'-c', 'lua DAP_PORT=${port}',
'-c', 'luafile tests/run_server.lua'
},
}
}
describe('server executable', function()
local messages = {}
local orig_append
before_each(function()
dap.adapters.dummy = {
type = 'server',
port = '${port}',
executable = {
command = vim.v.progpath,
args = {
'-Es',
'-u', 'NONE',
'--headless',
'-c', 'lua DAP_PORT=${port}',
'-c', 'luafile tests/run_server.lua'
},
}
}
end)
after_each(function()
dap.terminate()
dap.close()
vim.wait(100, function()
return dap.session() == nil
end)
end)
it('Starts adapter executable and connects', function()
local messages = {}
require('dap.repl').append = function(line)
orig_append = require("dap.repl").append
---@diagnostic disable-next-line: duplicate-set-field
require("dap.repl").append = function(line)
local msg = line:gsub('port=%d+', 'port=12345')
table.insert(messages, msg)
end
dap.run({
type = 'dummy',
request = 'launch',
name = 'Launch',
})
vim.wait(2000, function()
local session = dap.session()
return (session and session.initialized)
end)
local session = dap.session()
assert.are_not.same(nil, session)
local expected_msg = "[debug-adapter stderr] Listening on port=12345\n"
assert.are.same({expected_msg}, messages)
assert.are.same(true, session.initialized, "initialized must be true")
end)
after_each(function()
dap.terminate()
vim.wait(100, function()
return dap.session() == nil
end)
assert.are.same(nil, dap.session())
require("dap.repl").append = orig_append
messages = {}
end)
it('Clears session after closing', function()
dap.run({
it('Starts adapter executable and connects', function()
local config = {
type = 'dummy',
request = 'launch',
name = 'Launch',
})
vim.wait(2000, function()
local session = dap.session()
return (session and session.initialized)
end)
local session = dap.session()
assert.are_not.same(nil, session)
}
local session = run_and_wait_until_initialized(config)
assert.are.same(true, session.initialized, "initialized must be true")
local expected_msg = "[debug-adapter stderr] Listening on port=12345\n"
assert.is_true(vim.tbl_contains(messages, expected_msg))
end)
it('Clears session after closing', function()
local config = {
type = 'dummy',
request = 'launch',
name = 'Launch',
}
local session = run_and_wait_until_initialized(config)
assert.are.same(true, session.initialized, "initialized must be true")
dap.close()
vim.wait(100, function()
return dap.session() == nil
end)
wait(function() return dap.session() == nil end, "Must remove session")
assert.are.same(nil, dap.session())
end)
end)

View file

@ -2,7 +2,7 @@ local api = vim.api
local ui = require('dap.ui')
describe('ui', function()
it('layered buf', function()
describe('layered buf', function()
-- note that test cases build on each other
local render_item = function(x) return x.label end
@ -86,7 +86,7 @@ describe('ui', function()
get_children = function(val) return val.children end
}
it('tree can render a tree structure', function()
describe('tree can render a tree structure', function()
local tree = ui.new_tree(opts)
local buf = api.nvim_create_buf(true, true)
local layer = ui.layer(buf)