Compare commits

...

2 Commits

Author SHA1 Message Date
238d5f9634 show always detail-float on <cr>
All checks were successful
tests / test (push) Successful in 8s
2026-01-08 13:47:45 +01:00
118f84c31e add convenient keymaps for test-command inspection 2026-01-08 13:21:01 +01:00
4 changed files with 173 additions and 3 deletions

View File

@@ -70,6 +70,8 @@ Additional keymaps:
- `<leader>ss` -> filter the listing to `[ SKIP ] - ...` entries - `<leader>ss` -> filter the listing to `[ SKIP ] - ...` entries
- `<leader>sa` -> clear the listing filter and show all entries - `<leader>sa` -> clear the listing filter and show all entries
- `<leader>tt` -> run the test under the cursor in the listing - `<leader>tt` -> run the test under the cursor in the listing
- `<leader>cb` -> breaks test-command onto multiple lines
- `<leader>cj` -> joins test-command onto single line
- `?` -> show help with TSam commands and standard keymaps in the Detail-Float - `?` -> show help with TSam commands and standard keymaps in the Detail-Float
## Output UI ## Output UI
@@ -81,6 +83,7 @@ Additional keymaps:
- Press `<cr>` on a `[ FAIL ] ...` line in the listing to open/update the **Detail-Float** as a 20/80 split (left 20% listing, right 80% detail). - Press `<cr>` on a `[ FAIL ] ...` line in the listing to open/update the **Detail-Float** as a 20/80 split (left 20% listing, right 80% detail).
- ANSI color translation is only applied in the **Detail-Float**; the **Test-Listing-Float** shows raw text without ANSI translation. - ANSI color translation is only applied in the **Detail-Float**; the **Test-Listing-Float** shows raw text without ANSI translation.
- `<esc><esc>` hides the floating window; `TSamShowOutput` reopens it. - `<esc><esc>` hides the floating window; `TSamShowOutput` reopens it.
- If no output is captured for a test, the **Detail-Float** shows `No output captured`.
## Runner architecture ## Runner architecture

View File

@@ -58,6 +58,8 @@ Additional keymaps:
<leader>ss Filter listing to [ SKIP ] only <leader>ss Filter listing to [ SKIP ] only
<leader>sa Show all listing entries (clear filter) <leader>sa Show all listing entries (clear filter)
<leader>tt Run the test under the cursor in the listing <leader>tt Run the test under the cursor in the listing
<leader>cb breaks test-command onto multiple lines
<leader>cj joins test-command onto single line
<leader>o Jump to test location <leader>o Jump to test location
<leader>z Toggle Detail-Float full width <leader>z Toggle Detail-Float full width
<C-l> Focus Detail-Float (press l again for full) <C-l> Focus Detail-Float (press l again for full)
@@ -75,7 +77,8 @@ Detail-Float: right subwindow showing detailed output for a test.
After running a test command, the UI opens in listing mode (only the After running a test command, the UI opens in listing mode (only the
Test-Listing-Float is visible). Press <cr> on a [ FAIL ] entry to open Test-Listing-Float is visible). Press <cr> on a [ FAIL ] entry to open
the Detail-Float with a 20/80 split. ANSI colors are translated only the Detail-Float with a 20/80 split. ANSI colors are translated only
inside the Detail-Float. inside the Detail-Float. If no output is captured for a test, the
Detail-Float shows "No output captured".
RUNNER ARCHITECTURE *test-samurai-runners* RUNNER ARCHITECTURE *test-samurai-runners*

View File

