Skip to content

Commit

Permalink
refactor: break out function
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Oct 13, 2024
1 parent c0a8f4e commit d76d6e6
Showing 1 changed file with 38 additions and 58 deletions.
96 changes: 38 additions & 58 deletions lua/neotest-golang/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,7 @@ local default_runners = {
cmd = vim.list_extend(vim.deepcopy(cmd), required_go_test_args)
return cmd, nil
end,
output_processor = function(spec, result, tree)
local process = require("neotest-golang.process")
local pos = tree:data()
if pos.type == "dir" then
-- A test command executed a directory of tests and the output/status must
-- now be processed.
local results = process.test_results(spec, result, tree)
return results
elseif pos.type == "file" then
-- A test command executed a file of tests and the output/status must
-- now be processed.
local results = process.test_results(spec, result, tree)
return results
elseif pos.type == "namespace" then
-- A test command executed a namespace and the output/status must now be
-- processed.
local results = process.test_results(spec, result, tree)
return results
elseif pos.type == "test" then
-- A test command executed a single test and the output/status must now be
-- processed.
local results = process.test_results(spec, result, tree)
return results
end
logger.error(
"Cannot process test results due to unknown Neotest position type:"
.. pos.type
)
end,
output_processor = M.process_gotest_results,
},
gotestsum = {
cmd = function(cmd_data)
Expand Down Expand Up @@ -120,35 +92,7 @@ local default_runners = {
cmd = vim.list_extend(vim.deepcopy(cmd), required_go_test_args)
return cmd, json_filepath
end,
output_processor = function(spec, result, tree)
local process = require("neotest-golang.process")
local pos = tree:data()
if pos.type == "dir" then
-- A test command executed a directory of tests and the output/status must
-- now be processed.
local results = process.test_results(spec, result, tree)
return results
elseif pos.type == "file" then
-- A test command executed a file of tests and the output/status must
-- now be processed.
local results = process.test_results(spec, result, tree)
return results
elseif pos.type == "namespace" then
-- A test command executed a namespace and the output/status must now be
-- processed.
local results = process.test_results(spec, result, tree)
return results
elseif pos.type == "test" then
-- A test command executed a single test and the output/status must now be
-- processed.
local results = process.test_results(spec, result, tree)
return results
end
logger.error(
"Cannot process test results due to unknown Neotest position type:"
.. pos.type
)
end,
output_processor = M.process_gotest_results,
},
},
}
Expand Down Expand Up @@ -176,4 +120,40 @@ function M.set(updated_opts)
return opts
end

--- Output processing, assuming 'go test' output.
--- @async
--- @param spec neotest.RunSpec
--- @param result neotest.StrategyResult
--- @param tree neotest.Tree
--- @return table<string, neotest.Result> | nil
function M.process_gotest_results(spec, result, tree)
local process = require("neotest-golang.process")
local pos = tree:data()
if pos.type == "dir" then
-- A test command executed a directory of tests and the output/status must
-- now be processed.
local results = process.test_results(spec, result, tree)
return results
elseif pos.type == "file" then
-- A test command executed a file of tests and the output/status must
-- now be processed.
local results = process.test_results(spec, result, tree)
return results
elseif pos.type == "namespace" then
-- A test command executed a namespace and the output/status must now be
-- processed.
local results = process.test_results(spec, result, tree)
return results
elseif pos.type == "test" then
-- A test command executed a single test and the output/status must now be
-- processed.
local results = process.test_results(spec, result, tree)
return results
end
logger.error(
"Cannot process test results due to unknown Neotest position type:"
.. pos.type
)
end

return M

0 comments on commit d76d6e6

Please sign in to comment.