Skip to content

Commit

Permalink
refactor: remove package_or_path
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Sep 21, 2024
1 parent 9f3ee54 commit cc04c23
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
1 change: 0 additions & 1 deletion lua/neotest-golang/lib/cmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ function M.golist_command()
end

--- @class TestCommandData
--- @field absolute_folder_path string | nil The absolute folder path to the test file.
--- @field package_name string | nil The Go package name.
--- @field position neotest.Position The position of the test.
--- @field regexp string | nil The regular expression to filter tests.
Expand Down
8 changes: 6 additions & 2 deletions lua/neotest-golang/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ local default_runners = {
cmd_data.position.type == "test"
or cmd_data.position.type == "namespace"
then
local absolute_folder_path =
vim.fn.fnamemodify(cmd_data.position.path, ":h")
required_go_test_args =
{ cmd_data.absolute_folder_path, "-run", cmd_data.regexp }
{ absolute_folder_path, "-run", cmd_data.regexp }
elseif cmd_data.position.type == "file" then
if cmd_data.regexp ~= nil then
required_go_test_args =
Expand Down Expand Up @@ -69,8 +71,10 @@ local default_runners = {
cmd_data.position.type == "test"
or cmd_data.position.type == "namespace"
then
local absolute_folder_path =
vim.fn.fnamemodify(cmd_data.position.path, ":h")
required_go_test_args =
{ cmd_data.absolute_folder_path, "-run", cmd_data.regexp }
{ absolute_folder_path, "-run", cmd_data.regexp }
elseif cmd_data.position.type == "file" then
if cmd_data.regexp ~= nil then
required_go_test_args =
Expand Down
1 change: 0 additions & 1 deletion lua/neotest-golang/runspec/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function M.build(pos, tree)
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
Expand Down
18 changes: 17 additions & 1 deletion lua/neotest-golang/runspec/namespace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,24 @@ function M.build(pos)
local test_name = lib.convert.to_gotest_test_name(pos.id)
local test_name_regexp = lib.convert.to_gotest_regex_pattern(test_name)

-- 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
and vim.tbl_contains(golist_item.TestGoFiles, pos_path_filename)
then
package_name = golist_item.ImportPath
break
end
end
end

local cmd_data = {
absolute_folder_path = test_folder_absolute_path,
package_name = package_name,
position = pos,
regexp = test_name_regexp,
}
Expand Down
18 changes: 17 additions & 1 deletion lua/neotest-golang/runspec/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,24 @@ function M.build(pos, strategy)
local test_name = lib.convert.to_gotest_test_name(pos.id)
local test_name_regexp = lib.convert.to_gotest_regex_pattern(test_name)

-- 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
and vim.tbl_contains(golist_item.TestGoFiles, pos_path_filename)
then
package_name = golist_item.ImportPath
break
end
end
end

local cmd_data = {
absolute_folder_path = test_folder_absolute_path,
package_name = package_name,
position = pos,
regexp = test_name_regexp,
}
Expand Down

0 comments on commit cc04c23

Please sign in to comment.