@@ -76,6 +76,8 @@ local function help_lines()
" <C-h> Focus Test-Listing-Float", " <C-h> Focus Test-Listing-Float",
" <leader>z Toggle Detail-Float full width", " <leader>z Toggle Detail-Float full width",
" <leader>o Jump to test location", " <leader>o Jump to test location",
" <leader>cb breaks test-command onto multiple lines",
" <leader>cj joins test-command onto single line",
" ? Show this help", " ? Show this help",
"", "",
"Testing-Float (Detail):", "Testing-Float (Detail):",
@@ -86,6 +88,9 @@ local function help_lines()
" <leader>z Toggle Detail-Float full width", " <leader>z Toggle Detail-Float full width",
" <C-c> Close Detail-Float", " <C-c> Close Detail-Float",
" ? Show this help", " ? Show this help",
"",
"Notes:",
" No output captured -> shows placeholder text",
} }
end end
@@ -139,6 +144,16 @@ local function apply_listing_lines(buf, lines)
rebuild_result_line_map(lines) rebuild_result_line_map(lines)
end end
local function apply_listing_substitution(command)
local buf = vim.api.nvim_get_current_buf()
if not (buf and vim.api.nvim_buf_is_valid(buf)) then
return
end
vim.api.nvim_buf_call(buf, function()
vim.cmd(command)
end)
end
local function apply_listing_filter(kind) local function apply_listing_filter(kind)
if not (state.last_buf and vim.api.nvim_buf_is_valid(state.last_buf)) then if not (state.last_buf and vim.api.nvim_buf_is_valid(state.last_buf)) then
return return
@@ -766,6 +781,12 @@ local function create_output_win(initial_lines)
vim.keymap.set("n", "<leader>pf", function() vim.keymap.set("n", "<leader>pf", function()
jump_listing_fail("prev") jump_listing_fail("prev")
end, { buffer = buf, nowait = true, silent = true }) end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>cb", function()
M.listing_break_on_dashes()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>cj", function()
M.listing_join_backslashes()
end, { buffer = buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>o", function() vim.keymap.set("n", "<leader>o", function()
jump_to_listing_test() jump_to_listing_test()
end, { buffer = buf, nowait = true, silent = true }) end, { buffer = buf, nowait = true, silent = true })
@@ -845,6 +866,12 @@ local function reopen_output_win()
vim.keymap.set("n", "<leader>pf", function() vim.keymap.set("n", "<leader>pf", function()
jump_listing_fail("prev") jump_listing_fail("prev")
end, { buffer = state.last_buf, nowait = true, silent = true }) end, { buffer = state.last_buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>cb", function()
M.listing_break_on_dashes()
end, { buffer = state.last_buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>cj", function()
M.listing_join_backslashes()
end, { buffer = state.last_buf, nowait = true, silent = true })
vim.keymap.set("n", "<leader>o", function() vim.keymap.set("n", "<leader>o", function()
jump_to_listing_test() jump_to_listing_test()
end, { buffer = state.last_buf, nowait = true, silent = true }) end, { buffer = state.last_buf, nowait = true, silent = true })
@@ -1305,7 +1332,7 @@ function M.open_test_output_at_cursor()
end end
end end
if type(output) ~= "table" or #output == 0 then if type(output) ~= "table" or #output == 0 then
vim.notify("[test-samurai] No output captured for " .. test_name, vim.log.levels.WARN) open_detail_split({ "", "No output captured" }, "default")
return return
end end
local border_kind = status and status:lower() or nil local border_kind = status and status:lower() or nil
@@ -1332,6 +1359,14 @@ function M.filter_listing_all()
apply_listing_filter("all") apply_listing_filter("all")
end end
function M.listing_break_on_dashes()
apply_listing_substitution([[%s/--/\\\r\t--/g]])
end
function M.listing_join_backslashes()
apply_listing_substitution([[%s/\\\n\t//g]])
end
function M.run_test_at_cursor() function M.run_test_at_cursor()
local cursor = vim.api.nvim_win_get_cursor(0) local cursor = vim.api.nvim_win_get_cursor(0)
local line = cursor[1] local line = cursor[1]

View File

@@ -222,13 +222,20 @@ describe("test-samurai core (no bundled runners)", function()
local listing_buf = vim.api.nvim_get_current_buf() local listing_buf = vim.api.nvim_get_current_buf()
local maps = vim.api.nvim_buf_get_keymap(listing_buf, "n") local maps = vim.api.nvim_buf_get_keymap(listing_buf, "n")
local has_help = false local has_help = false
local has_cb = false
local has_cj = false
for _, map in ipairs(maps) do for _, map in ipairs(maps) do
if map.lhs == "?" then if map.lhs == "?" then
has_help = true has_help = true
break elseif map.lhs and map.lhs:sub(-2) == "cb" then
has_cb = true
elseif map.lhs and map.lhs:sub(-2) == "cj" then
has_cj = true
end end
end end
assert.is_true(has_help) assert.is_true(has_help)
assert.is_true(has_cb)
assert.is_true(has_cj)
core.show_help() core.show_help()
@@ -239,10 +246,41 @@ describe("test-samurai core (no bundled runners)", function()
assert.is_true(joined:find("TSamShowOutput", 1, true) ~= nil) assert.is_true(joined:find("TSamShowOutput", 1, true) ~= nil)
assert.is_true(joined:find("<leader>tn", 1, true) ~= nil) assert.is_true(joined:find("<leader>tn", 1, true) ~= nil)
assert.is_true(joined:find("<leader>to", 1, true) ~= nil) assert.is_true(joined:find("<leader>to", 1, true) ~= nil)
assert.is_true(joined:find("<leader>cb", 1, true) ~= nil)
assert.is_true(joined:find("<leader>cj", 1, true) ~= nil)
assert.is_true(joined:find("breaks test-command onto multiple lines", 1, true) ~= nil)
assert.is_true(joined:find("joins test-command onto single line", 1, true) ~= nil)
vim.fn.jobstart = orig_jobstart vim.fn.jobstart = orig_jobstart
end) end)
it("applies listing break/join substitutions", function()
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_set_current_buf(buf)
vim.api.nvim_buf_set_lines(buf, 0, -1, false, {
"alpha -- beta",
"gamma -- delta",
})
core.listing_break_on_dashes()
local broken = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
assert.same({
"alpha \\",
"\t-- beta",
"gamma \\",
"\t-- delta",
}, broken)
core.listing_join_backslashes()
local joined = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
assert.same({
"alpha -- beta",
"gamma -- delta",
}, joined)
end)
it("filters listing entries and restores them", function() it("filters listing entries and restores them", function()
local runner = { local runner = {
name = "test-runner-filter", name = "test-runner-filter",
@@ -516,4 +554,95 @@ describe("test-samurai core (no bundled runners)", function()
assert.equals("TestC", build_specs[2].full_name) assert.equals("TestC", build_specs[2].full_name)
assert.equals("Suite TestC", build_specs[2].mocha_full_title) assert.equals("Suite TestC", build_specs[2].mocha_full_title)
end) end)
it("opens detail float with placeholder when no output captured", function()
local runner = {
name = "test-runner-no-output",
}
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
function runner.build_command(spec)
return { cmd = { "echo", "nearest" }, 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 = {}, failures = { "TestMissingOutput" }, skips = {} }
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-no-output-runner"] = runner
test_samurai.setup({ runner_modules = { "test-samurai-no-output-runner" } })
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_name(bufnr, "/tmp/test_samurai_no_output.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
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 %] %- TestMissingOutput") then
target = i
break
end
end
assert.is_true(target ~= nil)
vim.api.nvim_win_set_cursor(0, { target, 0 })
core.open_test_output_at_cursor()
local detail_buf = vim.api.nvim_get_current_buf()
local detail_lines = vim.api.nvim_buf_get_lines(detail_buf, 0, -1, false)
assert.same({ "", "No output captured" }, detail_lines)
vim.fn.jobstart = orig_jobstart
end)
end) end)