From 84805093e18addd991f3a531d1bdaa16eadcf5cf Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Tue, 2 Jul 2024 21:26:57 +0200 Subject: [PATCH] feat(poc): use the dir logic for individual test --- lua/neotest-golang/init.lua | 2 +- lua/neotest-golang/results_test.lua | 4 ++++ lua/neotest-golang/runspec_test.lua | 23 ++++++++++++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lua/neotest-golang/init.lua b/lua/neotest-golang/init.lua index 88335583..71753543 100644 --- a/lua/neotest-golang/init.lua +++ b/lua/neotest-golang/init.lua @@ -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 diff --git a/lua/neotest-golang/results_test.lua b/lua/neotest-golang/results_test.lua index fbc5ba58..fad96aa8 100644 --- a/lua/neotest-golang/results_test.lua +++ b/lua/neotest-golang/results_test.lua @@ -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") diff --git a/lua/neotest-golang/runspec_test.lua b/lua/neotest-golang/runspec_test.lua index c6b28c22..5dd40332 100644 --- a/lua/neotest-golang/runspec_test.lua +++ b/lua/neotest-golang/runspec_test.lua @@ -1,5 +1,6 @@ local convert = require("neotest-golang.convert") local options = require("neotest-golang.options") +local json = require("neotest-golang.json") local M = {} @@ -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", @@ -37,6 +53,7 @@ function M.build(pos, strategy) context = { id = pos.id, test_filepath = pos.path, + golist_output = golist_output, pos_type = "test", }, }