add keymaps for quick filtering the test-listings
All checks were successful
tests / test (push) Successful in 10s
All checks were successful
tests / test (push) Successful in 10s
This commit is contained in:
@@ -242,4 +242,180 @@ describe("test-samurai core (no bundled runners)", function()
|
||||
|
||||
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