1351 lines
39 KiB
Lua
1351 lines
39 KiB
Lua
local test_samurai = require("test-samurai")
|
|
local core = require("test-samurai.core")
|
|
local config = require("test-samurai.config")
|
|
|
|
describe("test-samurai core (no bundled runners)", function()
|
|
before_each(function()
|
|
test_samurai.setup()
|
|
end)
|
|
|
|
it("defaults to an empty runner_modules list", function()
|
|
local cfg = config.get()
|
|
assert.is_true(type(cfg.runner_modules) == "table")
|
|
assert.equals(0, #cfg.runner_modules)
|
|
end)
|
|
|
|
it("warns when no runner is installed for a test file", function()
|
|
local notified = {}
|
|
local orig_notify = vim.notify
|
|
vim.notify = function(msg, level)
|
|
table.insert(notified, { msg = msg, level = level })
|
|
end
|
|
|
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
|
vim.api.nvim_buf_set_name(bufnr, "/tmp/no_runner_test.go")
|
|
vim.bo[bufnr].filetype = "go"
|
|
vim.api.nvim_set_current_buf(bufnr)
|
|
|
|
core.run_nearest()
|
|
|
|
vim.notify = orig_notify
|
|
|
|
assert.equals(1, #notified)
|
|
assert.equals("[test-samurai] no runner installed for this kind of test", notified[1].msg)
|
|
end)
|
|
|
|
it("fills quickfix after failed-only runs using last failures", 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 = {}
|
|
local failures = {}
|
|
if type(output) == "string" then
|
|
if output:find("FAIL TestA", 1, true) then
|
|
failures = { "TestA" }
|
|
end
|
|
if output:find("PASS TestA", 1, true) then
|
|
passes = { "TestA" }
|
|
end
|
|
end
|
|
return { passes = passes, failures = failures, skips = {} }
|
|
end
|
|
|
|
function runner.output_parser()
|
|
return {
|
|
on_line = function(line, _state)
|
|
if line == "FAIL TestA" then
|
|
return { passes = {}, failures = { "TestA" }, skips = {} }
|
|
end
|
|
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)
|
|
local items = {}
|
|
for _, name in ipairs(failures or {}) do
|
|
table.insert(items, { filename = "file", lnum = 1, col = 1, text = name })
|
|
end
|
|
return items
|
|
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_quickfix.go")
|
|
vim.bo[bufnr].filetype = "go"
|
|
vim.api.nvim_set_current_buf(bufnr)
|
|
|
|
local qf_calls = {}
|
|
local orig_setqflist = vim.fn.setqflist
|
|
vim.fn.setqflist = function(_, _, opts)
|
|
if opts and type(opts.items) == "table" then
|
|
table.insert(qf_calls, opts.items)
|
|
end
|
|
end
|
|
|
|
local job_outputs = {
|
|
{ "FAIL TestA" },
|
|
{ "PASS TestA" },
|
|
}
|
|
local orig_jobstart = vim.fn.jobstart
|
|
vim.fn.jobstart = function(_cmd, opts)
|
|
local lines = table.remove(job_outputs, 1) or {}
|
|
if opts.on_stdout then
|
|
opts.on_stdout(nil, lines, nil)
|
|
end
|
|
if opts.on_exit then
|
|
opts.on_exit(nil, 0, nil)
|
|
end
|
|
return 1
|
|
end
|
|
|
|
core.run_nearest()
|
|
core.run_failed_only()
|
|
|
|
vim.fn.jobstart = orig_jobstart
|
|
vim.fn.setqflist = orig_setqflist
|
|
|
|
local last = qf_calls[#qf_calls]
|
|
assert.is_true(type(last) == "table")
|
|
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
|
|
local has_cb = false
|
|
local has_cj = false
|
|
for _, map in ipairs(maps) do
|
|
if map.lhs == "?" then
|
|
has_help = true
|
|
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
|
|
assert.is_true(has_help)
|
|
assert.is_true(has_cb)
|
|
assert.is_true(has_cj)
|
|
|
|
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("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>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
|
|
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)
|
|
|
|
it("runs the test under the cursor from the listing", function()
|
|
local runner = {
|
|
name = "test-runner-run-cursor",
|
|
}
|
|
|
|
function runner.is_test_file(_bufnr)
|
|
return true
|
|
end
|
|
|
|
function runner.find_nearest(bufnr, _row, _col)
|
|
return { file = vim.api.nvim_buf_get_name(bufnr), cwd = vim.loop.cwd(), test_name = "TestA" }
|
|
end
|
|
|
|
local build_specs = {}
|
|
function runner.build_command(spec)
|
|
table.insert(build_specs, vim.deepcopy(spec))
|
|
return { cmd = { "echo", "single" }, cwd = spec.cwd }
|
|
end
|
|
|
|
function runner.build_file_command(_bufnr)
|
|
return { cmd = { "echo", "file" } }
|
|
end
|
|
|
|
function runner.build_all_command(_bufnr)
|
|
return { cmd = { "echo", "all" } }
|
|
end
|
|
|
|
function runner.build_failed_command(last_command, _failures, _scope_kind)
|
|
return { cmd = { "echo", "failed" }, cwd = last_command and last_command.cwd or nil }
|
|
end
|
|
|
|
function runner.parse_results(_output)
|
|
return { passes = { "TestA" }, failures = { "TestC" }, skips = { "TestB" } }
|
|
end
|
|
|
|
function runner.output_parser()
|
|
return {
|
|
on_line = function(_line, _state)
|
|
return nil
|
|
end,
|
|
on_complete = function(output, _state)
|
|
return runner.parse_results(output)
|
|
end,
|
|
}
|
|
end
|
|
|
|
function runner.parse_test_output(_output)
|
|
return {}
|
|
end
|
|
|
|
function runner.collect_failed_locations(_failures, _command, _scope_kind)
|
|
return {}
|
|
end
|
|
|
|
package.loaded["test-samurai-run-cursor-runner"] = runner
|
|
test_samurai.setup({ runner_modules = { "test-samurai-run-cursor-runner" } })
|
|
|
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
|
vim.api.nvim_buf_set_name(bufnr, "/tmp/test_samurai_run_cursor.go")
|
|
vim.bo[bufnr].filetype = "go"
|
|
vim.api.nvim_set_current_buf(bufnr)
|
|
|
|
local orig_jobstart = vim.fn.jobstart
|
|
vim.fn.jobstart = function(_cmd, opts)
|
|
if opts.on_exit then
|
|
opts.on_exit(nil, 0, nil)
|
|
end
|
|
return 1
|
|
end
|
|
|
|
runner._last_mocha_titles = { TestC = "Suite TestC" }
|
|
core.run_nearest()
|
|
|
|
local listing_buf = vim.api.nvim_get_current_buf()
|
|
local lines = vim.api.nvim_buf_get_lines(listing_buf, 0, -1, false)
|
|
local target = nil
|
|
for i, line in ipairs(lines) do
|
|
if line:match("^%[ FAIL %] %-") then
|
|
target = i
|
|
break
|
|
end
|
|
end
|
|
assert.is_true(target ~= nil)
|
|
|
|
vim.api.nvim_win_set_cursor(0, { target, 0 })
|
|
core.run_test_at_cursor()
|
|
|
|
vim.api.nvim_win_set_cursor(0, { 1, 0 })
|
|
core.run_test_at_cursor()
|
|
|
|
vim.fn.jobstart = orig_jobstart
|
|
|
|
assert.equals(2, #build_specs)
|
|
assert.equals("TestC", build_specs[2].test_name)
|
|
assert.equals("TestC", build_specs[2].full_name)
|
|
assert.equals("Suite TestC", build_specs[2].mocha_full_title)
|
|
end)
|
|
|
|
it("opens detail float with placeholder when no output captured", function()
|
|
local runner = {
|
|
name = "test-runner-no-output",
|
|
}
|
|
|
|
function runner.is_test_file(_bufnr)
|
|
return true
|
|
end
|
|
|
|
function runner.find_nearest(bufnr, _row, _col)
|
|
return { file = vim.api.nvim_buf_get_name(bufnr), cwd = vim.loop.cwd(), test_name = "TestA" }
|
|
end
|
|
|
|
function runner.build_command(spec)
|
|
return { cmd = { "echo", "nearest" }, cwd = spec.cwd }
|
|
end
|
|
|
|
function runner.build_file_command(_bufnr)
|
|
return { cmd = { "echo", "file" } }
|
|
end
|
|
|
|
function runner.build_all_command(_bufnr)
|
|
return { cmd = { "echo", "all" } }
|
|
end
|
|
|
|
function runner.build_failed_command(last_command, _failures, _scope_kind)
|
|
return { cmd = { "echo", "failed" }, cwd = last_command and last_command.cwd or nil }
|
|
end
|
|
|
|
function runner.parse_results(_output)
|
|
return { passes = {}, failures = { "TestMissingOutput" }, skips = {} }
|
|
end
|
|
|
|
function runner.output_parser()
|
|
return {
|
|
on_line = function(_line, _state)
|
|
return nil
|
|
end,
|
|
on_complete = function(output, _state)
|
|
return runner.parse_results(output)
|
|
end,
|
|
}
|
|
end
|
|
|
|
function runner.parse_test_output(_output)
|
|
return {}
|
|
end
|
|
|
|
function runner.collect_failed_locations(_failures, _command, _scope_kind)
|
|
return {}
|
|
end
|
|
|
|
package.loaded["test-samurai-no-output-runner"] = runner
|
|
test_samurai.setup({ runner_modules = { "test-samurai-no-output-runner" } })
|
|
|
|
local bufnr = vim.api.nvim_create_buf(false, true)
|
|
vim.api.nvim_buf_set_name(bufnr, "/tmp/test_samurai_no_output.go")
|
|
vim.bo[bufnr].filetype = "go"
|
|
vim.api.nvim_set_current_buf(bufnr)
|
|
|
|
local orig_jobstart = vim.fn.jobstart
|
|
vim.fn.jobstart = function(_cmd, opts)
|
|
if opts.on_exit then
|
|
opts.on_exit(nil, 0, nil)
|
|
end
|
|
return 1
|
|
end
|
|
|
|
core.run_nearest()
|
|
|
|
local listing_buf = vim.api.nvim_get_current_buf()
|
|
local lines = vim.api.nvim_buf_get_lines(listing_buf, 0, -1, false)
|
|
local target = nil
|
|
for i, line in ipairs(lines) do
|
|
if line:match("^%[ FAIL %] %- TestMissingOutput") then
|
|
target = i
|
|
break
|
|
end
|
|
end
|
|
assert.is_true(target ~= nil)
|
|
|
|
vim.api.nvim_win_set_cursor(0, { target, 0 })
|
|
core.open_test_output_at_cursor()
|
|
|
|
local detail_buf = vim.api.nvim_get_current_buf()
|
|
local detail_lines = vim.api.nvim_buf_get_lines(detail_buf, 0, -1, false)
|
|
assert.same({ "", "No output captured" }, detail_lines)
|
|
|
|
vim.fn.jobstart = orig_jobstart
|
|
end)
|
|
|
|
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)
|