diff --git a/lua/neotest-golang/lib/init.lua b/lua/neotest-golang/lib/init.lua index 7ffb8f4f..ffc41be7 100644 --- a/lua/neotest-golang/lib/init.lua +++ b/lua/neotest-golang/lib/init.lua @@ -4,5 +4,6 @@ M.convert = require("neotest-golang.lib.convert") M.cmd = require("neotest-golang.lib.cmd") M.find = require("neotest-golang.lib.find") M.json = require("neotest-golang.lib.json") +M.string = require("neotest-golang.lib.string") return M diff --git a/lua/neotest-golang/lib/string.lua b/lua/neotest-golang/lib/string.lua new file mode 100644 index 00000000..73068424 --- /dev/null +++ b/lua/neotest-golang/lib/string.lua @@ -0,0 +1,13 @@ +local M = {} + +---Check if a string starts with a given prefix. +---@param str string +---@param prefix string +function M.starts_with(str, prefix) + if str == nil or prefix == nil then + return false + end + return str:sub(1, #prefix) == prefix +end + +return M diff --git a/lua/neotest-golang/process.lua b/lua/neotest-golang/process.lua index 1c36682b..5f882598 100644 --- a/lua/neotest-golang/process.lua +++ b/lua/neotest-golang/process.lua @@ -259,8 +259,14 @@ function M.decorate_with_go_test_results(res, gotest_output) for pos_id, test_data in pairs(res) do for _, line in ipairs(gotest_output) do if - test_data.gotest_data.pkg == line.Package - and test_data.gotest_data.name == line.Test + line.Package == test_data.gotest_data.pkg + and ( + line.Test == test_data.gotest_data.name + or lib.string.starts_with( + line.Test, + test_data.gotest_data.name .. "/" + ) + ) then -- record test status if line.Action == "pass" then