diff --git a/lua/neotest-golang/cmd.lua b/lua/neotest-golang/cmd.lua index b0106e56..219a63a5 100644 --- a/lua/neotest-golang/cmd.lua +++ b/lua/neotest-golang/cmd.lua @@ -3,10 +3,11 @@ 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", @@ -14,9 +15,9 @@ function M.golist_cmd(cwd) "-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) diff --git a/lua/neotest-golang/runspec_dir.lua b/lua/neotest-golang/runspec_dir.lua index 7e409ee6..de9e8c0e 100644 --- a/lua/neotest-golang/runspec_dir.lua +++ b/lua/neotest-golang/runspec_dir.lua @@ -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 diff --git a/lua/neotest-golang/runspec_test.lua b/lua/neotest-golang/runspec_test.lua index cc189809..c13947ac 100644 --- a/lua/neotest-golang/runspec_test.lua +++ b/lua/neotest-golang/runspec_test.lua @@ -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)