Skip to content

Commit

Permalink
feat: add maintainer/dev option for association problems
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Jun 24, 2024
1 parent 269ca36 commit 956c2b4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
5 changes: 5 additions & 0 deletions lua/neotest-golang/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local Opts = {}

--- Create a new options object.
function Opts:new(opts)
-- end-user options below.
self.go_test_args = opts.go_test_args
or {
"-v",
Expand All @@ -17,6 +18,9 @@ function Opts:new(opts)
self.dap_go_opts = opts.dap_go_opts or {}
self.warn_test_name_dupes = opts.warn_test_name_dupes or true
self.warn_test_not_executed = opts.warn_test_not_executed or true

-- dev options below, not meant for end-users.
self.debug_test_not_associated = opts.debug_test_not_associated or false
end

--- A convenience function to get the current options.
Expand All @@ -27,6 +31,7 @@ function Opts:get()
dap_go_opts = self.dap_go_opts,
warn_test_name_dupes = self.warn_test_name_dupes,
warn_test_not_executed = self.warn_test_not_executed,
debug_test_not_associated = self.debug_test_not_associated,
}
end

Expand Down
25 changes: 18 additions & 7 deletions lua/neotest-golang/results_dir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ end
--- The strategy here is to loop over the Neotest position data, and figure out
--- which position belongs to a specific Go package (using the output from
--- 'go list -json').
---
--- If a test cannot be decorated with Go package/test name data, an association
--- warning will be shown (see show_warnings).
--- @param res table<string, TestData>
--- @param gotest_output table
--- @param golist_output table
Expand Down Expand Up @@ -266,14 +269,22 @@ end
--- @param d table<string, TestData>
--- @return nil
function M.show_warnings(d)
-- warn if Go package/test is missing from tree node.
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,
vim.log.levels.WARN
)
if options.get().debug_test_not_associated == true then
-- warn if Go package/test is missing for given Neotest position id (Neotest tree node).
-- NOTE: this may be a temporary debug/warning, which could be removed later, hence why it is
-- not part of the public adapter options.
local position_ids = {}
for pos_id, test_data in pairs(d) do
if
test_data.gotest_data.pkg == "" or test_data.gotest_data.name == ""
then
table.insert(position_ids, pos_id)
end
end
vim.notify(
"Test(s) not found/not associated:\n" .. table.concat(position_ids, "\n"),
vim.log.levels.DEBUG
)
end

if options.get().warn_test_name_dupes == true then
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/options_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ describe("Options are set up", function()
},
warn_test_name_dupes = true,
warn_test_not_executed = true,

-- dev options below.
debug_test_not_associated = false,
}
options.setup()
assert.are_same(expected_options, options.get())
Expand All @@ -31,6 +34,9 @@ describe("Options are set up", function()
},
warn_test_name_dupes = true,
warn_test_not_executed = true,

-- dev options below.
debug_test_not_associated = false,
}
options.setup(expected_options)
assert.are_same(expected_options, options.get())
Expand Down

0 comments on commit 956c2b4

Please sign in to comment.