Skip to content

Commit

Permalink
@testNG; append test result to nvim-dap repl if installed
Browse files Browse the repository at this point in the history
  • Loading branch information
rhilliges committed Dec 10, 2024
1 parent 02fc1d6 commit a24cb40
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
29 changes: 18 additions & 11 deletions lua/neotest-jdtls/testng/reports/testng.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,27 @@ end
function TestNGReport:get_stream_reader(conn)
self.conn = conn
self.result_parser = self.result_parser_fac:get_parser()
return vim.schedule_wrap(function(err, buffer)
if err then
self.conn:close()
return
end

if buffer then
self:on_update(buffer)
else
self.conn:close()
self.result_parser = self.result_parser_fac:get_parser()
local buffer_loop = function ()
local buffer = ""
return function(err, chunk)
if err then
self.conn:close()
return
end

if chunk then
buffer = buffer .. chunk
else
self:on_update(buffer)
self.conn:close()
end
end
end)
end
return vim.schedule_wrap(buffer_loop())
end


---Runs on connection update
---@private
---@param text string
Expand Down
27 changes: 20 additions & 7 deletions lua/neotest-jdtls/testng/results/result-parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,44 +32,57 @@ local function parse(content)
local test = vim.json.decode(line)
if test.name ~= 'testStarted' then
return test
-- table.insert(tests, test)
end
return nil
end
end
return nil
end

---Parse a given text into test details
---@param text string test result buffer
function TestParser:parse(text)
local parsedResult = parse(text)
if parsedResult == nil then
log.info("Could not parse result.", text)
return;
end
local testName = parsedResult["attributes"]["name"]
local test = vim.split(testName, "#")
local testPathElements = vim.split(test[1], "%.")
local testFile = testPathElements[#testPathElements]
local testMethodName = test[2]:sub(1,-3)
local testId = test[1]:gsub("%.","/") .. ".java::" .. testFile .. "::" .. testMethodName
testId = vim.fn.getcwd() .. "/src/test/java/" .. testId
local testId = vim.fn.expand("src/**/" .. test[1]:gsub("%.","/") .. ".java")
testId = vim.fn.getcwd() .. "/" .. testId .. "::" .. testFile .. "::" .. testMethodName

local status = parsedResult["name"]
local repl = require('dap.repl')
if status == 'testFailed' then
local msg = parsedResult["attributes"]["message"] or 'test failed'
local trace = parsedResult["attributes"]["trace"]
self.test_details.results[testId] = {
status = "failed",
short = parsedResult["attributes"]["message"],
short = msg,
errors = {
{
message = parsedResult["attributes"]["trace"],
message = trace,
}
},
}
if repl ~= nil then
repl.append('' .. testName .. ' failed')
repl.append(msg)
repl.append(trace)
end
elseif status == 'testFinished' then
self.test_details.results[testId] = {
status = "passed",
}
if repl ~= nil then
repl.append('' .. testName .. ' passed')
end
else
log.warn("Unknown test status: ", parsedResult["name"])
end
log.warn("Unknown test status: ", parsedResult["name"])
end

return TestParser
Expand Down

0 comments on commit a24cb40

Please sign in to comment.