Skip to content
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

fix: add resources for junit command #156

Merged
merged 2 commits into from
Oct 7, 2024
Merged
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
21 changes: 16 additions & 5 deletions lua/neotest-java/command/jdtls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ M.get_java_home = function()
return java_exec[setting]
end

M.get_classpath = function()
---@param additional_classpath_entries string[]
M.get_classpath = function(additional_classpath_entries)
additional_classpath_entries = additional_classpath_entries or {}

local classpaths = {}

local bufnr = vim.api.nvim_get_current_buf()
local uri = vim.uri_from_bufnr(bufnr)
local runtime_classpath_future = nio.control.future()
Expand All @@ -46,15 +51,21 @@ M.get_classpath = function()
local runtime_classpaths = runtime_classpath_future.wait()
local test_classpaths = test_classpath_future.wait()

for _, v in ipairs(additional_classpath_entries) do
classpaths[#classpaths + 1] = v
end
for _, v in ipairs(runtime_classpaths) do
classpaths[#classpaths + 1] = v
end
for _, v in ipairs(test_classpaths) do
runtime_classpaths[#runtime_classpaths + 1] = v
classpaths[#classpaths + 1] = v
end

return runtime_classpaths
return classpaths
end

M.get_classpath_file_argument = function(report_dir)
local classpath = table.concat(M.get_classpath(), ":")
M.get_classpath_file_argument = function(report_dir, additional_classpath_entries)
local classpath = table.concat(M.get_classpath(additional_classpath_entries), ":")
local temp_file = compatible_path(report_dir .. "/.cp")
write_file(temp_file, ("-cp %s"):format(classpath))

Expand Down
8 changes: 7 additions & 1 deletion lua/neotest-java/command/junit_command_builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local binaries = require("neotest-java.command.binaries")
local java = binaries.java
local logger = require("neotest-java.logger")
local jdtls = require("neotest-java.command.jdtls")
local scan = require("plenary.scandir")

--- @class CommandBuilder
local CommandBuilder = {
Expand Down Expand Up @@ -98,13 +99,18 @@ local CommandBuilder = {
end
assert(#selectors ~= 0, "junit command has to have a selector")

local resources = scan.scan_dir(self._basedir, {
only_dirs = true,
search_pattern = "test/resources$",
})

local junit_command = {
command = java(),
args = {
"-jar",
self._junit_jar,
"execute",
("%s"):format(jdtls.get_classpath_file_argument(self._reports_dir)),
("%s"):format(jdtls.get_classpath_file_argument(self._reports_dir, resources)),
"--reports-dir=" .. self._reports_dir,
"--fail-if-no-tests",
"--disable-banner",
Expand Down