Skip to content

Commit

Permalink
fix: runspec for dir/file did not properly detect go package (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil authored Jul 11, 2024
1 parent 5ac25f5 commit c9c5e33
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lua/neotest-golang/runspec_dir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ function M.build(pos)
local package_name = "./..."
for _, golist_item in ipairs(golist_data) do
if pos.path == golist_item.Dir then
package_name = golist_item.ImportPath
break
if golist_item.Name == "main" then
-- do nothing, keep ./...
else
package_name = golist_item.ImportPath
break
end
end
end

Expand Down
7 changes: 6 additions & 1 deletion lua/neotest-golang/runspec_file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ function M.build(pos, tree)
-- 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 vim.tbl_contains(golist_item.TestGoFiles, pos_path_filename) then
if
pos_path_foldername == golist_item.Dir
and vim.tbl_contains(golist_item.TestGoFiles, pos_path_filename)
then
package_name = golist_item.ImportPath
break
end
Expand Down

0 comments on commit c9c5e33

Please sign in to comment.