add rerun function from within the listing-float
All checks were successful
tests / test (push) Successful in 8s

This commit is contained in:
2026-01-07 20:11:53 +01:00
parent 5d0b4e9dd6
commit 924584d8b3
4 changed files with 173 additions and 1 deletions

View File

@@ -418,4 +418,102 @@ describe("test-samurai core (no bundled runners)", function()
vim.fn.jobstart = orig_jobstart
end)
it("runs the test under the cursor from the listing", function()
local runner = {
name = "test-runner-run-cursor",
}
function runner.is_test_file(_bufnr)
return true
end
function runner.find_nearest(bufnr, _row, _col)
return { file = vim.api.nvim_buf_get_name(bufnr), cwd = vim.loop.cwd(), test_name = "TestA" }
end
local build_specs = {}
function runner.build_command(spec)
table.insert(build_specs, vim.deepcopy(spec))
return { cmd = { "echo", "single" }, cwd = spec.cwd }
end
function runner.build_file_command(_bufnr)
return { cmd = { "echo", "file" } }
end
function runner.build_all_command(_bufnr)
return { cmd = { "echo", "all" } }
end
function runner.build_failed_command(last_command, _failures, _scope_kind)
return { cmd = { "echo", "failed" }, cwd = last_command and last_command.cwd or nil }
end
function runner.parse_results(_output)
return { passes = { "TestA" }, failures = { "TestC" }, skips = { "TestB" } }
end
function runner.output_parser()
return {
on_line = function(_line, _state)
return nil
end,
on_complete = function(output, _state)
return runner.parse_results(output)
end,
}
end
function runner.parse_test_output(_output)
return {}
end
function runner.collect_failed_locations(_failures, _command, _scope_kind)
return {}
end
package.loaded["test-samurai-run-cursor-runner"] = runner
test_samurai.setup({ runner_modules = { "test-samurai-run-cursor-runner" } })
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(bufnr, "/tmp/test_samurai_run_cursor.go")
vim.bo[bufnr].filetype = "go"
vim.api.nvim_set_current_buf(bufnr)
local orig_jobstart = vim.fn.jobstart
vim.fn.jobstart = function(_cmd, opts)
if opts.on_exit then
opts.on_exit(nil, 0, nil)
end
return 1
end
runner._last_mocha_titles = { TestC = "Suite TestC" }
core.run_nearest()
local listing_buf = vim.api.nvim_get_current_buf()
local lines = vim.api.nvim_buf_get_lines(listing_buf, 0, -1, false)
local target = nil
for i, line in ipairs(lines) do
if line:match("^%[ FAIL %] %-") then
target = i
break
end
end
assert.is_true(target ~= nil)
vim.api.nvim_win_set_cursor(0, { target, 0 })
core.run_test_at_cursor()
vim.api.nvim_win_set_cursor(0, { 1, 0 })
core.run_test_at_cursor()
vim.fn.jobstart = orig_jobstart
assert.equals(2, #build_specs)
assert.equals("TestC", build_specs[2].test_name)
assert.equals("TestC", build_specs[2].full_name)
assert.equals("Suite TestC", build_specs[2].mocha_full_title)
end)
end)