Add messages to diagnostic for failing tests
This commit is contained in:
parent
9de263590e
commit
b276d18995
@ -23,12 +23,6 @@ local test_function_query_string = [[
|
||||
)
|
||||
]]
|
||||
|
||||
local t_run_query_string = [[
|
||||
(
|
||||
|
||||
)
|
||||
]]
|
||||
|
||||
local find_test_line = function(go_bufnr, name)
|
||||
local formatted = string.format(test_function_query_string, name)
|
||||
local query = vim.treesitter.query.parse("go", formatted)
|
||||
@ -75,7 +69,7 @@ end, {})
|
||||
local errored = false
|
||||
function M.goRunTests()
|
||||
-- TODO: replace jobstart/jobwait with system()
|
||||
local id = vim.fn.jobstart({ "go", "test", "./...", "-json" }, {
|
||||
vim.fn.jobstart({ "go", "test", "./...", "-json" }, {
|
||||
stdout_buffered = true,
|
||||
on_stdout = function(_, data)
|
||||
if errored == true then
|
||||
@ -89,6 +83,7 @@ function M.goRunTests()
|
||||
|
||||
clear(M.results)
|
||||
|
||||
local collected_messages = {}
|
||||
for _, line in ipairs(data) do
|
||||
if line == "" then goto continue end
|
||||
local decoded = vim.json.decode(line)
|
||||
@ -99,9 +94,22 @@ function M.goRunTests()
|
||||
if decoded.Action == 'pass' or decoded.Action == 'fail' then
|
||||
M.results[decoded.Test] = { Action = decoded.Action }
|
||||
end
|
||||
|
||||
if decoded.Action == 'output' then
|
||||
local testname = decoded.Test
|
||||
local a = ""
|
||||
if collected_messages[testname] == nil then
|
||||
a = ""
|
||||
else
|
||||
a = collected_messages[testname]
|
||||
end
|
||||
collected_messages[decoded.Test] = a .. decoded.Output
|
||||
end
|
||||
::continue::
|
||||
end
|
||||
-- Merge collected messages into results
|
||||
for test, _ in pairs(M.results) do
|
||||
M.results[test].Message = collected_messages[test]
|
||||
end
|
||||
end,
|
||||
on_stderr = function(_, data)
|
||||
for _, value in pairs(data) do
|
||||
@ -156,7 +164,7 @@ function M.goSetMarks(currbuf)
|
||||
col = 0,
|
||||
severity = vim.diagnostic.severity.ERROR,
|
||||
source = "go-test",
|
||||
message = "Test Failed",
|
||||
message = "Test Failed\n\n" .. val.Message,
|
||||
user_data = {},
|
||||
})
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user