Skip to content

Commit

Permalink
refactor: workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Jun 15, 2024
1 parent e56d235 commit 4e71a1d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
24 changes: 19 additions & 5 deletions lua/neotest-golang/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions lua/neotest-golang/results_dir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 0 additions & 5 deletions lua/neotest-golang/results_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4e71a1d

Please sign in to comment.