From 4e71a1dbd9cb32215244cf5ce43e470e177d6ddd Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sat, 15 Jun 2024 23:40:17 +0200 Subject: [PATCH] refactor: workaround --- lua/neotest-golang/init.lua | 24 +++++++++++++++++++----- lua/neotest-golang/results_dir.lua | 5 ----- lua/neotest-golang/results_test.lua | 5 ----- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lua/neotest-golang/init.lua b/lua/neotest-golang/init.lua index 4c26367f..68ae3966 100644 --- a/lua/neotest-golang/init.lua +++ b/lua/neotest-golang/init.lua @@ -93,12 +93,13 @@ function M.Adapter.build_spec(args) if pos.type == "dir" and pos.path == vim.fn.getcwd() then -- A runspec is to be created, based on running all tests in the given - -- directory. In this case, the directory is also the $CWD, and likely, the - -- project root. + -- directory. In this case, the directory is also the current working + -- directory. return runspec_dir.build(pos) elseif pos.type == "dir" then -- A runspec is to be created, based on running all tests in the given - -- directory. In this case, the directory is a sub-directory of the $CWD. + -- directory. In this case, the directory is a sub-directory of the current + -- working directory. return runspec_dir.build(pos) elseif pos.type == "file" then -- A runspec is to be created, based on on running all tests in the given @@ -130,11 +131,15 @@ function M.Adapter.results(spec, result, tree) if spec.context.test_type == "dir" then -- A test command executed a directory of tests and the output/status must -- now be processed. - return results_dir.results(spec, result, tree) + local results = results_dir.results(spec, result, tree) + M.workaround_neotest_issue_391(result) + return results elseif spec.context.test_type == "test" then -- A test command executed a single test and the output/status must now be -- processed. - return results_test.results(spec, result, tree) + local results = results_test.results(spec, result, tree) + M.workaround_neotest_issue_391(result) + return results end vim.notify( @@ -144,6 +149,15 @@ function M.Adapter.results(spec, result, tree) ) end +--- Workaround, to avoid JSON in output panel, erase contents of output. +--- @param result neotest.StrategyResult +function M.workaround_neotest_issue_391(result) + -- FIXME: once output is parsed, erase file contents, so to avoid JSON in + -- output panel. This is a workaround for now, only because of + -- https://github.com/nvim-neotest/neotest/issues/391 + vim.fn.writefile({ "" }, result.output) +end + --- Adapter options. setmetatable(M.Adapter, { __call = function(_, opts) diff --git a/lua/neotest-golang/results_dir.lua b/lua/neotest-golang/results_dir.lua index 9423d0c4..ab45c61b 100644 --- a/lua/neotest-golang/results_dir.lua +++ b/lua/neotest-golang/results_dir.lua @@ -48,11 +48,6 @@ function M.results(spec, result, tree) -- DEBUG: enable the following to see the final Neotest result. -- vim.notify(vim.inspect(neotest_results), vim.log.levels.DEBUG) - -- FIXME: once output is parsed, erase file contents, so to avoid JSON in - -- output panel. This is a workaround for now, only because of - -- https://github.com/nvim-neotest/neotest/issues/391 - vim.fn.writefile({ "" }, result.output) - return neotest_results end diff --git a/lua/neotest-golang/results_test.lua b/lua/neotest-golang/results_test.lua index 71ad4439..7ab33a66 100644 --- a/lua/neotest-golang/results_test.lua +++ b/lua/neotest-golang/results_test.lua @@ -85,11 +85,6 @@ function M.results(spec, result, tree) errors = errors, } - -- FIXME: once output is parsed, erase file contents, so to avoid JSON in - -- output panel. This is a workaround for now, only because of - -- https://github.com/nvim-neotest/neotest/issues/391 - vim.fn.writefile({ "" }, result.output) - return results end