From 64094c4abe0ce89bd6fa3d4d978297bb98b0c6e4 Mon Sep 17 00:00:00 2001 From: augbed <> Date: Mon, 2 Sep 2024 02:38:12 +0300 Subject: [PATCH 1/7] included -tags to go list command from go_test_args if provided --- lua/neotest-golang/lib/cmd.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lua/neotest-golang/lib/cmd.lua b/lua/neotest-golang/lib/cmd.lua index dd9eefaf..b89c2f01 100644 --- a/lua/neotest-golang/lib/cmd.lua +++ b/lua/neotest-golang/lib/cmd.lua @@ -16,6 +16,15 @@ function M.golist_data(cwd) "-json", "./...", } + + -- if we have tags in go test args + -- we need to add them to list command for it to be able to list properly + for _, go_test_arg in ipairs(options.get().go_test_args) do + if string.match(go_test_arg, "^-tags=") then + table.insert(go_list_command, 3, go_test_arg) + end + end + local go_list_command_concat = table.concat(go_list_command, " ") logger.debug("Running Go list: " .. go_list_command_concat .. " in " .. cwd) local output = vim From 6871c1bb382d8fa97064f56418d1bb9a4280b475 Mon Sep 17 00:00:00 2001 From: Augustas Bedulskis Date: Tue, 3 Sep 2024 23:47:57 +0300 Subject: [PATCH 2/7] added go_list_args --- README.md | 1 + lua/neotest-golang/lib/cmd.lua | 13 +++---------- lua/neotest-golang/options.lua | 1 + tests/unit/options_spec.lua | 2 ++ 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 07a06945..f1bb6f0a 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 b89c2f01..220765f7 100644 --- a/lua/neotest-golang/lib/cmd.lua +++ b/lua/neotest-golang/lib/cmd.lua @@ -9,21 +9,14 @@ local json = require("neotest-golang.lib.json") local M = {} function M.golist_data(cwd) - -- call 'go list -json ./...' to get test file data + -- call 'go list -json {go_list_args...} ./...' to get test file data local go_list_command = { "go", "list", "-json", - "./...", } - - -- if we have tags in go test args - -- we need to add them to list command for it to be able to list properly - for _, go_test_arg in ipairs(options.get().go_test_args) do - if string.match(go_test_arg, "^-tags=") then - table.insert(go_list_command, 3, go_test_arg) - end - end + -- combine base command, user args and packages(./...) + vim.list_extend(vim.list_extend(go_list_command, options.get().go_list_args or {}), { "./..." }) local go_list_command_concat = table.concat(go_list_command, " ") logger.debug("Running Go list: " .. go_list_command_concat .. " in " .. cwd) 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, From fe8db64ba48cc6e21531d9bb030c858385b48f17 Mon Sep 17 00:00:00 2001 From: Augustas Bedulskis Date: Tue, 3 Sep 2024 23:56:31 +0300 Subject: [PATCH 3/7] Fixed readme table formatting --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f1bb6f0a..7be6a982 100644 --- a/README.md +++ b/README.md @@ -144,7 +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. | +| `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. | From f88f965bbe52af37789edab39210e35389e50095 Mon Sep 17 00:00:00 2001 From: augbed Date: Wed, 4 Sep 2024 23:12:26 +0300 Subject: [PATCH 4/7] Update lua/neotest-golang/lib/cmd.lua Co-authored-by: Fredrik Averpil --- lua/neotest-golang/lib/cmd.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/neotest-golang/lib/cmd.lua b/lua/neotest-golang/lib/cmd.lua index 220765f7..051be431 100644 --- a/lua/neotest-golang/lib/cmd.lua +++ b/lua/neotest-golang/lib/cmd.lua @@ -16,7 +16,10 @@ function M.golist_data(cwd) "-json", } -- combine base command, user args and packages(./...) - vim.list_extend(vim.list_extend(go_list_command, options.get().go_list_args or {}), { "./..." }) + vim.list_extend( + vim.list_extend(go_list_command, options.get().go_list_args or {}), + { "./..." } + ) local go_list_command_concat = table.concat(go_list_command, " ") logger.debug("Running Go list: " .. go_list_command_concat .. " in " .. cwd) From 8c513dedb246dfa21f35e4a8b4894daef7ec2208 Mon Sep 17 00:00:00 2001 From: Augustas Bedulskis Date: Wed, 4 Sep 2024 23:31:13 +0300 Subject: [PATCH 5/7] made go list cmd building be more inline with style in plugin --- lua/neotest-golang/lib/cmd.lua | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lua/neotest-golang/lib/cmd.lua b/lua/neotest-golang/lib/cmd.lua index 051be431..a3f85314 100644 --- a/lua/neotest-golang/lib/cmd.lua +++ b/lua/neotest-golang/lib/cmd.lua @@ -10,21 +10,16 @@ local M = {} function M.golist_data(cwd) -- call 'go list -json {go_list_args...} ./...' to get test file data - local go_list_command = { - "go", - "list", - "-json", - } + -- combine base command, user args and packages(./...) - vim.list_extend( - vim.list_extend(go_list_command, options.get().go_list_args or {}), - { "./..." } - ) + 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(go_list_command, " ") + 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 }) + .system(cmd, { cwd = cwd, text = true }) :wait().stdout or "" if output == "" then logger.error({ "Execution of 'go list' failed, output:", output }) From d88be5fad2158841befe815e875284e524c95c77 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Thu, 5 Sep 2024 05:57:51 +0200 Subject: [PATCH 6/7] Apply suggestions from code review --- lua/neotest-golang/lib/cmd.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lua/neotest-golang/lib/cmd.lua b/lua/neotest-golang/lib/cmd.lua index a3f85314..d227c810 100644 --- a/lua/neotest-golang/lib/cmd.lua +++ b/lua/neotest-golang/lib/cmd.lua @@ -14,13 +14,11 @@ function M.golist_data(cwd) -- 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, { "./..."}) + 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(cmd, { 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 From b22ded591ea4308b5b8a469e41347537640d2aba Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Thu, 5 Sep 2024 06:11:02 +0200 Subject: [PATCH 7/7] empty