@@ -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\n DAP 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 = {}
0 commit comments