Skip to content

Commit

Permalink
fix: include sub-test in test output (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil authored Jul 14, 2024
1 parent c068d37 commit 50c3d56
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions lua/neotest-golang/lib/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions lua/neotest-golang/lib/string.lua
Original file line number Diff line number Diff line change
@@ -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
10 changes: 8 additions & 2 deletions lua/neotest-golang/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 50c3d56

Please sign in to comment.