diff --git a/lua/neotest-golang/features/dap/init.lua b/lua/neotest-golang/features/dap/init.lua index bebc5f13..55e2670d 100644 --- a/lua/neotest-golang/features/dap/init.lua +++ b/lua/neotest-golang/features/dap/init.lua @@ -30,17 +30,18 @@ function M.setup_debugging(cwd) end end +--- @param test_path string --- @param test_name_regex string --- @return table | nil -function M.get_dap_config(test_name_regex) +function M.get_dap_config(test_path, test_name_regex) -- :help dap-configuration local dap_config = { type = "go", name = "Neotest-golang", request = "launch", mode = "test", - program = "${fileDirname}", args = { "-test.run", test_name_regex }, + program = test_path, } local dap_go_opts = options.get().dap_go_opts or {} diff --git a/lua/neotest-golang/runspec/test.lua b/lua/neotest-golang/runspec/test.lua index 1831178d..17df70f5 100644 --- a/lua/neotest-golang/runspec/test.lua +++ b/lua/neotest-golang/runspec/test.lua @@ -11,8 +11,8 @@ local M = {} --- @param strategy string --- @return neotest.RunSpec | neotest.RunSpec[] | nil function M.build(pos, strategy) - local test_folder_absolute_path = - string.match(pos.path, "(.+)" .. lib.find.os_path_sep) + local pos_path_foldername = vim.fn.fnamemodify(pos.path, ":h") + local test_folder_absolute_path = pos_path_foldername local golist_data, golist_error = lib.cmd.golist_data(test_folder_absolute_path) @@ -36,7 +36,7 @@ function M.build(pos, strategy) local runspec_strategy = nil if strategy == "dap" then M.assert_dap_prerequisites() - runspec_strategy = dap.get_dap_config(test_name_regex) + runspec_strategy = dap.get_dap_config(pos_path_foldername, test_name_regex) logger.debug("DAP strategy used: " .. vim.inspect(runspec_strategy)) dap.setup_debugging(test_folder_absolute_path) end