Skip to content

Commit

Permalink
refactor: use tree:data().type for position type
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Sep 8, 2024
1 parent 963d6e0 commit 43985f1
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 24 deletions.
12 changes: 7 additions & 5 deletions lua/neotest-golang/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,27 @@ end
--- @param tree neotest.Tree
--- @return table<string, neotest.Result> | nil
function M.Adapter.results(spec, result, tree)
if spec.context.pos_type == "dir" then
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)
M.workaround_neotest_issue_391(result)
return results
elseif spec.context.pos_type == "file" then
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)
M.workaround_neotest_issue_391(result)
return results
elseif spec.context.pos_type == "namespace" then
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)
M.workaround_neotest_issue_391(result)
return results
elseif spec.context.pos_type == "test" then
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)
Expand All @@ -163,7 +165,7 @@ function M.Adapter.results(spec, result, tree)

logger.error(
"Cannot process test results due to unknown Neotest position type:"
.. spec.context.pos_type
.. pos.type
)
end

Expand Down
14 changes: 0 additions & 14 deletions lua/neotest-golang/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ local logger = require("neotest-golang.logging")
local options = require("neotest-golang.options")
local lib = require("neotest-golang.lib")

-- TODO: remove pos_type when properly supporting all position types.
-- and instead get this from the pos.type field.

--- @class RunspecContext
--- @field pos_id string Neotest tree position id.
--- @field pos_type neotest.PositionType Neotest tree position type.
--- @field golist_data table<string, string> Filepath to 'go list' JSON data (lua table). -- TODO: rename to golist_data
--- @field golist_error? string Error message from 'go list' command.
--- @field parse_test_results boolean If true, parsing of test output will occur.
Expand Down Expand Up @@ -78,16 +74,6 @@ function M.test_results(spec, result, tree)
--- @type neotest.Position
local pos = tree:data()

-- Sanity check
-- TODO: refactor so that we use pos.type and pos.id instead of passing them separately on the context
if options.get().dev_notifications == true then
if pos.id ~= context.pos_id then
logger.error(
"Neotest position id mismatch: " .. pos.id .. " vs " .. context.pos_id
)
end
end

--- The runner to use for running tests.
--- @type string
local runner = options.get().runner
Expand Down
1 change: 0 additions & 1 deletion lua/neotest-golang/runspec/dir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ function M.build(pos)
--- @type RunspecContext
local context = {
pos_id = pos.id,
pos_type = "dir",
golist_data = golist_data,
golist_error = golist_error,
parse_test_results = true,
Expand Down
2 changes: 0 additions & 2 deletions lua/neotest-golang/runspec/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ function M.build(pos, tree)
--- @type RunspecContext
local context = {
pos_id = pos.id,
pos_type = "file",
golist_data = golist_data,
golist_error = golist_error,
parse_test_results = true,
Expand All @@ -80,7 +79,6 @@ function M.return_skipped(pos)
--- @type RunspecContext
local context = {
pos_id = pos.id,
pos_type = "file",
golist_data = {}, -- no golist output
parse_test_results = false,
}
Expand Down
1 change: 0 additions & 1 deletion lua/neotest-golang/runspec/namespace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function M.build(pos)
--- @type RunspecContext
local context = {
pos_id = pos.id,
pos_type = "namespace",
golist_data = golist_data,
golist_error = golist_error,
parse_test_results = true,
Expand Down
1 change: 0 additions & 1 deletion lua/neotest-golang/runspec/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function M.build(pos, strategy)
--- @type RunspecContext
local context = {
pos_id = pos.id,
pos_type = "test",
golist_data = golist_data,
golist_error = golist_error,
parse_test_results = true,
Expand Down

0 comments on commit 43985f1

Please sign in to comment.