From 929e8fb64bdaebc357b022919a7cfc982e50ceb7 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Mon, 17 Jun 2024 20:06:12 +0200 Subject: [PATCH] feat: warn about duplicate test names --- README.md | 11 ++++++----- lua/neotest-golang/options.lua | 2 ++ lua/neotest-golang/results_dir.lua | 28 ++++++++++++++++------------ 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index b87e78e9..44fc3996 100644 --- a/README.md +++ b/README.md @@ -95,11 +95,12 @@ return { ## ⚙️ Configuration -| Argument | Default value | Description | -| ---------------- | ----------------------------------------------- | ----------------------------------------------------------------------------------------- | -| `go_test_args` | `{ "-v", "-race", "-count=1", "-timeout=60s" }` | Arguments to pass into `go test`. | -| `dap_go_enabled` | `false` | Leverage [leoluz/nvim-dap-go](https://github.com/leoluz/nvim-dap-go) for debugging tests. | -| `dap_go_opts` | `{}` | Options to pass into `require("dap-go").setup()`. | +| Argument | Default value | Description | +| --------------------------- | ----------------------------------------------- | ----------------------------------------------------------------------------------------- | +| `go_test_args` | `{ "-v", "-race", "-count=1", "-timeout=60s" }` | Arguments to pass into `go test`. | +| `dap_go_enabled` | `false` | Leverage [leoluz/nvim-dap-go](https://github.com/leoluz/nvim-dap-go) for debugging tests. | +| `dap_go_opts` | `{}` | Options to pass into `require("dap-go").setup()`. | +| `warn_duplicate_test_names` | `true` | Warn about duplicate test names within the same Go module. | ### Example configuration: custom `go test` arguments diff --git a/lua/neotest-golang/options.lua b/lua/neotest-golang/options.lua index e6b1b4ba..91ced1aa 100644 --- a/lua/neotest-golang/options.lua +++ b/lua/neotest-golang/options.lua @@ -15,6 +15,7 @@ function Opts:new(opts) } self.dap_go_enabled = opts.dap_go_enabled or false self.dap_go_opts = opts.dap_go_opts or {} + self.warn_duplicate_test_names = opts.warn_duplicate_test_names or true end --- A convenience function to get the current options. @@ -23,6 +24,7 @@ function Opts:get() go_test_args = self.go_test_args, dap_go_enabled = self.dap_go_enabled, dap_go_opts = self.dap_go_opts, + warn_duplicate_test_names = self.warn_duplicate_test_names, } end diff --git a/lua/neotest-golang/results_dir.lua b/lua/neotest-golang/results_dir.lua index 91583a0a..99554a90 100644 --- a/lua/neotest-golang/results_dir.lua +++ b/lua/neotest-golang/results_dir.lua @@ -1,5 +1,6 @@ local async = require("neotest.async") +local options = require("neotest-golang.options") local convert = require("neotest-golang.convert") local json = require("neotest-golang.json") local utils = require("neotest-golang.utils") @@ -249,27 +250,30 @@ end --- @return nil function M.show_warnings(d) -- warn if Go package/test is missing from tree node. - -- TODO: make configurable to skip this or use different log level? for pos_id, test_data in pairs(d) do if test_data.gotest_data.pkg == "" or test_data.gotest_data.name == "" then vim.notify( - "Unable to associate go package/test with neotest tree node: " .. pos_id, + "Unable to associate go package/test with neotest tree node: " + .. pos_id + .. ". Please file a bug report at " + .. "https://github.com/fredrikaverpil/neotest-golang/issues", vim.log.levels.WARN ) end end -- warn about duplicate tests - -- TODO: make debug level configurable - for pos_id, test_data in pairs(d) do - if test_data.duplicate_test_detected == true then - vim.notify( - "Duplicate test name detected: " - .. test_data.gotest_data.pkg - .. "/" - .. test_data.gotest_data.name, - vim.log.levels.WARN - ) + if options.get().warn_duplicate_test_names == true then + for pos_id, test_data in pairs(d) do + if test_data.duplicate_test_detected == true then + vim.notify( + "Duplicate test name detected: " + .. test_data.gotest_data.pkg + .. "/" + .. test_data.gotest_data.name, + vim.log.levels.WARN + ) + end end end end