Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added go_list_args option to configuration #172

Merged
merged 7 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading