diff --git a/README.md b/README.md index 07a06945..7be6a982 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ consider setting up neotest and its adapters in a | Argument | Default value | Description | | ------------------------ | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `go_test_args` | `{ "-v", "-race", "-count=1" }` | Arguments to pass into `go test`. | +| `go_list_args` | `{}` | Arguments to pass into `go list`. If using -tags in go_test_args the same argument should be passed to go_list_args for it to list tests properly. | | `dap_go_opts` | `{}` | Options to pass into `require("dap-go").setup()`. | | `testify_enabled` | `false` | Enable support for [testify](https://github.com/stretchr/testify) suites. See [here](https://github.com/fredrikaverpil/neotest-golang#testify-suites) for more info. | | `warn_test_name_dupes` | `true` | Warn about duplicate test names within the same Go package. | diff --git a/lua/neotest-golang/lib/cmd.lua b/lua/neotest-golang/lib/cmd.lua index dd9eefaf..d227c810 100644 --- a/lua/neotest-golang/lib/cmd.lua +++ b/lua/neotest-golang/lib/cmd.lua @@ -9,18 +9,16 @@ local json = require("neotest-golang.lib.json") local M = {} function M.golist_data(cwd) - -- call 'go list -json ./...' to get test file data - local go_list_command = { - "go", - "list", - "-json", - "./...", - } - local go_list_command_concat = table.concat(go_list_command, " ") + -- call 'go list -json {go_list_args...} ./...' to get test file data + + -- combine base command, user args and packages(./...) + local cmd = { "go", "list", "-json" } + vim.list_extend(cmd, options.get().go_list_args or {}) + vim.list_extend(cmd, { "./..." }) + + local go_list_command_concat = table.concat(cmd, " ") logger.debug("Running Go list: " .. go_list_command_concat .. " in " .. cwd) - local output = vim - .system(go_list_command, { cwd = cwd, text = true }) - :wait().stdout or "" + local output = vim.system(cmd, { cwd = cwd, text = true }):wait().stdout or "" if output == "" then logger.error({ "Execution of 'go list' failed, output:", output }) end diff --git a/lua/neotest-golang/options.lua b/lua/neotest-golang/options.lua index 8482a765..f94f87db 100644 --- a/lua/neotest-golang/options.lua +++ b/lua/neotest-golang/options.lua @@ -8,6 +8,7 @@ local M = {} local opts = { go_test_args = { "-v", "-race", "-count=1" }, + go_list_args = {}, dap_go_opts = {}, testify_enabled = false, warn_test_name_dupes = true, diff --git a/tests/unit/options_spec.lua b/tests/unit/options_spec.lua index 8b669990..8ba1441f 100644 --- a/tests/unit/options_spec.lua +++ b/tests/unit/options_spec.lua @@ -9,6 +9,7 @@ describe("Options are set up", function() "-race", "-count=1", }, + go_list_args = {}, dap_go_opts = {}, testify_enabled = false, warn_test_name_dupes = true, @@ -31,6 +32,7 @@ describe("Options are set up", function() "-count=1", "-parallel=1", -- non-default }, + go_list_args = {}, dap_go_opts = {}, testify_enabled = false, warn_test_name_dupes = true,