Skip to content

Commit

Permalink
feat: add position data to cmd_data
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Sep 21, 2024
1 parent 47b0530 commit bc978ff
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
9 changes: 5 additions & 4 deletions lua/neotest-golang/lib/cmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ function M.golist_command()
return cmd
end

function M.test_command_in_package(package_or_path)
local cmd_data = { package_or_path = package_or_path }
function M.test_command_in_package(pos, package_or_path)
local cmd_data = { package_or_path = package_or_path, position = pos }
local cmd, json_filepath = M.test_command(cmd_data)
return cmd, json_filepath
end

function M.test_command_in_package_with_regexp(package_or_path, regexp)
local cmd_data = { package_or_path = package_or_path, regexp = regexp }
function M.test_command_in_package_with_regexp(pos, package_or_path, regexp)
local cmd_data =
{ package_or_path = package_or_path, position = pos, regexp = regexp }
local cmd, json_filepath = M.test_command(cmd_data)
return cmd, json_filepath
end
Expand Down
3 changes: 2 additions & 1 deletion lua/neotest-golang/runspec/dir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function M.build(pos)
end
end

local test_cmd, json_filepath = lib.cmd.test_command_in_package(package_name)
local test_cmd, json_filepath =
lib.cmd.test_command_in_package(pos, package_name)

--- @type RunspecContext
local context = {
Expand Down
4 changes: 2 additions & 2 deletions lua/neotest-golang/runspec/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ function M.build(pos, tree)
local regexp = M.get_regexp(pos.path)
if regexp ~= nil then
test_cmd, json_filepath =
lib.cmd.test_command_in_package_with_regexp(package_name, regexp)
lib.cmd.test_command_in_package_with_regexp(pos, package_name, regexp)
else
-- fallback: run all tests in the package
test_cmd, json_filepath = lib.cmd.test_command_in_package(package_name)
test_cmd, json_filepath = lib.cmd.test_command_in_package(pos, package_name)
-- NOTE: could also fall back to running on a per-test basis by using a bare return
end

Expand Down
3 changes: 2 additions & 1 deletion lua/neotest-golang/runspec/namespace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ function M.build(pos)

local test_cmd, json_filepath = lib.cmd.test_command_in_package_with_regexp(
test_folder_absolute_path,
test_name
test_name,
pos
)

--- @type RunspecContext
Expand Down
1 change: 1 addition & 0 deletions lua/neotest-golang/runspec/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ 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(
pos,
test_folder_absolute_path,
test_name_regex
)
Expand Down

0 comments on commit bc978ff

Please sign in to comment.