diff --git a/lua/neotest-golang/init.lua b/lua/neotest-golang/init.lua index 9b51eef4..9cd71379 100644 --- a/lua/neotest-golang/init.lua +++ b/lua/neotest-golang/init.lua @@ -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 = {} @@ -135,34 +135,8 @@ end --- @param tree neotest.Tree --- @return table | 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].output_processor(spec, result, tree) end --- Adapter options. diff --git a/lua/neotest-golang/options.lua b/lua/neotest-golang/options.lua index 6f9010dc..f8f587d0 100644 --- a/lua/neotest-golang/options.lua +++ b/lua/neotest-golang/options.lua @@ -53,6 +53,35 @@ 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, }, gotestsum = { cmd = function(cmd_data) @@ -91,6 +120,35 @@ 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, }, }, }