From b6c581c85fc460048f715e53f47c12c7d3e1e689 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Mon, 24 Jun 2024 13:46:07 +0200 Subject: [PATCH] feat: add maintainer/dev notification --- lua/neotest-golang/options.lua | 5 +++++ lua/neotest-golang/results_dir.lua | 26 +++++++++++++++++++------- tests/unit/options_spec.lua | 2 ++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lua/neotest-golang/options.lua b/lua/neotest-golang/options.lua index 475c4e82..29e49a2f 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", @@ -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.dev_notifications = opts.dev_notifications or false end --- A convenience function to get the current options. @@ -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, + dev_notifications = self.dev_notifications, } end diff --git a/lua/neotest-golang/results_dir.lua b/lua/neotest-golang/results_dir.lua index 1cdf3856..2b666eb6 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,23 @@ 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().dev_notifications == 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 associated (not found/executed):\n" + .. table.concat(position_ids, "\n"), + vim.log.levels.DEBUG + ) end if options.get().warn_test_name_dupes == true then diff --git a/tests/unit/options_spec.lua b/tests/unit/options_spec.lua index 37e137f9..d7807d0a 100644 --- a/tests/unit/options_spec.lua +++ b/tests/unit/options_spec.lua @@ -13,6 +13,7 @@ describe("Options are set up", function() }, warn_test_name_dupes = true, warn_test_not_executed = true, + dev_notifications = false, } options.setup() assert.are_same(expected_options, options.get()) @@ -31,6 +32,7 @@ describe("Options are set up", function() }, warn_test_name_dupes = true, warn_test_not_executed = true, + dev_notifications = false, } options.setup(expected_options) assert.are_same(expected_options, options.get())