Skip to content

Commit

Permalink
fix: added go_list_args option to configuration (#172)
Browse files Browse the repository at this point in the history
Co-authored-by: augbed <>
Co-authored-by: Augustas Bedulskis <[email protected]>
Co-authored-by: augbed <[email protected]>
  • Loading branch information
3 people authored Sep 5, 2024
1 parent baa2cf4 commit a4d9968
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
20 changes: 9 additions & 11 deletions lua/neotest-golang/lib/cmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lua/neotest-golang/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/options_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit a4d9968

Please sign in to comment.