Skip to content

Commit

Permalink
feat: warn about duplicate test names
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Jun 17, 2024
1 parent ddba25f commit 929e8fb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions lua/neotest-golang/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
28 changes: 16 additions & 12 deletions lua/neotest-golang/results_dir.lua
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 929e8fb

Please sign in to comment.