write all failed test into the quickfix list

This commit is contained in:
2025-12-29 21:13:17 +01:00
parent b916a11481
commit 3615ac0e2f
17 changed files with 1065 additions and 2 deletions

View File

@@ -35,6 +35,7 @@ local apply_border_kind
local close_container
local restore_listing_full
local close_detail_float
local jump_to_first_quickfix
local function disable_container_maps(buf)
local opts = { buffer = buf, nowait = true, silent = true }
@@ -356,6 +357,14 @@ close_container = function()
end
end
jump_to_first_quickfix = function()
close_container()
local info = vim.fn.getqflist({ size = 0 })
if type(info) == "table" and (info.size or 0) > 0 then
vim.cmd("cfirst")
end
end
close_detail_float = function()
if state.detail_win and vim.api.nvim_win_is_valid(state.detail_win) then
pcall(vim.api.nvim_win_close, state.detail_win, true)
@@ -481,6 +490,9 @@ local function create_output_win(initial_lines)
vim.keymap.set("n", "<leader>z", function()
M.toggle_detail_full()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>qn", function()
jump_to_first_quickfix()
end, { buffer = buf, nowait = true, silent = true })
disable_container_maps(buf)
state.last_win = listing
@@ -533,6 +545,9 @@ local function reopen_output_win()
vim.keymap.set("n", "<leader>z", function()
M.toggle_detail_full()
end, { buffer = state.last_buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>qn", function()
jump_to_first_quickfix()
end, { buffer = state.last_buf, nowait = true, silent = true })
disable_container_maps(state.last_buf)
state.last_win = win
@@ -845,6 +860,9 @@ local function ensure_detail_buf(lines)
vim.keymap.set("n", "<C-c>", function()
close_detail_float()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>qn", function()
jump_to_first_quickfix()
end, { buffer = buf, nowait = true, silent = true })
disable_container_maps(buf)
end
local clean_lines, highlights = parse_ansi_lines(normalize_output_lines(lines))
@@ -1243,16 +1261,41 @@ local function apply_result_highlights(buf, start_line, lines)
end
end
local function collect_failure_names_from_listing()
if not (state.last_buf and vim.api.nvim_buf_is_valid(state.last_buf)) then
return {}
end
local lines = vim.api.nvim_buf_get_lines(state.last_buf, 0, -1, false)
local out = {}
local seen = {}
for idx, line in ipairs(lines) do
if line:match("^%[ FAIL %]") then
local name = state.last_result_line_map[idx]
if not name then
name = line:match("^%[ FAIL %] %-%s*(.+)$")
end
if name and name ~= "" and not seen[name] then
seen[name] = true
table.insert(out, name)
end
end
end
return out
end
local function run_command(command, opts)
local options = opts or {}
state.last_test_outputs = {}
state.last_result_line_map = {}
state.last_raw_output = nil
local failures = {}
local failures_seen = {}
if command and type(command.cmd) == "table" and #command.cmd > 0 then
if options.save_last ~= false then
state.last_command = {
cmd = vim.deepcopy(command.cmd),
cwd = command.cwd,
file = command.file,
}
state.last_runner = options.runner
end
@@ -1260,6 +1303,7 @@ local function run_command(command, opts)
state.last_scope_command = {
cmd = vim.deepcopy(command.cmd),
cwd = command.cwd,
file = command.file,
}
state.last_scope_runner = options.runner
state.last_scope_kind = options.scope_kind
@@ -1321,6 +1365,14 @@ local function run_command(command, opts)
return
end
had_parsed_output = true
if type(results.failures) == "table" then
for _, name in ipairs(results.failures) do
if name and name ~= "" and not failures_seen[name] then
failures_seen[name] = true
table.insert(failures, name)
end
end
end
update_summary(summary, results)
update_summary(result_counts, results)
if options.track_scope then
@@ -1446,6 +1498,50 @@ local function run_command(command, opts)
if options.track_scope then
state.last_scope_exit_code = code
end
local items = {}
local failures_for_qf = failures
if options.track_scope and type(state.last_scope_failures) == "table" then
local merged = {}
local seen = {}
for _, name in ipairs(failures or {}) do
if name and not seen[name] then
seen[name] = true
table.insert(merged, name)
end
end
for _, name in ipairs(state.last_scope_failures or {}) do
if name and not seen[name] then
seen[name] = true
table.insert(merged, name)
end
end
failures_for_qf = merged
end
local listing_failures = collect_failure_names_from_listing()
if #listing_failures > 0 then
local merged = {}
local seen = {}
for _, name in ipairs(failures_for_qf or {}) do
if name and not seen[name] then
seen[name] = true
table.insert(merged, name)
end
end
for _, name in ipairs(listing_failures) do
if name and not seen[name] then
seen[name] = true
table.insert(merged, name)
end
end
failures_for_qf = merged
end
if #failures_for_qf > 0 and runner and type(runner.collect_failed_locations) == "function" then
local ok_collect, collected = pcall(runner.collect_failed_locations, failures_for_qf, command, options.scope_kind)
if ok_collect and type(collected) == "table" then
items = collected
end
end
vim.fn.setqflist({}, "r", { title = "Test-Samurai Failures", items = items })
end,
})
end
@@ -1507,6 +1603,7 @@ function M.run_nearest()
vim.notify("[test-samurai] Runner failed to build command", vim.log.levels.ERROR)
return
end
command.file = spec.file
local parser = runner.output_parser
if type(parser) == "function" then
@@ -1539,6 +1636,7 @@ function M.run_file()
vim.notify("[test-samurai] Runner failed to build file command", vim.log.levels.ERROR)
return
end
command.file = util.get_buf_path(bufnr)
local parser = runner.output_parser
if type(parser) == "function" then
@@ -1571,6 +1669,7 @@ function M.run_all()
vim.notify("[test-samurai] Runner failed to build all-tests command", vim.log.levels.ERROR)
return
end
command.file = util.get_buf_path(bufnr)
local parser = runner.output_parser
if type(parser) == "function" then
@@ -1625,6 +1724,9 @@ function M.run_failed_only()
end
local runner = state.last_scope_runner
if state.last_scope_command and state.last_scope_command.file then
command.file = state.last_scope_command.file
end
local parser = nil
if runner then
parser = runner.output_parser