Skip to content

Commit

Permalink
fix(runner): mark files as skipped if no child tests run
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarriga committed Aug 3, 2022
1 parent 1ef91b5 commit 956ff67
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 45 deletions.
86 changes: 43 additions & 43 deletions lua/neotest/client/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,68 +180,68 @@ end
---@param results table<string, neotest.Result>
---@param partial? boolean
function TestRunner:_missing_results(tree, results, partial)
local new_results = setmetatable({}, {
local new_results = {}
local results_proxy = setmetatable({}, {
__index = function(_, key)
return results[key]
return new_results[key] or results[key]
end,
__newindex = function(_, key, value)
new_results[key] = value
end,
})
local root = tree:data()
local missing_tests = {}
for _, node in tree:iter_nodes() do
local pos = node:data()

if results[pos.id] then
for parent in node:iter_parents() do
local parent_pos = parent:data()
if not lib.positions.contains(root, parent_pos) then
break
end
local parent_result = results[parent_pos.id]
local pos_result = results[pos.id]
if not parent_result then
parent_result = { status = "passed", output = pos_result.output }
end

if pos_result.status ~= "skipped" then
if parent_result.status == "passed" then
parent_result.status = pos_result.status
end
end
local function propagate_result_upwards(node)
for parent in node:iter_parents() do
local parent_pos = parent:data()
if not lib.positions.contains(root, parent_pos) then
return
end

if pos_result.errors then
parent_result.errors = vim.list_extend(parent_result.errors or {}, pos_result.errors)
end
local parent_result = results_proxy[parent_pos.id]
local pos_result = results_proxy[node:data().id]
if not parent_result then
parent_result = { status = "passed" }
end

new_results[parent_pos.id] = parent_result
if pos_result.status ~= "skipped" and parent_result.status == "passed" then
parent_result.status = pos_result.status
end
else
if pos.type == "test" then
missing_tests[#missing_tests + 1] = pos.id

if pos_result.errors then
parent_result.errors = vim.list_extend(parent_result.errors or {}, pos_result.errors)
end

results_proxy[parent_pos.id] = parent_result
end
end

for _, node in tree:iter_nodes() do
local pos = node:data()
if results_proxy[pos.id] then
propagate_result_upwards(node)
elseif pos.type == "test" then
missing_tests[#missing_tests + 1] = pos.id
end
end

if partial then
for _, test_id in ipairs(missing_tests) do
for parent in tree:get_key(test_id):iter_parents() do
new_results[parent:data().id] = nil
results_proxy[parent:data().id] = nil
end
end
end

local root_result = results[root.id]
for _, node in tree:iter_nodes() do
local pos = node:data()
if pos.type ~= "dir" then
if pos.type == "file" then
else
local root_result = results_proxy[root.id]
for _, node in tree:iter_nodes() do
local pos = node:data()
if pos.type == "file" and not results_proxy[pos.id] then
-- Files not being present means that they were skipped (probably)
if not results[pos.id] and root_result then
new_results[pos.id] = { status = "skipped", output = root_result.output }
end
else
results_proxy[pos.id] = { status = "skipped" }
elseif pos.type ~= "dir" and not results_proxy[pos.id] and root_result then
-- Tests and namespaces not being present means that they failed to even start, count as root result
if not results[pos.id] and root_result then
new_results[pos.id] = { status = root_result.status, output = root_result.output }
end
results_proxy[pos.id] = { status = root_result.status }
end
end
end
Expand Down
43 changes: 41 additions & 2 deletions tests/unit/client/init_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("neotest client", function()
results = function(_, _, tree)
local results = {}
for _, pos in tree:iter() do
if pos.type == "file" or pos.type == "test" then
if pos.type == "test" then
results[pos.id] = {
status = "failed",
short = pos.name,
Expand Down Expand Up @@ -501,8 +501,47 @@ describe("neotest client", function()
client:run_tree(tree, { strategy = mock_strategy })
local results = client:get_results(mock_adapter.name)
for _, pos in tree:iter() do
assert.Not.Nil(results[pos.id])
if pos.type == "dir" then
assert.equal(results[pos.id].status, "failed")
end
end
end)

a.it("fills results for files from child files", function()
local tree = get_pos(dir)
exit_test()
client:run_tree(tree, { strategy = mock_strategy })
local results = client:get_results(mock_adapter.name)
for _, pos in tree:iter() do
if pos.type == "file" then
assert.equal(results[pos.id].status, "failed")
end
end
end)

a.it("fills empty file as skipped", function()
get_pos(dir)
mock_adapter.results = function()
return {}
end
mock_adapter.discover_positions = function()
return Tree.from_list({
{
id = dir .. "/dummy_file",
type = "file",
path = dir .. "/dummy_file",
name = dir .. "/dummy_file",
},
}, function(pos)
return pos.id
end)
end
client:_update_positions(dir .. "/dummy_file", { adapter = "adapter" })
local tree = get_pos(dir .. "/dummy_file")
exit_test()
client:run_tree(tree, { strategy = mock_strategy })
local results = client:get_results(mock_adapter.name)
assert.equal(results[dir .. "/dummy_file"].status, "skipped")
end)

a.it("fills results for namespaces from child tests", function()
Expand Down

0 comments on commit 956ff67

Please sign in to comment.