Skip to content

Commit 7fbfffb

Browse files
committed
test: report protocol fixture launch state
1 parent 6f60150 commit 7fbfffb

2 files changed

Lines changed: 57 additions & 7 deletions

File tree

‎tests/e2e/dap_spec.lua‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ T["DAP-E2E-03 runs and terminates a hermetic adapter through AstroNvim mappings"
8686
vim.env.ASTRONVIM_E2E_DAP_SOURCE = %s
8787
local nvim = vim.fn.exepath "nvim"
8888
if nvim == "" then nvim = vim.env.ASTRONVIM_TEST_NVIM or vim.v.progpath end
89+
_G.astronvim_test_child_nvim = nvim
8990
local probe = vim.system({ nvim, "--headless", "--clean", "-u", "NONE", "+qa" }, { text = true }):wait()
9091
assert(probe.code == 0, ("Unable to launch the child Neovim executable: %%s"):format(vim.inspect(probe)))
9192
dap.adapters.astronvim_fixture = {
@@ -129,9 +130,31 @@ T["DAP-E2E-03 runs and terminates a hermetic adapter through AstroNvim mappings"
129130
assert(type(mapping.callback) == "function")
130131
mapping.callback()
131132
]]
132-
helpers.wait_until(child, "require('dap').session() ~= nil", "DAP adapter session")
133-
helpers.wait_until(
134-
child,
133+
134+
local function wait_for_dap(expression, description)
135+
local ok, err = pcall(helpers.wait_until, child, expression, description)
136+
if ok then return end
137+
local diagnostics = child.lua_get(([=[(function()
138+
local log = {}
139+
if vim.fn.filereadable(%s) == 1 then log = vim.fn.readfile(%s) end
140+
local notifications = {}
141+
for _, notification in ipairs(Snacks.notifier.get_history()) do
142+
table.insert(notifications, notification.msg)
143+
end
144+
return {
145+
nvim = _G.astronvim_test_child_nvim,
146+
progpath = vim.v.progpath,
147+
exepath = vim.fn.exepath("nvim"),
148+
session = require("dap").session() ~= nil,
149+
log = log,
150+
notifications = notifications,
151+
}
152+
end)()]=]):format(vim.inspect(log), vim.inspect(log)))
153+
error(("%s\nDAP diagnostics: %s"):format(err, vim.inspect(diagnostics)), 0)
154+
end
155+
156+
wait_for_dap("require('dap').session() ~= nil", "DAP adapter session")
157+
wait_for_dap(
135158
([[(function()
136159
if vim.fn.filereadable(%s) == 0 then return false end
137160
local commands = {}
@@ -144,7 +167,7 @@ T["DAP-E2E-03 runs and terminates a hermetic adapter through AstroNvim mappings"
144167
end)()]]):format(vim.inspect(log), vim.inspect(log)),
145168
"DAP adapter initialization"
146169
)
147-
helpers.wait_until(child, "#vim.api.nvim_list_wins() > 1", "DAP UI open")
170+
wait_for_dap("#vim.api.nvim_list_wins() > 1", "DAP UI open")
148171

149172
local commands = child.lua_get(([[(function()
150173
local commands = {}
@@ -176,8 +199,8 @@ T["DAP-E2E-03 runs and terminates a hermetic adapter through AstroNvim mappings"
176199
assert(type(mapping.callback) == "function")
177200
mapping.callback()
178201
]]
179-
helpers.wait_until(child, "require('dap').session() == nil", "DAP session termination")
180-
helpers.wait_until(child, "#vim.api.nvim_list_wins() == 1", "DAP UI close")
202+
wait_for_dap("require('dap').session() == nil", "DAP session termination")
203+
wait_for_dap("#vim.api.nvim_list_wins() == 1", "DAP UI close")
181204

182205
commands = child.lua_get(([[(function()
183206
local commands = {}

‎tests/e2e/lsp_spec.lua‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ T["LSP-E2E-01 attaches a real local server, registers a capability, and formats"
2828
vim.env.ASTRONVIM_E2E_LSP_LOG = log_path
2929
local nvim = vim.fn.exepath "nvim"
3030
if nvim == "" then nvim = vim.env.ASTRONVIM_TEST_NVIM or vim.v.progpath end
31+
_G.astronvim_test_child_nvim = nvim
3132
local probe = vim.system({ nvim, "--headless", "--clean", "-u", "NONE", "+qa" }, { text = true }):wait()
3233
assert(probe.code == 0, ("Unable to launch the child Neovim executable: %%s"):format(vim.inspect(probe)))
3334
vim.lsp.config("astronvim-e2e-lsp", {
@@ -39,7 +40,33 @@ T["LSP-E2E-01 attaches a real local server, registers a capability, and formats"
3940
return { client_id = client_id, buffer = vim.api.nvim_get_current_buf(), log_path = log_path }
4041
end)()]=]):format(vim.inspect(project), vim.inspect(server)))
4142

42-
helpers.wait_until(child, "#vim.lsp.get_clients({ name = 'astronvim-e2e-lsp' }) == 1", "real LSP client")
43+
local function wait_for_lsp(expression, description)
44+
local ok, err = pcall(helpers.wait_until, child, expression, description)
45+
if ok then return end
46+
local diagnostics = child.lua_get(
47+
([=[(function()
48+
local log = {}
49+
if vim.fn.filereadable(%s) == 1 then log = vim.fn.readfile(%s) end
50+
local clients = {}
51+
for _, client in ipairs(vim.lsp.get_clients()) do
52+
table.insert(clients, { id = client.id, name = client.name, cmd = client.config.cmd })
53+
end
54+
return {
55+
nvim = _G.astronvim_test_child_nvim,
56+
progpath = vim.v.progpath,
57+
exepath = vim.fn.exepath("nvim"),
58+
clients = clients,
59+
log = log,
60+
}
61+
end)()]=]):format(
62+
vim.inspect(child.lua_get "vim.fs.joinpath(vim.fn.getcwd(), 'lsp-events.jsonl')"),
63+
vim.inspect(child.lua_get "vim.fs.joinpath(vim.fn.getcwd(), 'lsp-events.jsonl')")
64+
)
65+
)
66+
error(("%s\nLSP diagnostics: %s"):format(err, vim.inspect(diagnostics)), 0)
67+
end
68+
69+
wait_for_lsp("#vim.lsp.get_clients({ name = 'astronvim-e2e-lsp' }) == 1", "real LSP client")
4370
helpers.wait_until(
4471
child,
4572
"vim.lsp.get_clients({ name = 'astronvim-e2e-lsp' })[1]:supports_method('textDocument/formatting')",

0 commit comments

Comments
 (0)