Compare commits
4 Commits
e315a8e8f2
...
5d0b4e9dd6
| Author | SHA1 | Date | |
|---|---|---|---|
|
5d0b4e9dd6
|
|||
|
c538a32307
|
|||
|
e9a7d2029b
|
|||
|
4c2d585f2d
|
@@ -11,6 +11,9 @@
|
||||
- **Keine stillen Änderungen**:
|
||||
- Bestehende Features dürfen nicht unbemerkt geändert oder ersetzt werden.
|
||||
- Notwendige Anpassungen zur Koexistenz mehrerer Features müssen klar erkennbar sein.
|
||||
- **Hilfe-Ansicht aktuell halten**:
|
||||
- Änderungen und/oder Erweiterungen müssen **immer** die `:help`-Dokumentation, die README.md und die `quick-help`-Ansicht (via `?`) automatisch aktualisieren.
|
||||
- Sprache der Hilfe ist wie die README.md immer **englisch**.
|
||||
|
||||
## Projektziel
|
||||
- Neovim Plugin: **test-samurai**
|
||||
|
||||
@@ -59,12 +59,17 @@ If no runner matches the current test file, test-samurai will show:
|
||||
- `TSamLast` -> `<leader>tl`
|
||||
- `TSamFailedOnly` -> `<leader>te`
|
||||
- `TSamShowOutput` -> `<leader>to`
|
||||
- Help: `:help test-samurai`
|
||||
|
||||
Additional keymaps:
|
||||
|
||||
- `<leader>qn` -> close the testing floats and jump to the first quickfix entry
|
||||
- `<leader>nf` -> jump to the next `[ FAIL ]` entry in the Test-Listing-Float (wraps to the first)
|
||||
- `<leader>pf` -> jump to the previous `[ FAIL ]` entry in the Test-Listing-Float (wraps to the last)
|
||||
- `<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
|
||||
- `?` -> show help with TSam commands and standard keymaps in the Detail-Float
|
||||
|
||||
## Output UI
|
||||
|
||||
@@ -104,7 +109,7 @@ No runner for your environment exists? No problem: use `runners-agents.md` to gu
|
||||
|
||||
## Development
|
||||
|
||||
Runner development guidelines, including required data formats for keymaps, tests (`run_test.sh`), and Gitea CI (Neovim AppImage on ARM runners), are documented in `runner-agents.md`.
|
||||
Runner development guidelines, including required data formats for keymaps, tests (`run_test.sh`), Gitea CI (Neovim AppImage on ARM runners), and framework-agnostic best practices (naming conventions, TSamNearest priority, reporter payloads, failed-only behavior), are documented in `runner-agents.md`.
|
||||
|
||||
Tests are written with `plenary.nvim` / `busted`. Mocks and stubs are allowed.
|
||||
|
||||
|
||||
9
doc/tags
Normal file
9
doc/tags
Normal file
@@ -0,0 +1,9 @@
|
||||
test-samurai test-samurai.txt /*test-samurai*
|
||||
test-samurai-commands test-samurai.txt /*test-samurai-commands*
|
||||
test-samurai-default-keys test-samurai.txt /*test-samurai-default-keys*
|
||||
test-samurai-quickhelp test-samurai.txt /*test-samurai-quickhelp*
|
||||
test-samurai-req test-samurai.txt /*test-samurai-req*
|
||||
test-samurai-runners test-samurai.txt /*test-samurai-runners*
|
||||
test-samurai-setup test-samurai.txt /*test-samurai-setup*
|
||||
test-samurai-ui test-samurai.txt /*test-samurai-ui*
|
||||
test-samurai.txt test-samurai.txt /*test-samurai.txt*
|
||||
86
doc/test-samurai.txt
Normal file
86
doc/test-samurai.txt
Normal file
@@ -0,0 +1,86 @@
|
||||
*test-samurai.txt* Run tests with a unified UX
|
||||
|
||||
INTRODUCTION *test-samurai*
|
||||
|
||||
Test Samurai provides a unified UX to run tests across languages
|
||||
and frameworks, backed by an extensible runner architecture.
|
||||
|
||||
|
||||
REQUIREMENTS *test-samurai-req*
|
||||
|
||||
Neovim 0.11.4 or later is required.
|
||||
|
||||
|
||||
SETUP *test-samurai-setup*
|
||||
|
||||
This plugin ships without built-in runners. Configure runner modules
|
||||
in your setup so test commands and keymaps work properly:
|
||||
|
||||
>
|
||||
require("test-samurai").setup({
|
||||
runner_modules = {
|
||||
"my-runners.go",
|
||||
"my-runners.js",
|
||||
},
|
||||
})
|
||||
<
|
||||
|
||||
|
||||
COMMANDS *test-samurai-commands*
|
||||
|
||||
:TSamNearest Run the nearest test.
|
||||
:TSamFile Run all tests in the current file.
|
||||
:TSamAll Run all tests in the project.
|
||||
:TSamLast Re-run the last test command.
|
||||
:TSamFailedOnly Re-run only previously failed tests.
|
||||
:TSamShowOutput Reopen the Testing-Float output window.
|
||||
|
||||
|
||||
DEFAULT KEYMAPS *test-samurai-default-keys*
|
||||
|
||||
TSamNearest <leader>tn
|
||||
TSamFile <leader>tf
|
||||
TSamAll <leader>ta
|
||||
TSamLast <leader>tl
|
||||
TSamFailedOnly <leader>te
|
||||
TSamShowOutput <leader>to
|
||||
|
||||
|
||||
QUICK-HELP & FLOATS *test-samurai-quickhelp*
|
||||
|
||||
In the Testing-Float, press ? to open the quick-help in the Detail-Float.
|
||||
|
||||
Additional keymaps:
|
||||
<leader>qn Close floats + jump to the first quickfix entry
|
||||
<leader>nf Next [ FAIL ] in listing
|
||||
<leader>pf Previous [ FAIL ] in listing
|
||||
<leader>sf Filter listing to [ FAIL ] only
|
||||
<leader>ss Filter listing to [ SKIP ] only
|
||||
<leader>sa Show all listing entries (clear filter)
|
||||
<leader>o Jump to test location
|
||||
<leader>z Toggle Detail-Float full width
|
||||
<C-l> Focus Detail-Float (press l again for full)
|
||||
<C-h> Focus Test-Listing-Float
|
||||
<esc><esc> Close Testing-Float
|
||||
<C-c> Close Detail-Float (when focused)
|
||||
|
||||
|
||||
OUTPUT UI *test-samurai-ui*
|
||||
|
||||
Testing-Float: container floating window for output.
|
||||
Test-Listing-Float: left subwindow listing test results.
|
||||
Detail-Float: right subwindow showing detailed output for a test.
|
||||
|
||||
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
|
||||
the Detail-Float with a 20/80 split. ANSI colors are translated only
|
||||
inside the Detail-Float.
|
||||
|
||||
|
||||
RUNNER ARCHITECTURE *test-samurai-runners*
|
||||
|
||||
Runners are standalone Lua modules that implement the full interface.
|
||||
See README.md for the required functions and runner guidelines.
|
||||
|
||||
==============================================================================
|
||||
vim:ft=help
|
||||
@@ -23,6 +23,8 @@ local state = {
|
||||
detail_win = nil,
|
||||
detail_opening = false,
|
||||
detail_full = false,
|
||||
listing_unfiltered_lines = nil,
|
||||
listing_filtered_kind = nil,
|
||||
hardtime_refcount = 0,
|
||||
hardtime_was_enabled = false,
|
||||
autocmds_set = false,
|
||||
@@ -36,6 +38,8 @@ local close_container
|
||||
local restore_listing_full
|
||||
local close_detail_float
|
||||
local jump_to_first_quickfix
|
||||
local apply_summary_highlights
|
||||
local apply_result_highlights
|
||||
|
||||
local function disable_container_maps(buf)
|
||||
local opts = { buffer = buf, nowait = true, silent = true }
|
||||
@@ -43,6 +47,146 @@ local function disable_container_maps(buf)
|
||||
vim.keymap.set("n", "<C-k>", "<Nop>", opts)
|
||||
end
|
||||
|
||||
local function help_lines()
|
||||
return {
|
||||
"Test-Samurai Help",
|
||||
"",
|
||||
"TSam Commands:",
|
||||
" TSamNearest <leader>tn",
|
||||
" TSamFile <leader>tf",
|
||||
" TSamAll <leader>ta",
|
||||
" TSamLast <leader>tl",
|
||||
" TSamFailedOnly <leader>te",
|
||||
" TSamShowOutput <leader>to",
|
||||
"",
|
||||
"Standard Keymaps:",
|
||||
" <leader>qn Close floats + jump to first quickfix entry",
|
||||
" <leader>nf Next [ FAIL ] in listing",
|
||||
" <leader>pf Previous [ FAIL ] in listing",
|
||||
" <leader>sf Filter listing to [ FAIL ] only",
|
||||
" <leader>ss Filter listing to [ SKIP ] only",
|
||||
" <leader>sa Show all listing entries (clear filter)",
|
||||
"",
|
||||
"Testing-Float (Listing):",
|
||||
" <cr> Open Detail-Float for selected test",
|
||||
" <esc><esc> Close Testing-Float",
|
||||
" <C-l> Focus Detail-Float (press l again for full)",
|
||||
" <C-h> Focus Test-Listing-Float",
|
||||
" <leader>z Toggle Detail-Float full width",
|
||||
" <leader>o Jump to test location",
|
||||
" ? Show this help",
|
||||
"",
|
||||
"Testing-Float (Detail):",
|
||||
" <esc><esc> Close Testing-Float",
|
||||
" <C-h> Focus Test-Listing-Float",
|
||||
" <C-w>h Focus Test-Listing-Float",
|
||||
" <C-l> Focus Detail-Float",
|
||||
" <leader>z Toggle Detail-Float full width",
|
||||
" <C-c> Close Detail-Float",
|
||||
" ? Show this help",
|
||||
}
|
||||
end
|
||||
|
||||
local function split_listing_sections(lines)
|
||||
local summary_start = nil
|
||||
for i, line in ipairs(lines or {}) do
|
||||
if line:match("^TOTAL%s+%d+") then
|
||||
summary_start = i - 1
|
||||
if summary_start < 2 then
|
||||
summary_start = 2
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
local header = {}
|
||||
local body = {}
|
||||
local summary = {}
|
||||
if lines and #lines > 0 then
|
||||
header = { lines[1] }
|
||||
end
|
||||
for i, line in ipairs(lines or {}) do
|
||||
if i == 1 then
|
||||
elseif summary_start and i >= summary_start then
|
||||
table.insert(summary, line)
|
||||
else
|
||||
table.insert(body, line)
|
||||
end
|
||||
end
|
||||
return header, body, summary
|
||||
end
|
||||
|
||||
local function rebuild_result_line_map(lines)
|
||||
state.last_result_line_map = {}
|
||||
for idx, line in ipairs(lines or {}) do
|
||||
local status = line:match("^%[%s*(%u+)%s*%]%s*%-")
|
||||
if status == "PASS" or status == "FAIL" or status == "SKIP" then
|
||||
local name = line:match("^%[%s*[%u]+%s*%]%s*%-%s*(.+)$")
|
||||
if name and name ~= "" then
|
||||
state.last_result_line_map[idx] = name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function apply_listing_lines(buf, 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, summary_ns, 0, -1)
|
||||
apply_result_highlights(buf, 0, lines)
|
||||
apply_summary_highlights(buf, 0, lines)
|
||||
rebuild_result_line_map(lines)
|
||||
end
|
||||
|
||||
local function apply_listing_filter(kind)
|
||||
if not (state.last_buf and vim.api.nvim_buf_is_valid(state.last_buf)) then
|
||||
return
|
||||
end
|
||||
if kind == "all" then
|
||||
if not state.listing_filtered_kind or not state.listing_unfiltered_lines then
|
||||
return
|
||||
end
|
||||
apply_listing_lines(state.last_buf, state.listing_unfiltered_lines)
|
||||
state.listing_filtered_kind = nil
|
||||
return
|
||||
end
|
||||
|
||||
if state.listing_filtered_kind == kind then
|
||||
return
|
||||
end
|
||||
|
||||
local base = state.listing_unfiltered_lines
|
||||
if not base then
|
||||
base = vim.api.nvim_buf_get_lines(state.last_buf, 0, -1, false)
|
||||
state.listing_unfiltered_lines = vim.deepcopy(base)
|
||||
end
|
||||
local header, body, summary = split_listing_sections(base)
|
||||
local filtered = {}
|
||||
for _, line in ipairs(body) do
|
||||
if kind == "fail" and line:match("^%[ FAIL %] %-") then
|
||||
table.insert(filtered, line)
|
||||
elseif kind == "skip" and line:match("^%[ SKIP %] %-") then
|
||||
table.insert(filtered, line)
|
||||
end
|
||||
end
|
||||
if #filtered == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local combined = {}
|
||||
if #header > 0 then
|
||||
table.insert(combined, header[1])
|
||||
table.insert(combined, "")
|
||||
end
|
||||
for _, line in ipairs(filtered) do
|
||||
table.insert(combined, line)
|
||||
end
|
||||
for _, line in ipairs(summary) do
|
||||
table.insert(combined, line)
|
||||
end
|
||||
apply_listing_lines(state.last_buf, combined)
|
||||
state.listing_filtered_kind = kind
|
||||
end
|
||||
|
||||
local function get_hardtime()
|
||||
local ok, hardtime = pcall(require, "hardtime")
|
||||
if not ok or type(hardtime) ~= "table" then
|
||||
@@ -626,6 +770,18 @@ local function create_output_win(initial_lines)
|
||||
vim.keymap.set("n", "<leader>qn", function()
|
||||
jump_to_first_quickfix()
|
||||
end, { buffer = buf, nowait = true, silent = true })
|
||||
vim.keymap.set("n", "<leader>sf", function()
|
||||
M.filter_listing_failures()
|
||||
end, { buffer = buf, nowait = true, silent = true })
|
||||
vim.keymap.set("n", "<leader>ss", function()
|
||||
M.filter_listing_skips()
|
||||
end, { buffer = buf, nowait = true, silent = true })
|
||||
vim.keymap.set("n", "<leader>sa", function()
|
||||
M.filter_listing_all()
|
||||
end, { buffer = buf, nowait = true, silent = true })
|
||||
vim.keymap.set("n", "?", function()
|
||||
M.show_help()
|
||||
end, { buffer = buf, nowait = true, silent = true })
|
||||
disable_container_maps(buf)
|
||||
|
||||
state.last_win = listing
|
||||
@@ -690,6 +846,18 @@ local function reopen_output_win()
|
||||
vim.keymap.set("n", "<leader>qn", function()
|
||||
jump_to_first_quickfix()
|
||||
end, { buffer = state.last_buf, nowait = true, silent = true })
|
||||
vim.keymap.set("n", "<leader>sf", function()
|
||||
M.filter_listing_failures()
|
||||
end, { buffer = state.last_buf, nowait = true, silent = true })
|
||||
vim.keymap.set("n", "<leader>ss", function()
|
||||
M.filter_listing_skips()
|
||||
end, { buffer = state.last_buf, nowait = true, silent = true })
|
||||
vim.keymap.set("n", "<leader>sa", function()
|
||||
M.filter_listing_all()
|
||||
end, { buffer = state.last_buf, nowait = true, silent = true })
|
||||
vim.keymap.set("n", "?", function()
|
||||
M.show_help()
|
||||
end, { buffer = state.last_buf, nowait = true, silent = true })
|
||||
disable_container_maps(state.last_buf)
|
||||
|
||||
state.last_win = win
|
||||
@@ -1005,6 +1173,9 @@ local function ensure_detail_buf(lines)
|
||||
vim.keymap.set("n", "<leader>qn", function()
|
||||
jump_to_first_quickfix()
|
||||
end, { buffer = buf, nowait = true, silent = true })
|
||||
vim.keymap.set("n", "?", function()
|
||||
M.show_help()
|
||||
end, { buffer = buf, nowait = true, silent = true })
|
||||
disable_container_maps(buf)
|
||||
end
|
||||
local clean_lines, highlights = parse_ansi_lines(normalize_output_lines(lines))
|
||||
@@ -1133,6 +1304,26 @@ function M.open_test_output_at_cursor()
|
||||
open_detail_split(output, border_kind)
|
||||
end
|
||||
|
||||
function M.show_help()
|
||||
if not (state.last_win and vim.api.nvim_win_is_valid(state.last_win)) then
|
||||
vim.notify("[test-samurai] No test output window", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
open_detail_split(help_lines(), "default")
|
||||
end
|
||||
|
||||
function M.filter_listing_failures()
|
||||
apply_listing_filter("fail")
|
||||
end
|
||||
|
||||
function M.filter_listing_skips()
|
||||
apply_listing_filter("skip")
|
||||
end
|
||||
|
||||
function M.filter_listing_all()
|
||||
apply_listing_filter("all")
|
||||
end
|
||||
|
||||
function M.focus_listing()
|
||||
if state.last_win and vim.api.nvim_win_is_valid(state.last_win) then
|
||||
if state.detail_win and vim.api.nvim_win_is_valid(state.detail_win) then
|
||||
@@ -1525,7 +1716,7 @@ local function highlight_label_word(buf, ns, lnum, line, label, hl_group)
|
||||
vim.api.nvim_buf_add_highlight(buf, ns, hl_group, lnum, label_start - 1, label_start - 1 + #label)
|
||||
end
|
||||
|
||||
local function apply_summary_highlights(buf, start_line, lines)
|
||||
apply_summary_highlights = function(buf, start_line, lines)
|
||||
if not (buf and vim.api.nvim_buf_is_valid(buf)) then
|
||||
return
|
||||
end
|
||||
@@ -1547,7 +1738,7 @@ local function apply_summary_highlights(buf, start_line, lines)
|
||||
end
|
||||
end
|
||||
|
||||
local function apply_result_highlights(buf, start_line, lines)
|
||||
apply_result_highlights = function(buf, start_line, lines)
|
||||
if not (buf and vim.api.nvim_buf_is_valid(buf)) then
|
||||
return
|
||||
end
|
||||
@@ -1590,6 +1781,8 @@ local function run_command(command, opts)
|
||||
state.last_test_outputs = {}
|
||||
state.last_result_line_map = {}
|
||||
state.last_raw_output = nil
|
||||
state.listing_unfiltered_lines = nil
|
||||
state.listing_filtered_kind = nil
|
||||
local failures = {}
|
||||
local failures_seen = {}
|
||||
if command and type(command.cmd) == "table" and #command.cmd > 0 then
|
||||
@@ -1804,7 +1997,7 @@ local function run_command(command, opts)
|
||||
append_lines(buf, summary_lines)
|
||||
apply_summary_highlights(buf, start_line, summary_lines)
|
||||
end
|
||||
append_lines(buf, { "", "[exit code] " .. tostring(code) })
|
||||
append_lines(buf, { "" })
|
||||
else
|
||||
if not has_output then
|
||||
local cur = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
|
||||
@@ -1823,7 +2016,7 @@ local function run_command(command, opts)
|
||||
append_lines(buf, summary_lines)
|
||||
apply_summary_highlights(buf, start_line, summary_lines)
|
||||
end
|
||||
append_lines(buf, { "", "[exit code] " .. tostring(code) })
|
||||
append_lines(buf, { "" })
|
||||
end
|
||||
if options.track_scope then
|
||||
state.last_scope_exit_code = code
|
||||
|
||||
@@ -237,3 +237,11 @@ jobs:
|
||||
- name: Run tests
|
||||
run: bash run_test.sh
|
||||
```
|
||||
|
||||
## Zusaetzliche Runner-Guidelines (framework-agnostisch)
|
||||
|
||||
- **Testnamen-Konvention:** Runner sollen eine konsistente, dokumentierte Full-Name-Bildung verwenden (z. B. `Parent/Subtest`), inklusive Mehrfach-Nesting. Diese Konvention muss in `results.*`, `parse_test_output` und `collect_failed_locations` uebereinstimmen.
|
||||
- **TSamNearest-Prioritaet:** Falls moeglich, gelten folgende Regeln: Test-Block > Describe/Context-Block > File-Command. Das Verhalten muss getestet werden (Cursor im Test, zwischen Tests, ausserhalb von Describe/Context).
|
||||
- **Reporter-Payload-Schema:** Wenn ein Custom-Reporter verwendet wird, soll dessen JSON-Payload dokumentiert und stabil sein (z. B. `{ name, status, file, location, output }`), damit Parser/Quickfix/Detail-Output konsistent bleiben.
|
||||
- **Failed-Only-Logik:** Failed-Only muss auf den letzten Fehlermeldungen basieren und nur die fehlerhaften Tests erneut ausfuehren. Die Pattern-Strategie (z. B. Titel-only vs. Full-Name) muss getestet werden.
|
||||
- **CI-Installations-Snippet:** Die Neovim-Installation in CI soll als „authoritative snippet“ behandelt werden und in Runner-Repos 1:1 uebernommen werden.
|
||||
|
||||
@@ -148,4 +148,274 @@ describe("test-samurai core (no bundled runners)", function()
|
||||
assert.equals(1, #last)
|
||||
assert.equals("TestA", last[1].text)
|
||||
end)
|
||||
|
||||
it("shows help with TSam commands and keymaps in the detail float", function()
|
||||
local runner = {
|
||||
name = "test-runner-help",
|
||||
}
|
||||
|
||||
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-help-runner"] = runner
|
||||
test_samurai.setup({ runner_modules = { "test-samurai-help-runner" } })
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/test_samurai_help.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 maps = vim.api.nvim_buf_get_keymap(listing_buf, "n")
|
||||
local has_help = false
|
||||
for _, map in ipairs(maps) do
|
||||
if map.lhs == "?" then
|
||||
has_help = true
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_true(has_help)
|
||||
|
||||
core.show_help()
|
||||
|
||||
local detail_buf = vim.api.nvim_get_current_buf()
|
||||
local lines = vim.api.nvim_buf_get_lines(detail_buf, 0, -1, false)
|
||||
local joined = table.concat(lines, "\n")
|
||||
assert.is_true(joined:find("TSamNearest", 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>to", 1, true) ~= nil)
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
|
||||
it("filters listing entries and restores them", function()
|
||||
local runner = {
|
||||
name = "test-runner-filter",
|
||||
}
|
||||
|
||||
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 = { "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-filter-runner"] = runner
|
||||
test_samurai.setup({ runner_modules = { "test-samurai-filter-runner" } })
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/test_samurai_filter.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 original = vim.api.nvim_buf_get_lines(listing_buf, 0, -1, false)
|
||||
|
||||
core.filter_listing_failures()
|
||||
local failures_only = vim.api.nvim_buf_get_lines(listing_buf, 0, -1, false)
|
||||
local failures_joined = table.concat(failures_only, "\n")
|
||||
assert.is_true(failures_joined:find("[ FAIL ] - TestC", 1, true) ~= nil)
|
||||
assert.is_true(failures_joined:find("[ SKIP ] - TestB", 1, true) == nil)
|
||||
assert.equals(original[1], failures_only[1])
|
||||
assert.equals("", failures_only[2])
|
||||
assert.is_true(failures_joined:find("TOTAL", 1, true) ~= nil)
|
||||
|
||||
core.filter_listing_skips()
|
||||
local skips_only = vim.api.nvim_buf_get_lines(listing_buf, 0, -1, false)
|
||||
local skips_joined = table.concat(skips_only, "\n")
|
||||
assert.is_true(skips_joined:find("[ SKIP ] - TestB", 1, true) ~= nil)
|
||||
assert.is_true(skips_joined:find("[ FAIL ] - TestC", 1, true) == nil)
|
||||
|
||||
core.filter_listing_all()
|
||||
local restored = vim.api.nvim_buf_get_lines(listing_buf, 0, -1, false)
|
||||
assert.equals(table.concat(original, "\n"), table.concat(restored, "\n"))
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
|
||||
it("keeps the listing unchanged when no filter matches exist", function()
|
||||
local runner = {
|
||||
name = "test-runner-no-matches",
|
||||
}
|
||||
|
||||
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 = {}, 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-match-runner"] = runner
|
||||
test_samurai.setup({ runner_modules = { "test-samurai-no-match-runner" } })
|
||||
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(bufnr, "/tmp/test_samurai_no_match.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 original = vim.api.nvim_buf_get_lines(listing_buf, 0, -1, false)
|
||||
|
||||
core.filter_listing_failures()
|
||||
core.filter_listing_skips()
|
||||
local after = vim.api.nvim_buf_get_lines(listing_buf, 0, -1, false)
|
||||
assert.equals(table.concat(original, "\n"), table.concat(after, "\n"))
|
||||
|
||||
vim.fn.jobstart = orig_jobstart
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user