Skip to content

feat: integrate with jacoco and nvim-coverage #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lua/neotest-java/command/junit_command_builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,14 @@ local CommandBuilder = {
end
assert(#selectors ~= 0, "junit command has to have a selector")

--TODO: put this in config
local jacoco_jar = "/home/rcasia/Downloads/org.jacoco.agent-0.8.9-runtime.jar"
local jacoco_output = "/home/rcasia/jacoco.exe"

local junit_command = {
command = java(),
args = {
("-javaagent:%s=output=file,destfile=%s,append=false"):format(jacoco_jar, jacoco_output),
"-jar",
self._junit_jar,
"execute",
Expand Down
13 changes: 13 additions & 0 deletions lua/neotest-java/core/result_builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ local log = require("neotest-java.logger")
local scan = require("plenary.scandir")
local lib = require("neotest.lib")
local JunitResult = require("neotest-java.types.junit_result")
local Path = require("plenary.path")
local nio = require("nio")
local SKIPPED = JunitResult.SKIPPED

local REPORT_FILE_NAMES_PATTERN = "TEST-.+%.xml$"
Expand Down Expand Up @@ -73,6 +75,17 @@ function ResultBuilder.build_results(spec, result, tree) -- luacheck: ignore 212
spec.context.terminated_command_event.wait()
end

local coverage_file = Path:new("/home/rcasia/jacoco.exe")
local jacoco_cli = "/home/rcasia/Downloads/org.jacoco.cli-0.8.9-nodeps.jar"
local coverage_output = "/home/rcasia/jacoco.xml"
local classfiles = "target/neotest-java/classes"
if coverage_file:exists() then
vim.system(({"java", "-jar", jacoco_cli, "report", coverage_file.filename, "--xml", coverage_output, "--classfiles", classfiles})):wait()
end

require('coverage').load(true)
require('coverage').summary()

---@type table<string, neotest.Result>
local results = {}

Expand Down
Loading