Skip to content

Commit

Permalink
refactor: bring back warning
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Jul 16, 2024
1 parent ab2b01c commit cb866d5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ You can run `:checkhealth neotest-golang` to review common issues.

## ⚙️ Configuration

| Argument | Default value | Description |
| ---------------------- | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `go_test_args` | `{ "-v", "-race", "-count=1" }` | 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()`. |
| `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. |
| Argument | Default value | Description |
| ------------------------ | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `go_test_args` | `{ "-v", "-race", "-count=1" }` | 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()`. |
| `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. |
| `warn_test_not_executed` | `true` | Warn if test was not executed. |

### Example configuration: custom `go test` arguments

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 @@ -12,6 +12,7 @@ local opts = {
dap_go_opts = {},
testify_enabled = false,
warn_test_name_dupes = true,
warn_test_not_executed = true,

-- experimental, for now undocumented, options
runner = "go", -- or "gotestsum"
Expand Down
17 changes: 8 additions & 9 deletions lua/neotest-golang/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function M.test_results(spec, result, tree)
local pos = tree:data()

-- Sanity check
-- TODO: refactor so that we use pos.type and pos.id instead of passing them separately on the context
if options.get().dev_notifications == true then
if pos.id ~= context.pos_id then
logger.error(
Expand Down Expand Up @@ -310,8 +311,8 @@ end
--- @param d table<string, TestData>
--- @return nil
function M.show_warnings(d)
if options.get().dev_notifications == true then
-- warn if Go package/test is missing for given Neotest position id (Neotest tree node).
-- warn if Go package/test is missing for given Neotest position id (Neotest tree node).
if options.get().warn_test_not_executed == true then
--- @type table<string>
local position_ids = {}
for pos_id, test_data in pairs(d) do
Expand All @@ -322,10 +323,10 @@ function M.show_warnings(d)
end
end
if #position_ids > 0 then
local msg = "Test(s) not associated (not found/executed):\n"
.. table.concat(position_ids, "\n")
vim.notify(msg, vim.log.levels.DEBUG)
logger.debug(msg)
logger.warn({
"Test(s) not associated (not found/executed): ",
position_ids,
})
end
end

Expand All @@ -341,9 +342,7 @@ function M.show_warnings(d)
end
end
if #test_dupes > 0 then
logger.warn(
"Duplicate test name(s) detected:\n" .. table.concat(test_dupes, "\n")
)
logger.warn({ "Duplicate test name(s) detected: ", test_dupes })
end
end
end
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 @@ -13,6 +13,7 @@ describe("Options are set up", function()
dap_go_opts = {},
testify_enabled = false,
warn_test_name_dupes = true,
warn_test_not_executed = true,

-- experimental
runner = "go",
Expand All @@ -35,6 +36,7 @@ describe("Options are set up", function()
dap_go_opts = {},
testify_enabled = false,
warn_test_name_dupes = true,
warn_test_not_executed = true,

-- experimental
runner = "go",
Expand Down

0 comments on commit cb866d5

Please sign in to comment.