Skip to content

Commit

Permalink
refactor: delegate output processing to runner
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Oct 13, 2024
1 parent 5d2ca4d commit 9ef5aed
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 29 deletions.
32 changes: 3 additions & 29 deletions lua/neotest-golang/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local logger = require("neotest-golang.logging")
local options = require("neotest-golang.options")
local query = require("neotest-golang.query")
local runspec = require("neotest-golang.runspec")
local process = require("neotest-golang.process")
local lib = require("neotest-golang.lib")

local M = {}

Expand Down Expand Up @@ -135,34 +135,8 @@ end
--- @param tree neotest.Tree
--- @return table<string, neotest.Result> | nil
function M.Adapter.results(spec, result, tree)
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
)
local runner = lib.cmd.runner_fallback(options.get().runner)
return options.get().runners[runner].result(spec, result, tree)
end

--- Adapter options.
Expand Down
58 changes: 58 additions & 0 deletions lua/neotest-golang/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,35 @@ local default_runners = {
cmd = vim.list_extend(vim.deepcopy(cmd), required_go_test_args)
return cmd, nil
end,
result = 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,
},
gotestsum = {
cmd = function(cmd_data)
Expand Down Expand Up @@ -91,6 +120,35 @@ local default_runners = {
cmd = vim.list_extend(vim.deepcopy(cmd), required_go_test_args)
return cmd, json_filepath
end,
result = 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,
},
},
}
Expand Down

0 comments on commit 9ef5aed

Please sign in to comment.