From 6e071196ef9f1d9e053cc513e1b2b12dc97c950e Mon Sep 17 00:00:00 2001 From: Jay Morelli Date: Fri, 25 Oct 2024 16:25:12 +0100 Subject: [PATCH 1/6] feat: output colorizer --- lua/neotest-golang/process.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lua/neotest-golang/process.lua b/lua/neotest-golang/process.lua index e09f96ff..b53da525 100644 --- a/lua/neotest-golang/process.lua +++ b/lua/neotest-golang/process.lua @@ -302,6 +302,8 @@ function M.decorate_with_go_test_results(res, gotest_output) elseif line.Action == "fail" then test_data.status = "failed" elseif line.Action == "output" then + line.Output = M.colorizer(line.Output) + test_data.gotest_data.output = vim.list_extend(test_data.gotest_data.output, { line.Output }) @@ -334,6 +336,26 @@ function M.decorate_with_go_test_results(res, gotest_output) return res end +--- Colorize the test output based on the test result. +--- +--- It will colorize the test output line based on the test result (PASS - green, FAIL - red, SKIP - yellow). +--- @param output string +--- @return string +function M.colorizer(output) + if not options.get().colorize_test_output == true or not output then + return output + end + + if string.find(output, "FAIL") then + output = output:gsub("^", ""):gsub("$", "") -- colorizer red + elseif string.find(output, "PASS") then + output = output:gsub("^", ""):gsub("$", "") -- colorizer green + elseif string.find(output, "SKIP") then + output = output:gsub("^", ""):gsub("$", "") -- colorizer yellow + end + return output +end + --- Show warnings. --- @param d table --- @return nil @@ -391,6 +413,7 @@ function M.to_neotest_result(res) errors = test_data.errors, output = test_output_path, -- NOTE: could be slow when running many tests? } + vim.notify(vim.inspect(neotest_result[pos_id])) end return neotest_result From 429f83eba09333c781f7956958185072d24da2e1 Mon Sep 17 00:00:00 2001 From: Jay Morelli Date: Fri, 25 Oct 2024 16:25:27 +0100 Subject: [PATCH 2/6] docs: output colorizer options --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index e6ce033d..3013a846 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,7 @@ consider setting up neotest and its adapters in a | `go_list_args` | `{}` | Arguments to pass into `go list`. Note: [`-tags` usage](https://github.com/fredrikaverpil/neotest-golang#using-build-tags), [pass args as function](https://github.com/fredrikaverpil/neotest-golang#pass-arguments-as-function-instead-of-table). | | `dap_go_opts` | `{}` | Options to pass into `require("dap-go").setup()`. Note: [`-tags` usage](https://github.com/fredrikaverpil/neotest-golang#using-build-tags), [pass args as function](https://github.com/fredrikaverpil/neotest-golang#pass-arguments-as-function-instead-of-table). | | `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. | +| `colorize_test_output` | `false` | Enable output color for `SUCCESS`, `FAIL`, and `SKIP` tests. See [here](https://github.com/fredrikaverpil/neotest-golang#output-colors) 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. | @@ -573,6 +574,29 @@ feature... 🙈 > remedied at any time by extending the treesitter queries. Feel free to dig in > and open a PR! +### Output colors + +If you want to enable output colors for `SUCCESS`, `FAIL`, and `SKIP` tests, you must set the `colorize_test_output` option to `true`. This will colorize the output of the tests in the output panel. + +Configuration example: +```lua +return { + { + "nvim-neotest/neotest", + config = function() + require("neotest").setup({ + adapters = { + require("neotest-golang")({ + -- ... + colorize_test_output = true, + }), + }, + }) + end, + }, +} +``` + ### Using build tags If you need to set build tags (like e.g. `-tags debug` or `-tags "tag1 tag2"`), From e64292c12ab95c37ec21eaf33e21e8c5d56c8d29 Mon Sep 17 00:00:00 2001 From: Jay Morelli Date: Fri, 25 Oct 2024 16:30:24 +0100 Subject: [PATCH 3/6] chore: cleanup comments --- lua/neotest-golang/process.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lua/neotest-golang/process.lua b/lua/neotest-golang/process.lua index b53da525..3f14cc1b 100644 --- a/lua/neotest-golang/process.lua +++ b/lua/neotest-golang/process.lua @@ -336,8 +336,8 @@ function M.decorate_with_go_test_results(res, gotest_output) return res end ---- Colorize the test output based on the test result. ---- +--- Colorize the test output based on the test result. +--- --- It will colorize the test output line based on the test result (PASS - green, FAIL - red, SKIP - yellow). --- @param output string --- @return string @@ -347,11 +347,11 @@ function M.colorizer(output) end if string.find(output, "FAIL") then - output = output:gsub("^", ""):gsub("$", "") -- colorizer red + output = output:gsub("^", ""):gsub("$", "") elseif string.find(output, "PASS") then - output = output:gsub("^", ""):gsub("$", "") -- colorizer green + output = output:gsub("^", ""):gsub("$", "") elseif string.find(output, "SKIP") then - output = output:gsub("^", ""):gsub("$", "") -- colorizer yellow + output = output:gsub("^", ""):gsub("$", "") end return output end @@ -413,7 +413,6 @@ function M.to_neotest_result(res) errors = test_data.errors, output = test_output_path, -- NOTE: could be slow when running many tests? } - vim.notify(vim.inspect(neotest_result[pos_id])) end return neotest_result From 4fcaf068c63f0fff7fa27e236da96544d6f1c4f7 Mon Sep 17 00:00:00 2001 From: Jean Morelli <61237619+jaymorelli96@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:07:16 +0000 Subject: [PATCH 4/6] chore: apply suggestions from code review Co-authored-by: Fredrik Averpil --- README.md | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/README.md b/README.md index 3013a846..96ad1955 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ consider setting up neotest and its adapters in a | `go_list_args` | `{}` | Arguments to pass into `go list`. Note: [`-tags` usage](https://github.com/fredrikaverpil/neotest-golang#using-build-tags), [pass args as function](https://github.com/fredrikaverpil/neotest-golang#pass-arguments-as-function-instead-of-table). | | `dap_go_opts` | `{}` | Options to pass into `require("dap-go").setup()`. Note: [`-tags` usage](https://github.com/fredrikaverpil/neotest-golang#using-build-tags), [pass args as function](https://github.com/fredrikaverpil/neotest-golang#pass-arguments-as-function-instead-of-table). | | `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. | -| `colorize_test_output` | `false` | Enable output color for `SUCCESS`, `FAIL`, and `SKIP` tests. See [here](https://github.com/fredrikaverpil/neotest-golang#output-colors) for more info. | +| `colorize_test_output` | `true` | Enable output color for `SUCCESS`, `FAIL`, and `SKIP` tests. | | `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. | @@ -574,29 +574,6 @@ feature... 🙈 > remedied at any time by extending the treesitter queries. Feel free to dig in > and open a PR! -### Output colors - -If you want to enable output colors for `SUCCESS`, `FAIL`, and `SKIP` tests, you must set the `colorize_test_output` option to `true`. This will colorize the output of the tests in the output panel. - -Configuration example: -```lua -return { - { - "nvim-neotest/neotest", - config = function() - require("neotest").setup({ - adapters = { - require("neotest-golang")({ - -- ... - colorize_test_output = true, - }), - }, - }) - end, - }, -} -``` - ### Using build tags If you need to set build tags (like e.g. `-tags debug` or `-tags "tag1 tag2"`), From 87a641cf3ad4837e77abc0ff4ebf380afa04e569 Mon Sep 17 00:00:00 2001 From: Jay Morelli Date: Mon, 28 Oct 2024 14:07:45 +0000 Subject: [PATCH 5/6] refactor: make colorize test output default --- lua/neotest-golang/options.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/neotest-golang/options.lua b/lua/neotest-golang/options.lua index 0d0f7346..8caa54b2 100644 --- a/lua/neotest-golang/options.lua +++ b/lua/neotest-golang/options.lua @@ -13,6 +13,7 @@ local opts = { go_list_args = {}, -- NOTE: can also be a function dap_go_opts = {}, -- NOTE: can also be a function testify_enabled = false, + colorize_test_output = true, warn_test_name_dupes = true, warn_test_not_executed = true, From 95d508460dda49bda00de18491b3df4cc928617a Mon Sep 17 00:00:00 2001 From: Jay Morelli Date: Mon, 28 Oct 2024 14:14:32 +0000 Subject: [PATCH 6/6] chore: test options --- tests/unit/options_spec.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/options_spec.lua b/tests/unit/options_spec.lua index 199c6a26..e7859406 100644 --- a/tests/unit/options_spec.lua +++ b/tests/unit/options_spec.lua @@ -14,6 +14,7 @@ describe("Options are set up", function() gotestsum_args = { "--format=standard-verbose" }, dap_go_opts = {}, testify_enabled = false, + colorize_test_output = true, warn_test_name_dupes = true, warn_test_not_executed = true, @@ -37,6 +38,7 @@ describe("Options are set up", function() gotestsum_args = { "--format=standard-verbose" }, dap_go_opts = {}, testify_enabled = false, + colorize_test_output = false, warn_test_name_dupes = true, warn_test_not_executed = true, @@ -64,6 +66,7 @@ describe("Options are set up", function() return {} end, testify_enabled = false, + colorize_test_output = true, warn_test_name_dupes = true, warn_test_not_executed = true,