Compare commits
7 Commits
924584d8b3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
456a157549
|
|||
|
8c598002e4
|
|||
|
bd6930adc0
|
|||
|
24bd89a7be
|
|||
|
fd3952bedf
|
|||
|
238d5f9634
|
|||
|
118f84c31e
|
28
README.md
28
README.md
@@ -63,15 +63,24 @@ If no runner matches the current test file, test-samurai will show:
|
|||||||
|
|
||||||
Additional keymaps:
|
Additional keymaps:
|
||||||
|
|
||||||
- `<leader>qn` -> close the testing floats and jump to the first quickfix entry
|
- Listing navigation:
|
||||||
- `<leader>nf` -> jump to the next `[ FAIL ]` entry in the Test-Listing-Float (wraps to the first)
|
- `<leader>fn` -> [F]ind [N]ext failed test in listing (wraps to the first, opens Detail-Float, works in Detail-Float)
|
||||||
- `<leader>pf` -> jump to the previous `[ FAIL ]` entry in the Test-Listing-Float (wraps to the last)
|
- `<leader>fp` -> [F]ind [P]revious failed test in listing (wraps to the last, opens Detail-Float, works in Detail-Float)
|
||||||
- `<leader>sf` -> filter the listing to `[ FAIL ] - ...` entries
|
- `<leader>ff` -> [F]ind [F]irst list entry (opens Detail-Float, works in Detail-Float)
|
||||||
- `<leader>ss` -> filter the listing to `[ SKIP ] - ...` entries
|
- `<leader>o` -> jump to the test location
|
||||||
- `<leader>sa` -> clear the listing filter and show all entries
|
- `<leader>qn` -> close the testing floats and jump to the first quickfix entry
|
||||||
- `<leader>tt` -> run the test under the cursor in the listing
|
- Listing filters:
|
||||||
|
- `<leader>sf` -> filter the listing to `[ FAIL ] - ...` entries
|
||||||
|
- `<leader>ss` -> filter the listing to `[ SKIP ] - ...` entries
|
||||||
|
- `<leader>sa` -> clear the listing filter and show all entries
|
||||||
|
- Listing actions:
|
||||||
|
- `<leader>tt` -> run the test under the cursor in the listing
|
||||||
|
- `<leader>cb` -> breaks test-command onto multiple lines (clears search highlight)
|
||||||
|
- `<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
|
||||||
|
|
||||||
|
Before running any test command, test-samurai runs `:wall` to save all buffers.
|
||||||
|
|
||||||
## Output UI
|
## Output UI
|
||||||
|
|
||||||
- Output is shown in a floating container called **Testing-Float**.
|
- Output is shown in a floating container called **Testing-Float**.
|
||||||
@@ -80,7 +89,10 @@ Additional keymaps:
|
|||||||
- After `TSamNearest`, `TSamFile`, `TSamAll`, `TSamFailedOnly`, etc., the UI opens in listing mode (only **Test-Listing-Float** visible).
|
- After `TSamNearest`, `TSamFile`, `TSamAll`, `TSamFailedOnly`, etc., the UI opens in listing mode (only **Test-Listing-Float** visible).
|
||||||
- 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 and restores the cursor position; `TSamShowOutput` reopens it.
|
||||||
|
- If no output is captured for a test, the **Detail-Float** shows `No output captured`.
|
||||||
|
- The active listing entry is highlighted while the **Detail-Float** is visible.
|
||||||
|
- Summary lines (`TOTAL`/`DURATION`) are appended in the listing output, including `TSamLast`.
|
||||||
|
|
||||||
## Runner architecture
|
## Runner architecture
|
||||||
|
|
||||||
|
|||||||
@@ -51,20 +51,31 @@ QUICK-HELP & FLOATS *test-samurai-quickhelp*
|
|||||||
In the Testing-Float, press ? to open the quick-help in the Detail-Float.
|
In the Testing-Float, press ? to open the quick-help in the Detail-Float.
|
||||||
|
|
||||||
Additional keymaps:
|
Additional keymaps:
|
||||||
|
Listing navigation:
|
||||||
|
<leader>fn [F]ind [N]ext failed test in listing (opens Detail-Float; works in Detail-Float)
|
||||||
|
<leader>fp [F]ind [P]revious failed test in listing (opens Detail-Float; works in Detail-Float)
|
||||||
|
<leader>ff [F]ind [F]irst list entry (opens Detail-Float; works in Detail-Float)
|
||||||
|
<leader>o Jump to test location
|
||||||
<leader>qn Close floats + jump to the first quickfix entry
|
<leader>qn Close floats + jump to the first quickfix entry
|
||||||
<leader>nf Next [ FAIL ] in listing
|
Listing filters:
|
||||||
<leader>pf Previous [ FAIL ] in listing
|
|
||||||
<leader>sf Filter listing to [ FAIL ] only
|
<leader>sf Filter listing to [ FAIL ] only
|
||||||
<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)
|
||||||
|
Listing actions:
|
||||||
<leader>tt Run the test under the cursor in the listing
|
<leader>tt Run the test under the cursor in the listing
|
||||||
<leader>o Jump to test location
|
<leader>cb breaks test-command onto multiple lines (clears search highlight)
|
||||||
|
<leader>cj joins test-command onto single line
|
||||||
|
Testing-Float:
|
||||||
<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)
|
||||||
<C-h> Focus Test-Listing-Float
|
<C-h> Focus Test-Listing-Float
|
||||||
<esc><esc> Close Testing-Float
|
<esc><esc> Close Testing-Float and restore cursor
|
||||||
<C-c> Close Detail-Float (when focused)
|
<C-c> Close Detail-Float (when focused)
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
Active listing entry is highlighted while the Detail-Float is visible.
|
||||||
|
Buffers are saved via :wall before every test run.
|
||||||
|
|
||||||
|
|
||||||
OUTPUT UI *test-samurai-ui*
|
OUTPUT UI *test-samurai-ui*
|
||||||
|
|
||||||
@@ -75,7 +86,11 @@ 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".
|
||||||
|
|
||||||
|
Summary lines (TOTAL/DURATION) are rendered in the listing output,
|
||||||
|
including after :TSamLast.
|
||||||
|
|
||||||
|
|
||||||
RUNNER ARCHITECTURE *test-samurai-runners*
|
RUNNER ARCHITECTURE *test-samurai-runners*
|
||||||
|
|||||||
@@ -23,8 +23,12 @@ local state = {
|
|||||||
detail_win = nil,
|
detail_win = nil,
|
||||||
detail_opening = false,
|
detail_opening = false,
|
||||||
detail_full = false,
|
detail_full = false,
|
||||||
|
trigger_win = nil,
|
||||||
|
trigger_buf = nil,
|
||||||
|
trigger_cursor = nil,
|
||||||
listing_unfiltered_lines = nil,
|
listing_unfiltered_lines = nil,
|
||||||
listing_filtered_kind = nil,
|
listing_filtered_kind = nil,
|
||||||
|
detail_line = nil,
|
||||||
hardtime_refcount = 0,
|
hardtime_refcount = 0,
|
||||||
hardtime_was_enabled = false,
|
hardtime_was_enabled = false,
|
||||||
autocmds_set = false,
|
autocmds_set = false,
|
||||||
@@ -33,6 +37,8 @@ local state = {
|
|||||||
local summary_ns = vim.api.nvim_create_namespace("TestSamuraiSummary")
|
local summary_ns = vim.api.nvim_create_namespace("TestSamuraiSummary")
|
||||||
local result_ns = vim.api.nvim_create_namespace("TestSamuraiResult")
|
local result_ns = vim.api.nvim_create_namespace("TestSamuraiResult")
|
||||||
local detail_ns = vim.api.nvim_create_namespace("TestSamuraiDetailAnsi")
|
local detail_ns = vim.api.nvim_create_namespace("TestSamuraiDetailAnsi")
|
||||||
|
local help_ns = vim.api.nvim_create_namespace("TestSamuraiHelp")
|
||||||
|
local listing_sel_ns = vim.api.nvim_create_namespace("TestSamuraiListingSelection")
|
||||||
local apply_border_kind
|
local apply_border_kind
|
||||||
local close_container
|
local close_container
|
||||||
local restore_listing_full
|
local restore_listing_full
|
||||||
@@ -52,7 +58,7 @@ local function help_lines()
|
|||||||
return {
|
return {
|
||||||
"Test-Samurai Help",
|
"Test-Samurai Help",
|
||||||
"",
|
"",
|
||||||
"TSam Commands:",
|
"TSam commands:",
|
||||||
" TSamNearest <leader>tn",
|
" TSamNearest <leader>tn",
|
||||||
" TSamFile <leader>tf",
|
" TSamFile <leader>tf",
|
||||||
" TSamAll <leader>ta",
|
" TSamAll <leader>ta",
|
||||||
@@ -60,32 +66,44 @@ local function help_lines()
|
|||||||
" TSamFailedOnly <leader>te",
|
" TSamFailedOnly <leader>te",
|
||||||
" TSamShowOutput <leader>to",
|
" TSamShowOutput <leader>to",
|
||||||
"",
|
"",
|
||||||
"Standard Keymaps:",
|
"Listing navigation:",
|
||||||
|
" <leader>fn [F]ind [N]ext failed test in listing (opens Detail-Float; works in Detail-Float)",
|
||||||
|
" <leader>fp [F]ind [P]revious failed test in listing (opens Detail-Float; works in Detail-Float)",
|
||||||
|
" <leader>ff [F]ind [F]irst list entry (opens Detail-Float; works in Detail-Float)",
|
||||||
|
" <leader>o Jump to test location",
|
||||||
" <leader>qn Close floats + jump to first quickfix entry",
|
" <leader>qn Close floats + jump to first quickfix entry",
|
||||||
" <leader>nf Next [ FAIL ] in listing",
|
"",
|
||||||
" <leader>pf Previous [ FAIL ] in listing",
|
"Listing filters:",
|
||||||
" <leader>sf Filter listing to [ FAIL ] only",
|
" <leader>sf Filter listing to [ FAIL ] only",
|
||||||
" <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)",
|
||||||
|
"",
|
||||||
|
"Listing actions:",
|
||||||
" <leader>tt Run the test under the cursor",
|
" <leader>tt Run the test under the cursor",
|
||||||
|
" <leader>cb breaks test-command onto multiple lines (clears search highlight)",
|
||||||
|
" <leader>cj joins test-command onto single line",
|
||||||
"",
|
"",
|
||||||
"Testing-Float (Listing):",
|
"Testing-Float (Listing):",
|
||||||
" <cr> Open Detail-Float for selected test",
|
" <cr> Open Detail-Float for selected test",
|
||||||
" <esc><esc> Close Testing-Float",
|
" <esc><esc> Close Testing-Float and restore cursor",
|
||||||
" <C-l> Focus Detail-Float (press l again for full)",
|
" <C-l> Focus Detail-Float (press l again for full)",
|
||||||
" <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",
|
|
||||||
" ? Show this help",
|
" ? Show this help",
|
||||||
"",
|
"",
|
||||||
"Testing-Float (Detail):",
|
"Testing-Float (Detail):",
|
||||||
" <esc><esc> Close Testing-Float",
|
" <esc><esc> Close Testing-Float and restore cursor",
|
||||||
" <C-h> Focus Test-Listing-Float",
|
" <C-h> Focus Test-Listing-Float",
|
||||||
" <C-w>h Focus Test-Listing-Float",
|
" <C-w>h Focus Test-Listing-Float",
|
||||||
" <C-l> Focus Detail-Float",
|
" <C-l> Focus Detail-Float",
|
||||||
" <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",
|
||||||
|
" Active listing entry is highlighted while Detail-Float is visible",
|
||||||
|
" Buffers are saved via :wall before every test run",
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -134,11 +152,22 @@ local function apply_listing_lines(buf, lines)
|
|||||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
|
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
|
||||||
vim.api.nvim_buf_clear_namespace(buf, result_ns, 0, -1)
|
vim.api.nvim_buf_clear_namespace(buf, result_ns, 0, -1)
|
||||||
vim.api.nvim_buf_clear_namespace(buf, summary_ns, 0, -1)
|
vim.api.nvim_buf_clear_namespace(buf, summary_ns, 0, -1)
|
||||||
|
vim.api.nvim_buf_clear_namespace(buf, listing_sel_ns, 0, -1)
|
||||||
apply_result_highlights(buf, 0, lines)
|
apply_result_highlights(buf, 0, lines)
|
||||||
apply_summary_highlights(buf, 0, lines)
|
apply_summary_highlights(buf, 0, 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
|
||||||
@@ -253,11 +282,11 @@ local function jump_listing_fail(direction)
|
|||||||
local win = vim.api.nvim_get_current_win()
|
local win = vim.api.nvim_get_current_win()
|
||||||
local buf = vim.api.nvim_get_current_buf()
|
local buf = vim.api.nvim_get_current_buf()
|
||||||
if not (buf and vim.api.nvim_buf_is_valid(buf)) then
|
if not (buf and vim.api.nvim_buf_is_valid(buf)) then
|
||||||
return
|
return nil
|
||||||
end
|
end
|
||||||
local total = vim.api.nvim_buf_line_count(buf)
|
local total = vim.api.nvim_buf_line_count(buf)
|
||||||
if total == 0 then
|
if total == 0 then
|
||||||
return
|
return nil
|
||||||
end
|
end
|
||||||
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
|
||||||
local cursor = vim.api.nvim_win_get_cursor(win)
|
local cursor = vim.api.nvim_win_get_cursor(win)
|
||||||
@@ -309,6 +338,76 @@ local function jump_listing_fail(direction)
|
|||||||
if target then
|
if target then
|
||||||
vim.api.nvim_win_set_cursor(win, { target, 0 })
|
vim.api.nvim_win_set_cursor(win, { target, 0 })
|
||||||
end
|
end
|
||||||
|
return target
|
||||||
|
end
|
||||||
|
|
||||||
|
local function jump_to_first_listing_entry()
|
||||||
|
local win = vim.api.nvim_get_current_win()
|
||||||
|
local buf = vim.api.nvim_get_current_buf()
|
||||||
|
if not (buf and vim.api.nvim_buf_is_valid(buf)) then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local total = vim.api.nvim_buf_line_count(buf)
|
||||||
|
if total == 0 then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
|
||||||
|
for i = 1, total do
|
||||||
|
if lines[i] and lines[i]:match("^%[ %u+ %] %- ") then
|
||||||
|
vim.api.nvim_win_set_cursor(win, { i, 0 })
|
||||||
|
return i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local function jump_listing_and_open(kind)
|
||||||
|
local current_win = vim.api.nvim_get_current_win()
|
||||||
|
local listing_win = state.last_win
|
||||||
|
if listing_win and vim.api.nvim_win_is_valid(listing_win) then
|
||||||
|
vim.api.nvim_set_current_win(listing_win)
|
||||||
|
else
|
||||||
|
listing_win = current_win
|
||||||
|
end
|
||||||
|
local target = nil
|
||||||
|
if kind == "next" then
|
||||||
|
target = jump_listing_fail("next")
|
||||||
|
elseif kind == "prev" then
|
||||||
|
target = jump_listing_fail("prev")
|
||||||
|
elseif kind == "first" then
|
||||||
|
target = jump_to_first_listing_entry()
|
||||||
|
end
|
||||||
|
if target then
|
||||||
|
M.open_test_output_at_cursor()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if current_win and vim.api.nvim_win_is_valid(current_win) then
|
||||||
|
vim.api.nvim_set_current_win(current_win)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function clear_listing_selection()
|
||||||
|
if state.last_buf and vim.api.nvim_buf_is_valid(state.last_buf) then
|
||||||
|
vim.api.nvim_buf_clear_namespace(state.last_buf, listing_sel_ns, 0, -1)
|
||||||
|
end
|
||||||
|
state.detail_line = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
local function apply_listing_selection(line)
|
||||||
|
if not (state.last_buf and vim.api.nvim_buf_is_valid(state.last_buf)) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
vim.api.nvim_buf_clear_namespace(state.last_buf, listing_sel_ns, 0, -1)
|
||||||
|
if not line then
|
||||||
|
state.detail_line = nil
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local total = vim.api.nvim_buf_line_count(state.last_buf)
|
||||||
|
if line < 1 or line > total then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
vim.api.nvim_buf_add_highlight(state.last_buf, listing_sel_ns, "TestSamuraiListingActive", line - 1, 0, -1)
|
||||||
|
state.detail_line = line
|
||||||
end
|
end
|
||||||
|
|
||||||
local function find_normal_window()
|
local function find_normal_window()
|
||||||
@@ -321,6 +420,54 @@ local function find_normal_window()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function capture_trigger_location()
|
||||||
|
local win = vim.api.nvim_get_current_win()
|
||||||
|
local cfg = vim.api.nvim_win_get_config(win)
|
||||||
|
if cfg.relative ~= "" then
|
||||||
|
win = find_normal_window()
|
||||||
|
end
|
||||||
|
if not (win and vim.api.nvim_win_is_valid(win)) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local buf = vim.api.nvim_win_get_buf(win)
|
||||||
|
if not (buf and vim.api.nvim_buf_is_valid(buf)) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local cursor = vim.api.nvim_win_get_cursor(win)
|
||||||
|
state.trigger_win = win
|
||||||
|
state.trigger_buf = buf
|
||||||
|
state.trigger_cursor = { cursor[1], cursor[2] }
|
||||||
|
end
|
||||||
|
|
||||||
|
local function restore_trigger_location()
|
||||||
|
local buf = state.trigger_buf
|
||||||
|
local cursor = state.trigger_cursor
|
||||||
|
if not (buf and vim.api.nvim_buf_is_valid(buf)) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local target_win = nil
|
||||||
|
if state.trigger_win and vim.api.nvim_win_is_valid(state.trigger_win) then
|
||||||
|
local cfg = vim.api.nvim_win_get_config(state.trigger_win)
|
||||||
|
if cfg.relative == "" then
|
||||||
|
target_win = state.trigger_win
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not target_win then
|
||||||
|
target_win = find_normal_window()
|
||||||
|
end
|
||||||
|
if not (target_win and vim.api.nvim_win_is_valid(target_win)) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
vim.api.nvim_set_current_win(target_win)
|
||||||
|
vim.api.nvim_win_set_buf(target_win, buf)
|
||||||
|
if cursor then
|
||||||
|
pcall(vim.api.nvim_win_set_cursor, target_win, cursor)
|
||||||
|
end
|
||||||
|
state.trigger_win = nil
|
||||||
|
state.trigger_buf = nil
|
||||||
|
state.trigger_cursor = nil
|
||||||
|
end
|
||||||
|
|
||||||
local function jump_to_listing_test()
|
local function jump_to_listing_test()
|
||||||
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]
|
||||||
@@ -415,6 +562,7 @@ local function setup_summary_highlights()
|
|||||||
pcall(vim.api.nvim_set_hl, 0, "TestSamuraiResultSkip", { fg = skip_fg })
|
pcall(vim.api.nvim_set_hl, 0, "TestSamuraiResultSkip", { fg = skip_fg })
|
||||||
pcall(vim.api.nvim_set_hl, 0, "TestSamuraiBorderPass", { fg = pass_fg, bold = true })
|
pcall(vim.api.nvim_set_hl, 0, "TestSamuraiBorderPass", { fg = pass_fg, bold = true })
|
||||||
pcall(vim.api.nvim_set_hl, 0, "TestSamuraiBorderFail", { fg = fail_fg, bold = true })
|
pcall(vim.api.nvim_set_hl, 0, "TestSamuraiBorderFail", { fg = fail_fg, bold = true })
|
||||||
|
pcall(vim.api.nvim_set_hl, 0, "TestSamuraiListingActive", { link = "Visual" })
|
||||||
end
|
end
|
||||||
|
|
||||||
local function load_runners()
|
local function load_runners()
|
||||||
@@ -448,6 +596,7 @@ local function ensure_output_autocmds()
|
|||||||
if state.detail_win and closed == state.detail_win then
|
if state.detail_win and closed == state.detail_win then
|
||||||
state.detail_win = nil
|
state.detail_win = nil
|
||||||
restore_listing_full()
|
restore_listing_full()
|
||||||
|
clear_listing_selection()
|
||||||
hardtime_restore()
|
hardtime_restore()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -458,6 +607,7 @@ local function ensure_output_autocmds()
|
|||||||
pcall(vim.api.nvim_win_close, state.detail_win, true)
|
pcall(vim.api.nvim_win_close, state.detail_win, true)
|
||||||
state.detail_win = nil
|
state.detail_win = nil
|
||||||
end
|
end
|
||||||
|
clear_listing_selection()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
@@ -625,6 +775,12 @@ close_container = function()
|
|||||||
pcall(vim.api.nvim_win_close, state.last_win, true)
|
pcall(vim.api.nvim_win_close, state.last_win, true)
|
||||||
state.last_win = nil
|
state.last_win = nil
|
||||||
end
|
end
|
||||||
|
clear_listing_selection()
|
||||||
|
end
|
||||||
|
|
||||||
|
local function close_container_and_restore()
|
||||||
|
close_container()
|
||||||
|
restore_trigger_location()
|
||||||
end
|
end
|
||||||
|
|
||||||
jump_to_first_quickfix = function()
|
jump_to_first_quickfix = function()
|
||||||
@@ -639,6 +795,7 @@ close_detail_float = function()
|
|||||||
if state.detail_win and vim.api.nvim_win_is_valid(state.detail_win) then
|
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)
|
pcall(vim.api.nvim_win_close, state.detail_win, true)
|
||||||
end
|
end
|
||||||
|
clear_listing_selection()
|
||||||
end
|
end
|
||||||
|
|
||||||
restore_listing_full = function()
|
restore_listing_full = function()
|
||||||
@@ -712,6 +869,7 @@ local function apply_split_layout(left_ratio)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function create_output_win(initial_lines)
|
local function create_output_win(initial_lines)
|
||||||
|
capture_trigger_location()
|
||||||
if state.detail_win and vim.api.nvim_win_is_valid(state.detail_win) then
|
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)
|
pcall(vim.api.nvim_win_close, state.detail_win, true)
|
||||||
state.detail_win = nil
|
state.detail_win = nil
|
||||||
@@ -746,7 +904,7 @@ local function create_output_win(initial_lines)
|
|||||||
hardtime_disable()
|
hardtime_disable()
|
||||||
|
|
||||||
vim.keymap.set("n", "<esc><esc>", function()
|
vim.keymap.set("n", "<esc><esc>", function()
|
||||||
close_container()
|
close_container_and_restore()
|
||||||
end, { buffer = buf, nowait = true, silent = true })
|
end, { buffer = buf, nowait = true, silent = true })
|
||||||
vim.keymap.set("n", "<cr>", function()
|
vim.keymap.set("n", "<cr>", function()
|
||||||
M.open_test_output_at_cursor()
|
M.open_test_output_at_cursor()
|
||||||
@@ -760,11 +918,20 @@ local function create_output_win(initial_lines)
|
|||||||
vim.keymap.set("n", "<leader>z", function()
|
vim.keymap.set("n", "<leader>z", function()
|
||||||
M.toggle_detail_full()
|
M.toggle_detail_full()
|
||||||
end, { buffer = buf, nowait = true, silent = true })
|
end, { buffer = buf, nowait = true, silent = true })
|
||||||
vim.keymap.set("n", "<leader>nf", function()
|
vim.keymap.set("n", "<leader>fn", function()
|
||||||
jump_listing_fail("next")
|
jump_listing_and_open("next")
|
||||||
end, { buffer = buf, nowait = true, silent = true })
|
end, { buffer = buf, nowait = true, silent = true })
|
||||||
vim.keymap.set("n", "<leader>pf", function()
|
vim.keymap.set("n", "<leader>fp", function()
|
||||||
jump_listing_fail("prev")
|
jump_listing_and_open("prev")
|
||||||
|
end, { buffer = buf, nowait = true, silent = true })
|
||||||
|
vim.keymap.set("n", "<leader>ff", function()
|
||||||
|
jump_listing_and_open("first")
|
||||||
|
end, { buffer = buf, nowait = true, silent = true, desc = "[F]ind [F]irst list entry" })
|
||||||
|
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 })
|
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()
|
||||||
@@ -810,6 +977,7 @@ local function reopen_output_win()
|
|||||||
state.detail_win = nil
|
state.detail_win = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
capture_trigger_location()
|
||||||
local width, height, row, col = float_geometry()
|
local width, height, row, col = float_geometry()
|
||||||
state.last_float = { width = width, height = height, row = row, col = col }
|
state.last_float = { width = width, height = height, row = row, col = col }
|
||||||
|
|
||||||
@@ -825,7 +993,7 @@ local function reopen_output_win()
|
|||||||
hardtime_disable()
|
hardtime_disable()
|
||||||
|
|
||||||
vim.keymap.set("n", "<esc><esc>", function()
|
vim.keymap.set("n", "<esc><esc>", function()
|
||||||
close_container()
|
close_container_and_restore()
|
||||||
end, { buffer = state.last_buf, nowait = true, silent = true })
|
end, { buffer = state.last_buf, nowait = true, silent = true })
|
||||||
vim.keymap.set("n", "<cr>", function()
|
vim.keymap.set("n", "<cr>", function()
|
||||||
M.open_test_output_at_cursor()
|
M.open_test_output_at_cursor()
|
||||||
@@ -839,11 +1007,20 @@ local function reopen_output_win()
|
|||||||
vim.keymap.set("n", "<leader>z", function()
|
vim.keymap.set("n", "<leader>z", function()
|
||||||
M.toggle_detail_full()
|
M.toggle_detail_full()
|
||||||
end, { buffer = state.last_buf, nowait = true, silent = true })
|
end, { buffer = state.last_buf, nowait = true, silent = true })
|
||||||
vim.keymap.set("n", "<leader>nf", function()
|
vim.keymap.set("n", "<leader>fn", function()
|
||||||
jump_listing_fail("next")
|
jump_listing_and_open("next")
|
||||||
end, { buffer = state.last_buf, nowait = true, silent = true })
|
end, { buffer = state.last_buf, nowait = true, silent = true })
|
||||||
vim.keymap.set("n", "<leader>pf", function()
|
vim.keymap.set("n", "<leader>fp", function()
|
||||||
jump_listing_fail("prev")
|
jump_listing_and_open("prev")
|
||||||
|
end, { buffer = state.last_buf, nowait = true, silent = true })
|
||||||
|
vim.keymap.set("n", "<leader>ff", function()
|
||||||
|
jump_listing_and_open("first")
|
||||||
|
end, { buffer = state.last_buf, nowait = true, silent = true, desc = "[F]ind [F]irst list entry" })
|
||||||
|
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 })
|
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()
|
||||||
@@ -1128,6 +1305,18 @@ local function apply_detail_highlights(buf, highlights)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function apply_help_highlights(buf, lines)
|
||||||
|
if not (buf and vim.api.nvim_buf_is_valid(buf)) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
vim.api.nvim_buf_clear_namespace(buf, help_ns, 0, -1)
|
||||||
|
for lnum, line in ipairs(lines or {}) do
|
||||||
|
if line:match(":%s*$") then
|
||||||
|
vim.api.nvim_buf_add_highlight(buf, help_ns, "TestSamuraiSummaryPass", lnum - 1, 0, -1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function parse_go_output_from_raw(output)
|
local function parse_go_output_from_raw(output)
|
||||||
local out = {}
|
local out = {}
|
||||||
if not output or output == "" then
|
if not output or output == "" then
|
||||||
@@ -1161,7 +1350,7 @@ local function ensure_detail_buf(lines)
|
|||||||
vim.api.nvim_buf_set_option(buf, "filetype", "test-samurai-output")
|
vim.api.nvim_buf_set_option(buf, "filetype", "test-samurai-output")
|
||||||
state.detail_buf = buf
|
state.detail_buf = buf
|
||||||
vim.keymap.set("n", "<esc><esc>", function()
|
vim.keymap.set("n", "<esc><esc>", function()
|
||||||
close_container()
|
close_container_and_restore()
|
||||||
end, { buffer = buf, nowait = true, silent = true })
|
end, { buffer = buf, nowait = true, silent = true })
|
||||||
vim.keymap.set("n", "<C-w>h", function()
|
vim.keymap.set("n", "<C-w>h", function()
|
||||||
M.focus_listing()
|
M.focus_listing()
|
||||||
@@ -1175,6 +1364,15 @@ local function ensure_detail_buf(lines)
|
|||||||
vim.keymap.set("n", "<leader>z", function()
|
vim.keymap.set("n", "<leader>z", function()
|
||||||
M.toggle_detail_full()
|
M.toggle_detail_full()
|
||||||
end, { buffer = buf, nowait = true, silent = true })
|
end, { buffer = buf, nowait = true, silent = true })
|
||||||
|
vim.keymap.set("n", "<leader>fn", function()
|
||||||
|
jump_listing_and_open("next")
|
||||||
|
end, { buffer = buf, nowait = true, silent = true })
|
||||||
|
vim.keymap.set("n", "<leader>fp", function()
|
||||||
|
jump_listing_and_open("prev")
|
||||||
|
end, { buffer = buf, nowait = true, silent = true })
|
||||||
|
vim.keymap.set("n", "<leader>ff", function()
|
||||||
|
jump_listing_and_open("first")
|
||||||
|
end, { buffer = buf, nowait = true, silent = true, desc = "[F]ind [F]irst list entry" })
|
||||||
vim.keymap.set("n", "<C-c>", function()
|
vim.keymap.set("n", "<C-c>", function()
|
||||||
close_detail_float()
|
close_detail_float()
|
||||||
end, { buffer = buf, nowait = true, silent = true })
|
end, { buffer = buf, nowait = true, silent = true })
|
||||||
@@ -1188,6 +1386,7 @@ local function ensure_detail_buf(lines)
|
|||||||
end
|
end
|
||||||
local clean_lines, highlights = parse_ansi_lines(normalize_output_lines(lines))
|
local clean_lines, highlights = parse_ansi_lines(normalize_output_lines(lines))
|
||||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, clean_lines)
|
vim.api.nvim_buf_set_lines(buf, 0, -1, false, clean_lines)
|
||||||
|
vim.api.nvim_buf_clear_namespace(buf, help_ns, 0, -1)
|
||||||
apply_detail_highlights(buf, highlights)
|
apply_detail_highlights(buf, highlights)
|
||||||
return buf
|
return buf
|
||||||
end
|
end
|
||||||
@@ -1305,11 +1504,13 @@ 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")
|
||||||
|
apply_listing_selection(line)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local border_kind = status and status:lower() or nil
|
local border_kind = status and status:lower() or nil
|
||||||
open_detail_split(output, border_kind)
|
open_detail_split(output, border_kind)
|
||||||
|
apply_listing_selection(line)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.show_help()
|
function M.show_help()
|
||||||
@@ -1317,7 +1518,10 @@ function M.show_help()
|
|||||||
vim.notify("[test-samurai] No test output window", vim.log.levels.WARN)
|
vim.notify("[test-samurai] No test output window", vim.log.levels.WARN)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
open_detail_split(help_lines(), "default")
|
local lines = help_lines()
|
||||||
|
open_detail_split(lines, "default")
|
||||||
|
clear_listing_selection()
|
||||||
|
apply_help_highlights(state.detail_buf, lines)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.filter_listing_failures()
|
function M.filter_listing_failures()
|
||||||
@@ -1332,6 +1536,15 @@ 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]])
|
||||||
|
vim.cmd("noh")
|
||||||
|
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]
|
||||||
@@ -1850,6 +2063,7 @@ end
|
|||||||
|
|
||||||
run_command = function(command, opts)
|
run_command = function(command, opts)
|
||||||
local options = opts or {}
|
local options = opts or {}
|
||||||
|
vim.cmd("wall")
|
||||||
state.last_test_outputs = {}
|
state.last_test_outputs = {}
|
||||||
state.last_result_line_map = {}
|
state.last_result_line_map = {}
|
||||||
state.last_raw_output = nil
|
state.last_raw_output = nil
|
||||||
@@ -1900,7 +2114,10 @@ run_command = function(command, opts)
|
|||||||
skips = {},
|
skips = {},
|
||||||
}
|
}
|
||||||
local had_parsed_output = false
|
local had_parsed_output = false
|
||||||
local summary_enabled = options.scope_kind == "file" or options.scope_kind == "all" or options.scope_kind == "nearest"
|
local summary_enabled = options.scope_kind == "file"
|
||||||
|
or options.scope_kind == "all"
|
||||||
|
or options.scope_kind == "nearest"
|
||||||
|
or options.scope_kind == "last"
|
||||||
local summary = make_summary_tracker(summary_enabled)
|
local summary = make_summary_tracker(summary_enabled)
|
||||||
local result_counts = make_summary_tracker(true)
|
local result_counts = make_summary_tracker(true)
|
||||||
state.last_border_kind = "default"
|
state.last_border_kind = "default"
|
||||||
@@ -2174,6 +2391,7 @@ function M.run_last()
|
|||||||
end
|
end
|
||||||
run_command(command, {
|
run_command(command, {
|
||||||
runner = runner,
|
runner = runner,
|
||||||
|
scope_kind = state.last_scope_kind or "last",
|
||||||
output_parser = parser or (runner and runner.parse_results),
|
output_parser = parser or (runner and runner.parse_results),
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@@ -2351,6 +2569,10 @@ function M.run_failed_only()
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.close_output_and_restore()
|
||||||
|
close_container_and_restore()
|
||||||
|
end
|
||||||
|
|
||||||
function M.show_output()
|
function M.show_output()
|
||||||
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
|
||||||
vim.notify("[test-samurai] No previous output", vim.log.levels.WARN)
|
vim.notify("[test-samurai] No previous output", vim.log.levels.WARN)
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|
||||||
@@ -237,8 +244,403 @@ describe("test-samurai core (no bundled runners)", function()
|
|||||||
local joined = table.concat(lines, "\n")
|
local joined = table.concat(lines, "\n")
|
||||||
assert.is_true(joined:find("TSamNearest", 1, true) ~= nil)
|
assert.is_true(joined:find("TSamNearest", 1, true) ~= nil)
|
||||||
assert.is_true(joined:find("TSamShowOutput", 1, true) ~= nil)
|
assert.is_true(joined:find("TSamShowOutput", 1, true) ~= nil)
|
||||||
|
assert.is_true(joined:find("TSam commands:", 1, true) ~= nil)
|
||||||
|
assert.is_true(joined:find("Listing navigation:", 1, true) ~= nil)
|
||||||
|
assert.is_true(joined:find("Listing filters:", 1, true) ~= nil)
|
||||||
|
assert.is_true(joined:find("Listing actions:", 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>fn", 1, true) ~= nil)
|
||||||
|
assert.is_true(joined:find("<leader>fp", 1, true) ~= nil)
|
||||||
|
assert.is_true(joined:find("[F]ind [N]ext failed test in listing (opens Detail-Float; works in Detail-Float)", 1, true) ~= nil)
|
||||||
|
assert.is_true(joined:find("[F]ind [P]revious failed test in listing (opens Detail-Float; works in Detail-Float)", 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
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("keeps failed-navigation keymaps buffer-local to the output listing", function()
|
||||||
|
local runner = {
|
||||||
|
name = "test-runner-keymaps",
|
||||||
|
}
|
||||||
|
|
||||||
|
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.parse_results(_output)
|
||||||
|
return { passes = {}, failures = {}, 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
|
||||||
|
|
||||||
|
package.loaded["test-samurai-keymap-runner"] = runner
|
||||||
|
test_samurai.setup({ runner_modules = { "test-samurai-keymap-runner" } })
|
||||||
|
|
||||||
|
local normal_buf = vim.api.nvim_create_buf(false, true)
|
||||||
|
vim.api.nvim_buf_set_name(normal_buf, "/tmp/test_samurai_keymaps.go")
|
||||||
|
vim.bo[normal_buf].filetype = "go"
|
||||||
|
vim.api.nvim_set_current_buf(normal_buf)
|
||||||
|
|
||||||
|
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 listing_maps = vim.api.nvim_buf_get_keymap(listing_buf, "n")
|
||||||
|
local has_fn = false
|
||||||
|
local has_fp = false
|
||||||
|
for _, map in ipairs(listing_maps) do
|
||||||
|
if map.lhs and map.lhs:sub(-2) == "fn" then
|
||||||
|
has_fn = true
|
||||||
|
elseif map.lhs and map.lhs:sub(-2) == "fp" then
|
||||||
|
has_fp = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.is_true(has_fn)
|
||||||
|
assert.is_true(has_fp)
|
||||||
|
|
||||||
|
core.close_output_and_restore()
|
||||||
|
|
||||||
|
local normal_maps = vim.api.nvim_buf_get_keymap(normal_buf, "n")
|
||||||
|
local normal_fn = false
|
||||||
|
local normal_fp = false
|
||||||
|
for _, map in ipairs(normal_maps) do
|
||||||
|
if map.lhs and map.lhs:sub(-2) == "fn" then
|
||||||
|
normal_fn = true
|
||||||
|
elseif map.lhs and map.lhs:sub(-2) == "fp" then
|
||||||
|
normal_fp = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.is_false(normal_fn)
|
||||||
|
assert.is_false(normal_fp)
|
||||||
|
|
||||||
|
vim.fn.jobstart = orig_jobstart
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("restores cursor location after closing output with <esc><esc>", function()
|
||||||
|
local runner = {
|
||||||
|
name = "test-runner-restore",
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = {}, 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-restore-runner"] = runner
|
||||||
|
test_samurai.setup({ runner_modules = { "test-samurai-restore-runner" } })
|
||||||
|
|
||||||
|
local normal_win = nil
|
||||||
|
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||||
|
local cfg = vim.api.nvim_win_get_config(win)
|
||||||
|
if cfg.relative == "" then
|
||||||
|
normal_win = win
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if normal_win then
|
||||||
|
vim.api.nvim_set_current_win(normal_win)
|
||||||
|
end
|
||||||
|
|
||||||
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||||
|
vim.api.nvim_buf_set_name(bufnr, "/tmp/test_samurai_restore.go")
|
||||||
|
vim.bo[bufnr].filetype = "go"
|
||||||
|
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { "line1", "line2", "line3" })
|
||||||
|
vim.api.nvim_set_current_buf(bufnr)
|
||||||
|
vim.api.nvim_win_set_cursor(0, { 2, 1 })
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
core.close_output_and_restore()
|
||||||
|
|
||||||
|
local cur_buf = vim.api.nvim_get_current_buf()
|
||||||
|
local cur_cursor = vim.api.nvim_win_get_cursor(0)
|
||||||
|
|
||||||
|
vim.fn.jobstart = orig_jobstart
|
||||||
|
|
||||||
|
assert.equals(bufnr, cur_buf)
|
||||||
|
assert.equals(2, cur_cursor[1])
|
||||||
|
assert.equals(1, cur_cursor[2])
|
||||||
|
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",
|
||||||
|
})
|
||||||
|
|
||||||
|
local cmd_calls = {}
|
||||||
|
local orig_cmd = vim.cmd
|
||||||
|
vim.cmd = function(cmd)
|
||||||
|
table.insert(cmd_calls, cmd)
|
||||||
|
return orig_cmd(cmd)
|
||||||
|
end
|
||||||
|
|
||||||
|
core.listing_break_on_dashes()
|
||||||
|
|
||||||
|
local has_noh = false
|
||||||
|
for _, cmd in ipairs(cmd_calls) do
|
||||||
|
if cmd == "noh" then
|
||||||
|
has_noh = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.is_true(has_noh)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
vim.cmd = orig_cmd
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("saves all buffers before running tests", function()
|
||||||
|
local runner = {
|
||||||
|
name = "test-runner-save-buffers",
|
||||||
|
}
|
||||||
|
|
||||||
|
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.parse_results(_output)
|
||||||
|
return { passes = {}, failures = {}, 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-save-buffers-runner"] = runner
|
||||||
|
test_samurai.setup({ runner_modules = { "test-samurai-save-buffers-runner" } })
|
||||||
|
|
||||||
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||||
|
vim.api.nvim_buf_set_name(bufnr, "/tmp/test_samurai_save_buffers.go")
|
||||||
|
vim.bo[bufnr].filetype = "go"
|
||||||
|
vim.api.nvim_set_current_buf(bufnr)
|
||||||
|
|
||||||
|
local cmd_calls = {}
|
||||||
|
local orig_cmd = vim.cmd
|
||||||
|
vim.cmd = function(cmd)
|
||||||
|
table.insert(cmd_calls, cmd)
|
||||||
|
end
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
vim.fn.jobstart = orig_jobstart
|
||||||
|
vim.cmd = orig_cmd
|
||||||
|
|
||||||
|
local has_wall = false
|
||||||
|
for _, cmd in ipairs(cmd_calls) do
|
||||||
|
if cmd == "wall" then
|
||||||
|
has_wall = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.is_true(has_wall)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("renders the summary in the listing after TSamLast", function()
|
||||||
|
local runner = {
|
||||||
|
name = "test-runner-last-summary",
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = { "TestA" }, failures = { "TestB" }, 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-last-summary-runner"] = runner
|
||||||
|
test_samurai.setup({ runner_modules = { "test-samurai-last-summary-runner" } })
|
||||||
|
|
||||||
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||||
|
vim.api.nvim_buf_set_name(bufnr, "/tmp/test_samurai_last_summary.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()
|
||||||
|
core.run_last()
|
||||||
|
|
||||||
|
local listing_buf = vim.api.nvim_get_current_buf()
|
||||||
|
local lines = vim.api.nvim_buf_get_lines(listing_buf, 0, -1, false)
|
||||||
|
local joined = table.concat(lines, "\n")
|
||||||
|
assert.is_true(joined:find("TOTAL", 1, true) ~= nil)
|
||||||
|
|
||||||
vim.fn.jobstart = orig_jobstart
|
vim.fn.jobstart = orig_jobstart
|
||||||
end)
|
end)
|
||||||
@@ -516,4 +918,444 @@ 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)
|
||||||
|
local selection_ns = vim.api.nvim_create_namespace("TestSamuraiListingSelection")
|
||||||
|
local marks = vim.api.nvim_buf_get_extmarks(listing_buf, selection_ns, 0, -1, { details = true })
|
||||||
|
assert.is_true(#marks > 0)
|
||||||
|
local highlighted = false
|
||||||
|
for _, mark in ipairs(marks) do
|
||||||
|
if mark[2] == target - 1 then
|
||||||
|
highlighted = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.is_true(highlighted)
|
||||||
|
|
||||||
|
vim.fn.jobstart = orig_jobstart
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("maps <leader>ff to jump to the first listing entry and open the detail float", function()
|
||||||
|
local runner = {
|
||||||
|
name = "test-runner",
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
local passes = {}
|
||||||
|
if type(output) == "string" and output:find("PASS TestA", 1, true) then
|
||||||
|
passes = { "TestA" }
|
||||||
|
end
|
||||||
|
return { passes = passes, failures = {}, skips = {} }
|
||||||
|
end
|
||||||
|
|
||||||
|
function runner.output_parser()
|
||||||
|
return {
|
||||||
|
on_line = function(line, _state)
|
||||||
|
if line == "PASS TestA" then
|
||||||
|
return { passes = { "TestA" }, failures = {}, skips = {} }
|
||||||
|
end
|
||||||
|
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-test-runner"] = runner
|
||||||
|
test_samurai.setup({ runner_modules = { "test-samurai-test-runner" } })
|
||||||
|
|
||||||
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||||
|
vim.api.nvim_buf_set_name(bufnr, "/tmp/test_runner_listing_ff.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_stdout then
|
||||||
|
opts.on_stdout(nil, { "PASS TestA" }, nil)
|
||||||
|
end
|
||||||
|
if opts.on_exit then
|
||||||
|
opts.on_exit(nil, 0, nil)
|
||||||
|
end
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
core.run_nearest()
|
||||||
|
|
||||||
|
vim.fn.jobstart = orig_jobstart
|
||||||
|
|
||||||
|
local listing_buf = vim.api.nvim_get_current_buf()
|
||||||
|
assert.is_true(vim.bo[listing_buf].filetype == "test-samurai-output")
|
||||||
|
|
||||||
|
local maps = vim.api.nvim_buf_get_keymap(listing_buf, "n")
|
||||||
|
local found = nil
|
||||||
|
for _, map in ipairs(maps) do
|
||||||
|
if type(map.lhs) == "string" and map.lhs:sub(-2) == "ff" then
|
||||||
|
found = map
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.is_true(found ~= nil)
|
||||||
|
assert.equals("[F]ind [F]irst list entry", found.desc)
|
||||||
|
|
||||||
|
vim.api.nvim_set_current_buf(listing_buf)
|
||||||
|
local listing_win = vim.api.nvim_get_current_win()
|
||||||
|
local total = vim.api.nvim_buf_line_count(listing_buf)
|
||||||
|
vim.api.nvim_win_set_cursor(0, { total, 0 })
|
||||||
|
assert.is_true(type(found.callback) == "function")
|
||||||
|
found.callback()
|
||||||
|
|
||||||
|
local lines = vim.api.nvim_buf_get_lines(listing_buf, 0, -1, false)
|
||||||
|
local first_entry = nil
|
||||||
|
for i, line in ipairs(lines) do
|
||||||
|
if line:match("^%[ %u+ %] %- ") then
|
||||||
|
first_entry = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.is_true(first_entry ~= nil)
|
||||||
|
local cursor = vim.api.nvim_win_get_cursor(listing_win)
|
||||||
|
assert.equals(first_entry, cursor[1])
|
||||||
|
|
||||||
|
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)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("opens the detail float after jumping to the next failed entry", function()
|
||||||
|
local runner = {
|
||||||
|
name = "test-runner-listing-fn",
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = "TestB" }
|
||||||
|
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 = { "TestB" }, skips = {} }
|
||||||
|
end
|
||||||
|
|
||||||
|
function runner.output_parser()
|
||||||
|
return {
|
||||||
|
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-fn-runner"] = runner
|
||||||
|
test_samurai.setup({ runner_modules = { "test-samurai-fn-runner" } })
|
||||||
|
|
||||||
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||||
|
vim.api.nvim_buf_set_name(bufnr, "/tmp/test_runner_listing_fn.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()
|
||||||
|
|
||||||
|
vim.fn.jobstart = orig_jobstart
|
||||||
|
|
||||||
|
local listing_buf = vim.api.nvim_get_current_buf()
|
||||||
|
assert.is_true(vim.bo[listing_buf].filetype == "test-samurai-output")
|
||||||
|
|
||||||
|
local maps = vim.api.nvim_buf_get_keymap(listing_buf, "n")
|
||||||
|
local found = nil
|
||||||
|
for _, map in ipairs(maps) do
|
||||||
|
if type(map.lhs) == "string" and map.lhs:sub(-2) == "fn" then
|
||||||
|
found = map
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.is_true(found ~= nil)
|
||||||
|
|
||||||
|
vim.api.nvim_set_current_buf(listing_buf)
|
||||||
|
local listing_win = vim.api.nvim_get_current_win()
|
||||||
|
vim.api.nvim_win_set_cursor(0, { 1, 0 })
|
||||||
|
assert.is_true(type(found.callback) == "function")
|
||||||
|
found.callback()
|
||||||
|
|
||||||
|
local lines = vim.api.nvim_buf_get_lines(listing_buf, 0, -1, false)
|
||||||
|
local fail_entry = nil
|
||||||
|
for i, line in ipairs(lines) do
|
||||||
|
if line:match("^%[ FAIL %] %- ") then
|
||||||
|
fail_entry = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.is_true(fail_entry ~= nil)
|
||||||
|
local cursor = vim.api.nvim_win_get_cursor(listing_win)
|
||||||
|
assert.equals(fail_entry, cursor[1])
|
||||||
|
|
||||||
|
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)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("allows <leader>fn from the detail float to jump the listing and refresh detail", function()
|
||||||
|
local runner = {
|
||||||
|
name = "test-runner-detail-fn",
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = "TestC" }
|
||||||
|
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 = { "TestC" }, skips = {} }
|
||||||
|
end
|
||||||
|
|
||||||
|
function runner.output_parser()
|
||||||
|
return {
|
||||||
|
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-detail-fn-runner"] = runner
|
||||||
|
test_samurai.setup({ runner_modules = { "test-samurai-detail-fn-runner" } })
|
||||||
|
|
||||||
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||||
|
vim.api.nvim_buf_set_name(bufnr, "/tmp/test_runner_detail_fn.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()
|
||||||
|
|
||||||
|
vim.fn.jobstart = orig_jobstart
|
||||||
|
|
||||||
|
local listing_buf = vim.api.nvim_get_current_buf()
|
||||||
|
assert.is_true(vim.bo[listing_buf].filetype == "test-samurai-output")
|
||||||
|
|
||||||
|
local lines = vim.api.nvim_buf_get_lines(listing_buf, 0, -1, false)
|
||||||
|
local fail_entry = nil
|
||||||
|
for i, line in ipairs(lines) do
|
||||||
|
if line:match("^%[ FAIL %] %- ") then
|
||||||
|
fail_entry = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.is_true(fail_entry ~= nil)
|
||||||
|
|
||||||
|
local listing_win = vim.api.nvim_get_current_win()
|
||||||
|
vim.api.nvim_win_set_cursor(listing_win, { fail_entry, 0 })
|
||||||
|
core.open_test_output_at_cursor()
|
||||||
|
|
||||||
|
local detail_win = vim.api.nvim_get_current_win()
|
||||||
|
local detail_buf = vim.api.nvim_get_current_buf()
|
||||||
|
local maps = vim.api.nvim_buf_get_keymap(detail_buf, "n")
|
||||||
|
local found = nil
|
||||||
|
for _, map in ipairs(maps) do
|
||||||
|
if type(map.lhs) == "string" and map.lhs:sub(-2) == "fn" then
|
||||||
|
found = map
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert.is_true(found ~= nil)
|
||||||
|
|
||||||
|
vim.api.nvim_set_current_win(listing_win)
|
||||||
|
vim.api.nvim_win_set_cursor(listing_win, { 1, 0 })
|
||||||
|
vim.api.nvim_set_current_win(detail_win)
|
||||||
|
|
||||||
|
assert.is_true(type(found.callback) == "function")
|
||||||
|
found.callback()
|
||||||
|
|
||||||
|
local cursor = vim.api.nvim_win_get_cursor(listing_win)
|
||||||
|
assert.equals(fail_entry, cursor[1])
|
||||||
|
|
||||||
|
local refreshed_buf = vim.api.nvim_get_current_buf()
|
||||||
|
local detail_lines = vim.api.nvim_buf_get_lines(refreshed_buf, 0, -1, false)
|
||||||
|
assert.same({ "", "No output captured" }, detail_lines)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user