diff --git a/lua/neotest-golang/options.lua b/lua/neotest-golang/options.lua index d6af4826..83412541 100644 --- a/lua/neotest-golang/options.lua +++ b/lua/neotest-golang/options.lua @@ -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", @@ -16,6 +17,9 @@ 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_test_name_dupes = opts.warn_test_name_dupes 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. @@ -25,6 +29,7 @@ function Opts:get() dap_go_enabled = self.dap_go_enabled, dap_go_opts = self.dap_go_opts, warn_test_name_dupes = self.warn_test_name_dupes, + debug_test_not_associated = self.debug_test_not_associated, } end diff --git a/lua/neotest-golang/results_dir.lua b/lua/neotest-golang/results_dir.lua index bc4331fe..9a654d5c 100644 --- a/lua/neotest-golang/results_dir.lua +++ b/lua/neotest-golang/results_dir.lua @@ -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 --- @param gotest_output table --- @param golist_output table @@ -266,14 +269,20 @@ end --- @param d table --- @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). + 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:\n" .. table.concat(position_ids, "\n"), + vim.log.levels.DEBUG + ) end -- warn about duplicate tests diff --git a/tests/unit/options_spec.lua b/tests/unit/options_spec.lua index 195d5ab0..fe597bbf 100644 --- a/tests/unit/options_spec.lua +++ b/tests/unit/options_spec.lua @@ -12,6 +12,9 @@ describe("Options are set up", function() "-timeout=60s", }, warn_test_name_dupes = true, + + -- dev options below. + debug_test_not_associated = false, } options.setup() assert.are_same(expected_options, options.get()) @@ -29,6 +32,9 @@ describe("Options are set up", function() "-timeout=60s", }, warn_test_name_dupes = true, + + -- dev options below. + debug_test_not_associated = false, } options.setup(expected_options) assert.are_same(expected_options, options.get())