Skip to content

Commit e3f16d1

Browse files
committed
fix(test): normalize Windows protocol framing
1 parent 7fbfffb commit e3f16d1

4 files changed

Lines changed: 11 additions & 62 deletions

File tree

‎tests/e2e/dap_spec.lua‎

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ 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
90-
local probe = vim.system({ nvim, "--headless", "--clean", "-u", "NONE", "+qa" }, { text = true }):wait()
91-
assert(probe.code == 0, ("Unable to launch the child Neovim executable: %%s"):format(vim.inspect(probe)))
9289
dap.adapters.astronvim_fixture = {
9390
type = "executable",
9491
command = nvim,
@@ -131,30 +128,9 @@ T["DAP-E2E-03 runs and terminates a hermetic adapter through AstroNvim mappings"
131128
mapping.callback()
132129
]]
133130

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(
131+
helpers.wait_until(child, "require('dap').session() ~= nil", "DAP adapter session")
132+
helpers.wait_until(
133+
child,
158134
([[(function()
159135
if vim.fn.filereadable(%s) == 0 then return false end
160136
local commands = {}
@@ -167,7 +143,7 @@ T["DAP-E2E-03 runs and terminates a hermetic adapter through AstroNvim mappings"
167143
end)()]]):format(vim.inspect(log), vim.inspect(log)),
168144
"DAP adapter initialization"
169145
)
170-
wait_for_dap("#vim.api.nvim_list_wins() > 1", "DAP UI open")
146+
helpers.wait_until(child, "#vim.api.nvim_list_wins() > 1", "DAP UI open")
171147

172148
local commands = child.lua_get(([[(function()
173149
local commands = {}
@@ -199,8 +175,8 @@ T["DAP-E2E-03 runs and terminates a hermetic adapter through AstroNvim mappings"
199175
assert(type(mapping.callback) == "function")
200176
mapping.callback()
201177
]]
202-
wait_for_dap("require('dap').session() == nil", "DAP session termination")
203-
wait_for_dap("#vim.api.nvim_list_wins() == 1", "DAP UI close")
178+
helpers.wait_until(child, "require('dap').session() == nil", "DAP session termination")
179+
helpers.wait_until(child, "#vim.api.nvim_list_wins() == 1", "DAP UI close")
204180

205181
commands = child.lua_get(([[(function()
206182
local commands = {}

‎tests/e2e/lsp_spec.lua‎

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ 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
32-
local probe = vim.system({ nvim, "--headless", "--clean", "-u", "NONE", "+qa" }, { text = true }):wait()
33-
assert(probe.code == 0, ("Unable to launch the child Neovim executable: %%s"):format(vim.inspect(probe)))
3431
vim.lsp.config("astronvim-e2e-lsp", {
3532
cmd = { nvim, "--headless", "--clean", "-u", "NONE", "-l", server },
3633
root_dir = project,
@@ -40,33 +37,7 @@ T["LSP-E2E-01 attaches a real local server, registers a capability, and formats"
4037
return { client_id = client_id, buffer = vim.api.nvim_get_current_buf(), log_path = log_path }
4138
end)()]=]):format(vim.inspect(project), vim.inspect(server)))
4239

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")
40+
helpers.wait_until(child, "#vim.lsp.get_clients({ name = 'astronvim-e2e-lsp' }) == 1", "real LSP client")
7041
helpers.wait_until(
7142
child,
7243
"vim.lsp.get_clients({ name = 'astronvim-e2e-lsp' })[1]:supports_method('textDocument/formatting')",

‎tests/fixtures/dap_adapter.lua‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ local function send(message)
2929
sequence = sequence + 1
3030
message.seq = sequence
3131
local body = vim.json.encode(message)
32-
io.write("Content-Length: " .. #body .. "\r\n\r\n" .. body)
32+
local newline = vim.fn.has "win32" == 1 and "\n" or "\r\n"
33+
io.write("Content-Length: " .. #body .. newline .. newline .. body)
3334
io.flush()
3435
end
3536

‎tests/fixtures/lsp_server.lua‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ end
1616

1717
local function send_message(message)
1818
local body = vim.json.encode(message)
19-
io.write("Content-Length: " .. #body .. "\r\n\r\n" .. body)
19+
local newline = vim.fn.has "win32" == 1 and "\n" or "\r\n"
20+
io.write("Content-Length: " .. #body .. newline .. newline .. body)
2021
io.flush()
2122
end
2223

0 commit comments

Comments
 (0)