Skip to content

Commit

Permalink
fix: modify test result key
Browse files Browse the repository at this point in the history
  • Loading branch information
atm1020 committed Nov 24, 2024
1 parent a0e7cd5 commit 06562c9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# neotest-jdtls
* This plugin provides a jdtls adapter for the [Neotest](https://github.com/rcarriga/neotest) framework.
* Only supports Junit5 tests.

### Installation

Expand All @@ -21,9 +22,12 @@ require("neotest").setup {


```

### Logging
- logs are written to `neotest-jdtls.log` within the `~/.local/share/nvim/` directory.
- log level can be set with `vim.g.neotest_jdtls_log_level`.



### Acknowledgements
- **[neotest-java](https://github.com/rcasia/neotest-java)**
33 changes: 28 additions & 5 deletions lua/neotest-jdtls/neotest/impl/results.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,31 @@ local function map_to_neotest_result_item(item)
end
end

local function get_test_key_from_junit_result(test_name)
-- test_name format: "function_name(package.name.ClassName)"
log.debug('get_test_key_from_junit_result input:', test_name)
local function_name = test_name:match('^(.+)%(') -- Extract "function_name"
local class_name = test_name:match('%.([%w$]+)%)$') -- Extract "ClassName"

assert(function_name, 'function name not found')
assert(class_name, 'class name not found')
local key = class_name .. '::' .. function_name
log.debug('get_test_key_from_junit_result output:', key)
return key
end

local function get_test_key_from_neotest_id(test_id)
-- test_id format: "/path/to/file::class_name::function_name"
log.debug('get_test_key_from_neotest_id input:', test_id)
local key = test_id:match('::(.+)$')
log.debug('get_test_key_from_neotest_id output:', key)
return key
end

local function group_and_map_test_results(test_result_lookup, suite)
for _, ch in ipairs(suite.children) do
local key = vim.split(ch.test_name, '%(')[1]
if not ch.is_suite then
local key = get_test_key_from_junit_result(ch.test_name)
if test_result_lookup[key] == nil then
test_result_lookup[key] = {}
end
Expand All @@ -80,7 +101,9 @@ local function group_and_map_test_results(test_result_lookup, suite)
end

local function merge_neotest_results(test_result_lookup, node_data)
if test_result_lookup[node_data.name] == nil then
log.debug('Before|Merging test results', vim.inspect(node_data))
local key = get_test_key_from_neotest_id(node_data.id)
if test_result_lookup[key] == nil then
local root = jdtls.root_dir()
nio.scheduler()
local current = project.get_current_project()
Expand All @@ -95,14 +118,14 @@ local function merge_neotest_results(test_result_lookup, node_data)
return nil
end

if #test_result_lookup[node_data.name] == 1 then
return test_result_lookup[node_data.name][1]
if #test_result_lookup[key] == 1 then
return test_result_lookup[key][1]
end

local dynamic_test_result = {
status = TestStatus.Passed,
}
for _, result in ipairs(test_result_lookup[node_data.name]) do
for _, result in ipairs(test_result_lookup[key]) do
-- TODO merge stack traces
if result.status == TestStatus.Failed then
dynamic_test_result.status = TestStatus.Failed
Expand Down

0 comments on commit 06562c9

Please sign in to comment.