diff --git a/lua/neotest-golang/ast.lua b/lua/neotest-golang/ast.lua index b350f38e..f2eebe8f 100644 --- a/lua/neotest-golang/ast.lua +++ b/lua/neotest-golang/ast.lua @@ -193,8 +193,6 @@ function M.detect_tests(file_path) testify.add(file_path, function_name, receiver) -- FIXME: accumulates forever end - vim.notify(vim.inspect(testify.get())) - return tree_with_merged_namespaces end diff --git a/lua/neotest-golang/init.lua b/lua/neotest-golang/init.lua index fde29203..6cb3f97b 100644 --- a/lua/neotest-golang/init.lua +++ b/lua/neotest-golang/init.lua @@ -119,7 +119,9 @@ function M.Adapter.build_spec(args) elseif pos.type == "namespace" then -- A runspec is to be created, based on running all tests in the given -- namespace. - return runspec_namespace.build(pos) + + -- return runspec_namespace.build(pos) + return -- delegate to type 'test' elseif pos.type == "test" then -- A runspec is to be created, based on on running the given test. return runspec_test.build(pos, args.strategy) diff --git a/lua/neotest-golang/parse.lua b/lua/neotest-golang/parse.lua index 424e5dfc..730840ae 100644 --- a/lua/neotest-golang/parse.lua +++ b/lua/neotest-golang/parse.lua @@ -6,6 +6,7 @@ local async = require("neotest.async") local options = require("neotest-golang.options") local convert = require("neotest-golang.convert") local json = require("neotest-golang.json") +local testify = require("neotest-golang.testify") -- TODO: remove pos_type when properly supporting all position types. -- and instead get this from the pos.type field. @@ -192,6 +193,22 @@ function M.gather_neotest_data_and_set_defaults(tree) return res end +local function hack(test_name) + -- HACK: replace receiver with suite for testify. + -- TODO: place this under opt-in option. + -- TODO: could make more efficient by matching on filename first? + for filename, data in pairs(testify.get()) do + for _, entry in ipairs(data) do + -- TODO: better, more reliable matching needed + if string.match(test_name, "^" .. entry.suite .. "/") then + test_name = string.gsub(test_name, entry.suite, entry.receiver) + return test_name + end + end + end + return test_name +end + --- Decorate the internal test result data with go package and test name. --- This is an important step, in which we figure out exactly which test output --- belongs to which test in the Neotest position tree. @@ -225,7 +242,7 @@ function M.decorate_with_go_package_and_test_name( if gotestline.Package == golistline.ImportPath then local pattern = convert.to_lua_pattern(folderpath) .. "/(.-)/" - .. convert.to_lua_pattern(gotestline.Test) + .. convert.to_lua_pattern(hack(gotestline.Test)) .. "$" match = tweaked_pos_id:find(pattern, 1, false) if match ~= nil then @@ -233,6 +250,8 @@ function M.decorate_with_go_package_and_test_name( test_data.gotest_data.name = gotestline.Test break end + + -- HACK: testify suites end if match ~= nil then break diff --git a/lua/neotest-golang/runspec_test.lua b/lua/neotest-golang/runspec_test.lua index e1bb50c8..7be3f956 100644 --- a/lua/neotest-golang/runspec_test.lua +++ b/lua/neotest-golang/runspec_test.lua @@ -4,6 +4,7 @@ local convert = require("neotest-golang.convert") local options = require("neotest-golang.options") local cmd = require("neotest-golang.cmd") local dap = require("neotest-golang.dap") +local testify = require("neotest-golang.testify") local M = {} @@ -16,8 +17,20 @@ function M.build(pos, strategy) local test_folder_absolute_path = string.match(pos.path, "(.+)/") local golist_data = cmd.golist_data(test_folder_absolute_path) + local pos_id = pos.id + + -- HACK: replace receiver with suite for testify. + -- TODO: place this under opt-in option. + for filename, data in pairs(testify.get()) do + for _, entry in ipairs(data) do + if string.match(pos_id, "::" .. entry.receiver .. "::") then + pos_id = string.gsub(pos_id, entry.receiver, entry.suite) + end + end + end + --- @type string - local test_name = convert.to_gotest_test_name(pos.id) + local test_name = convert.to_gotest_test_name(pos_id) test_name = convert.to_gotest_regex_pattern(test_name) local test_cmd, json_filepath = cmd.test_command_in_package_with_regexp( diff --git a/lua/neotest-golang/testify.lua b/lua/neotest-golang/testify.lua index 5c03cbda..f2961018 100644 --- a/lua/neotest-golang/testify.lua +++ b/lua/neotest-golang/testify.lua @@ -9,11 +9,14 @@ function M.get() return lookup_map end -function M.add(file_name, suite_name, test_name) +function M.add(file_name, suite_name, receiver_name) if not lookup_map[file_name] then lookup_map[file_name] = {} end - table.insert(lookup_map[file_name], { suite = suite_name, test = test_name }) + table.insert( + lookup_map[file_name], + { suite = suite_name, receiver = receiver_name } + ) end function M.clear()