Skip to content

Commit

Permalink
refactor: go list
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Jul 3, 2024
1 parent 6082e18 commit 0c15ff3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lua/neotest-golang/cmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
local async = require("neotest.async")

local options = require("neotest-golang.options")
local json = require("neotest-golang.json")

local M = {}

function M.golist_cmd(cwd)
function M.golist_output(cwd)
-- call 'go list -json ./...' to get test file data
local go_list_command = {
"go",
"list",
"-json",
"./...",
}
local go_list_command_result =
local output =
vim.fn.system("cd " .. cwd .. " && " .. table.concat(go_list_command, " "))
return go_list_command_result
return json.process_golist_output(output)
end

function M.fallback_to_go_test(executable)
Expand Down
3 changes: 1 addition & 2 deletions lua/neotest-golang/runspec_dir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ function M.build(pos)
end

local go_mod_folderpath = vim.fn.fnamemodify(go_mod_filepath, ":h")
local go_list_command = cmd.golist_cmd(go_mod_folderpath)
local golist_output = json.process_golist_output(go_list_command)
local golist_output = cmd.golist_output(go_mod_folderpath)

-- find the go module that corresponds to the go_mod_folderpath
local module_name = "./..." -- if no go module, run all tests at the $CWD
Expand Down
3 changes: 1 addition & 2 deletions lua/neotest-golang/runspec_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ local M = {}
function M.build(pos, strategy)
--- @type string
local test_folder_absolute_path = string.match(pos.path, "(.+)/")
local go_list_command = cmd.golist_cmd(test_folder_absolute_path)
local golist_output = json.process_golist_output(go_list_command)
local golist_output = cmd.golist_output(test_folder_absolute_path)

--- @type string
local test_name = convert.to_gotest_test_name(pos.id)
Expand Down

0 comments on commit 0c15ff3

Please sign in to comment.