Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tests busted compatible #1240

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion tests/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion tests/integration_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions tests/progress_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
87 changes: 41 additions & 46 deletions tests/server_executable_spec.lua
Original file line number Diff line number Diff line change
@@ -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'
},
}
}
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
end)
after_each(function()
dap.terminate()
dap.close()
vim.wait(100, function()
return dap.session() == nil
end)
assert.are.same(nil, dap.session())
require("dap.repl").append = orig_append
messages = {}
end)

it('Starts adapter executable and connects', function()
local messages = {}
require('dap.repl').append = function(line)
local msg = line:gsub('port=%d+', 'port=12345')
table.insert(messages, msg)
end
dap.run({
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 expected_msg = "[debug-adapter stderr] Listening on port=12345\n"
assert.are.same({expected_msg}, messages)
}
local session = run_and_wait_until_initialized(config)
assert.are.same(true, session.initialized, "initialized must be true")

dap.terminate()
vim.wait(100, function()
return dap.session() == nil
end)
assert.are.same(nil, dap.session())
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()
dap.run({
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")
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)
4 changes: 2 additions & 2 deletions tests/ui_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Loading