diff --git a/lua/neotest-golang/runspec/dir.lua b/lua/neotest-golang/runspec/dir.lua index 237620ef..810259dc 100644 --- a/lua/neotest-golang/runspec/dir.lua +++ b/lua/neotest-golang/runspec/dir.lua @@ -87,7 +87,7 @@ function M.build(pos) end local go_mod_folderpath = vim.fn.fnamemodify(go_mod_filepath, ":h") - local golist_data, golist_error = lib.cmd.golist_data(go_mod_folderpath) + local golist_data, golist_error = lib.cmd.golist_data(pos.path) local errors = nil if golist_error ~= nil then diff --git a/lua/neotest-golang/runspec/file.lua b/lua/neotest-golang/runspec/file.lua index 3f778ec7..d826f3ff 100644 --- a/lua/neotest-golang/runspec/file.lua +++ b/lua/neotest-golang/runspec/file.lua @@ -25,7 +25,8 @@ function M.build(pos, tree, strategy) end local go_mod_folderpath = vim.fn.fnamemodify(go_mod_filepath, ":h") - local golist_data, golist_error = lib.cmd.golist_data(go_mod_folderpath) + local pos_path_folderpath = vim.fn.fnamemodify(pos.path, ":h") + local golist_data, golist_error = lib.cmd.golist_data(pos_path_folderpath) local errors = nil if golist_error ~= nil then @@ -38,12 +39,11 @@ function M.build(pos, tree, strategy) -- find the go package that corresponds to the pos.path local package_name = "./..." local pos_path_filename = vim.fn.fnamemodify(pos.path, ":t") - local pos_path_foldername = vim.fn.fnamemodify(pos.path, ":h") for _, golist_item in ipairs(golist_data) do if golist_item.TestGoFiles ~= nil then if - pos_path_foldername == golist_item.Dir + pos_path_folderpath == golist_item.Dir and vim.tbl_contains(golist_item.TestGoFiles, pos_path_filename) then package_name = golist_item.ImportPath @@ -53,7 +53,7 @@ function M.build(pos, tree, strategy) if golist_item.XTestGoFiles ~= nil then -- NOTE: XTestGoFiles are test files that are part of a [packagename]_test package. if - pos_path_foldername == golist_item.Dir + pos_path_folderpath == golist_item.Dir and vim.tbl_contains(golist_item.XTestGoFiles, pos_path_filename) then package_name = golist_item.ImportPath @@ -78,9 +78,9 @@ function M.build(pos, tree, strategy) local runspec_strategy = nil if strategy == "dap" then dap.assert_dap_prerequisites() - runspec_strategy = dap.get_dap_config(pos_path_foldername, regexp) + runspec_strategy = dap.get_dap_config(pos_path_folderpath, regexp) logger.debug("DAP strategy used: " .. vim.inspect(runspec_strategy)) - dap.setup_debugging(pos_path_foldername) + dap.setup_debugging(pos_path_folderpath) end --- @type RunspecContext diff --git a/lua/neotest-golang/runspec/namespace.lua b/lua/neotest-golang/runspec/namespace.lua index dcc5779b..2755d50e 100644 --- a/lua/neotest-golang/runspec/namespace.lua +++ b/lua/neotest-golang/runspec/namespace.lua @@ -9,11 +9,10 @@ local M = {} --- @param pos neotest.Position --- @return neotest.RunSpec | neotest.RunSpec[] | nil function M.build(pos) - local test_folder_absolute_path = + local pos_path_folderpath = string.match(pos.path, "(.+)" .. lib.find.os_path_sep) - local golist_data, golist_error = - lib.cmd.golist_data(test_folder_absolute_path) + local golist_data, golist_error = lib.cmd.golist_data(pos_path_folderpath) local errors = nil if golist_error ~= nil then @@ -26,10 +25,8 @@ function M.build(pos) local test_name = lib.convert.to_gotest_test_name(pos.id) test_name = lib.convert.to_gotest_regex_pattern(test_name) - local test_cmd, json_filepath = lib.cmd.test_command_in_package_with_regexp( - test_folder_absolute_path, - test_name - ) + local test_cmd, json_filepath = + lib.cmd.test_command_in_package_with_regexp(pos_path_folderpath, test_name) --- @type RunspecContext local context = { @@ -42,7 +39,7 @@ function M.build(pos) --- @type neotest.RunSpec local run_spec = { command = test_cmd, - cwd = test_folder_absolute_path, + cwd = pos_path_folderpath, context = context, } diff --git a/lua/neotest-golang/runspec/test.lua b/lua/neotest-golang/runspec/test.lua index 208a83be..822e4c6a 100644 --- a/lua/neotest-golang/runspec/test.lua +++ b/lua/neotest-golang/runspec/test.lua @@ -11,11 +11,9 @@ local M = {} --- @param strategy string --- @return neotest.RunSpec | neotest.RunSpec[] | nil function M.build(pos, strategy) - local pos_path_foldername = vim.fn.fnamemodify(pos.path, ":h") - local test_folder_absolute_path = pos_path_foldername + local pos_path_folderpath = vim.fn.fnamemodify(pos.path, ":h") - local golist_data, golist_error = - lib.cmd.golist_data(test_folder_absolute_path) + local golist_data, golist_error = lib.cmd.golist_data(pos_path_folderpath) local errors = nil if golist_error ~= nil then @@ -29,16 +27,16 @@ function M.build(pos, strategy) local test_name_regex = lib.convert.to_gotest_regex_pattern(test_name) local test_cmd, json_filepath = lib.cmd.test_command_in_package_with_regexp( - test_folder_absolute_path, + pos_path_folderpath, test_name_regex ) local runspec_strategy = nil if strategy == "dap" then dap.assert_dap_prerequisites() - runspec_strategy = dap.get_dap_config(pos_path_foldername, test_name_regex) + runspec_strategy = dap.get_dap_config(pos_path_folderpath, test_name_regex) logger.debug("DAP strategy used: " .. vim.inspect(runspec_strategy)) - dap.setup_debugging(test_folder_absolute_path) + dap.setup_debugging(pos_path_folderpath) end --- @type RunspecContext @@ -53,7 +51,7 @@ function M.build(pos, strategy) --- @type neotest.RunSpec local run_spec = { command = test_cmd, - cwd = test_folder_absolute_path, + cwd = pos_path_folderpath, context = context, }