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