Skip to content

Commit

Permalink
feat(poc): use the dir logic for individual test
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Jul 2, 2024
1 parent 537c267 commit fee81a3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lua/neotest-golang/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function M.Adapter.results(spec, result, tree)
elseif spec.context.pos_type == "test" then
-- A test command executed a single test and the output/status must now be
-- processed.
local results = results_test.results(spec, result, tree)
local results = results_dir.results(spec, result, tree)
M.workaround_neotest_issue_391(result)
return results
end
Expand Down
4 changes: 4 additions & 0 deletions lua/neotest-golang/results_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ function M.results(spec, result, tree)
--- @type table
local raw_output = async.fn.readfile(result.output)

--- The 'go test' JSON output, converted into a lua table.
--- @type table
local gotest_output = json.process_gotest_output(raw_output)

--- @type string
local test_filepath = spec.context.test_filepath
local test_filename = vim.fn.fnamemodify(test_filepath, ":t")
Expand Down
23 changes: 20 additions & 3 deletions lua/neotest-golang/runspec_test.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local convert = require("neotest-golang.convert")
local options = require("neotest-golang.options")
local json = require("neotest-golang.json")

local M = {}

Expand All @@ -9,11 +10,26 @@ local M = {}
--- @return neotest.RunSpec | neotest.RunSpec[] | nil
function M.build(pos, strategy)
--- @type string
local test_name = convert.to_gotest_test_name(pos.id)
test_name = convert.to_gotest_regex_pattern(test_name)
local test_folder_absolute_path = string.match(pos.path, "(.+)/")

-- call 'go list -json ./...' to get test file data
local go_list_command = {
"go",
"list",
"-json",
"./...",
}
local go_list_command_result = vim.fn.system(
"cd "
.. test_folder_absolute_path
.. " && "
.. table.concat(go_list_command, " ")
)
local golist_output = json.process_golist_output(go_list_command_result)

--- @type string
local test_folder_absolute_path = string.match(pos.path, "(.+)/")
local test_name = convert.to_gotest_test_name(pos.id)
test_name = convert.to_gotest_regex_pattern(test_name)

local gotest = {
"go",
Expand All @@ -37,6 +53,7 @@ function M.build(pos, strategy)
context = {
id = pos.id,
test_filepath = pos.path,
golist_output = golist_output,
pos_type = "test",
},
}
Expand Down

0 comments on commit fee81a3

Please sign in to comment.