fix TestNearest at execution within nested sub tests
tests / test (push) Successful in 21s

This commit is contained in:
2026-06-08 18:29:10 +02:00
parent 8f09942511
commit 544012de3f
2 changed files with 98 additions and 1 deletions
+55
View File
@@ -223,4 +223,59 @@ describe("test-samurai-go-runner", function()
assert.equals(file, items[1].filename)
assert.equals(5, items[1].lnum)
end)
it("filters parent tests for subtest scope", function()
-- This is a simpler test of the filtering logic
-- In real usage, parser_state.spec_scope = "subtest" is passed through core.lua
local passes = { "TestFoo", "TestFoo/first" }
local failures = {}
local skips = {}
-- Manually call what parse_results should do
local all_tests = {}
for _, n in ipairs(passes) do table.insert(all_tests, n) end
for _, n in ipairs(failures) do table.insert(all_tests, n) end
for _, n in ipairs(skips) do table.insert(all_tests, n) end
local has_children = {}
for _, n in ipairs(all_tests) do
local root = n:match("^([^/]+)/")
if root then has_children[root] = true end
end
-- TestFoo should have been marked as having children
assert.is_true(has_children["TestFoo"], "TestFoo should be marked as having children")
local filtered_passes = {}
for _, n in ipairs(passes) do
if not has_children[n] then
table.insert(filtered_passes, n)
end
end
assert.are.same({ "TestFoo/first" }, filtered_passes, "TestFoo should be filtered out")
end)
it("parse_results keeps parent test when spec_scope is function", function()
local output = table.concat({
vim.json.encode({ Action = "run", Test = "TestFoo" }),
vim.json.encode({ Action = "pass", Test = "TestFoo" }),
vim.json.encode({ Action = "pass", Test = "TestFoo/first" }),
}, "\n")
local parser_state = { spec_scope = "function" }
local results = runner.parse_results(output, parser_state)
assert.are.same({ "TestFoo", "TestFoo/first" }, results.passes)
end)
it("parse_results keeps parent test when setup fails even in subtest scope", function()
local output = table.concat({
vim.json.encode({ Action = "run", Test = "TestFoo" }),
vim.json.encode({ Action = "fail", Test = "TestFoo" }),
}, "\n")
local parser_state = { spec_scope = "subtest" }
local results = runner.parse_results(output, parser_state)
assert.are.same({ "TestFoo" }, results.failures)
end)
end)