Skip to content

Commit

Permalink
feat: handle filter_dir,is_test_file functions with jdtls
Browse files Browse the repository at this point in the history
delete all nvim-java dependency
add project cache support
  • Loading branch information
atm1020 committed Aug 5, 2024
1 parent 5485396 commit 25438fe
Show file tree
Hide file tree
Showing 26 changed files with 1,002 additions and 347 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ TEST_CONFIG=${TESTS_DIR}/minimal_init.lua

.PHONY: test lint format all

all: lint format test
all: lint format

test:
nvim --headless -c "PlenaryBustedDirectory ${TESTS_DIR} {minimal_init = '${TEST_CONFIG}'}"
nvim --headless -c "PlenaryBustedDirectory {minimal_init = '${TEST_CONFIG}'}"
lint:
luacheck ${SRC_DIR} ${TESTS_DIR}
luacheck ${SRC_DIR}

format:
stylua ${SRC_DIR} ${TESTS_DIR} --config-path=.stylua.toml
~/.cargo/bin//stylua ${SRC_DIR} --config-path=.stylua.toml
38 changes: 0 additions & 38 deletions lua/neotest-jdtls/impl/filter_dir.lua

This file was deleted.

11 changes: 0 additions & 11 deletions lua/neotest-jdtls/impl/is_test_file.lua

This file was deleted.

13 changes: 0 additions & 13 deletions lua/neotest-jdtls/impl/root.lua

This file was deleted.

73 changes: 14 additions & 59 deletions lua/neotest-jdtls/init.lua
Original file line number Diff line number Diff line change
@@ -1,63 +1,18 @@
local adapter = {}
---@class neotest.Adapter
---@field name string
adapter.Adapter = { name = 'neotest-jdtls' }
local adapter = require('neotest-jdtls.neotest.adapter')
local project = require('neotest-jdtls.utils.project')

---Find the project root directory given a current directory to work from.
---Should no root be found, the adapter can still be used in a non-project context if a test file matches.
---@async
---@param dir string @Directory to treat as cwd
---@return string | nil @Absolute root dir of test suite
function adapter.Adapter.root(dir)
return require('neotest-jdtls.impl.root').root(dir)
end
local group = vim.api.nvim_create_augroup('neotest-jdtls', { clear = true })

---Filter directories when searching for test files
---@async
---@param name string Name of directory
---@param rel_path string Path to directory, relative to root
---@param root string Root directory of project
---@return boolean
function adapter.Adapter.filter_dir(name, rel_path, root)
return require('neotest-jdtls.impl.filter_dir').filter_dir(
name,
rel_path,
root
)
end
vim.api.nvim_create_autocmd({ 'BufWritePost' }, {
pattern = '*.java',
callback = project.autocmd_clear_cache,
group = group,
})

---@async
---@param file_path string
---@return boolean
function adapter.Adapter.is_test_file(file_path)
local is_test_file =
require('neotest-jdtls.impl.is_test_file').is_test_file(file_path)
return is_test_file
end
vim.api.nvim_create_user_command(
'NeotestJdtlsClearProjectCache',
project.clear_project_cache,
{}
)

---Given a file path, parse all the tests within it.
---@async
---@param file_path string Absolute file path
---@return neotest.Tree | nil
function adapter.Adapter.discover_positions(file_path)
return require('neotest-jdtls.impl.discover_positions').discover_positions(
file_path
)
end

---@param args neotest.RunArgs
---@return neotest.RunSpec
function adapter.Adapter.build_spec(args)
return require('neotest-jdtls.impl.excute').build_spec(args)
end

---@async
---@param spec neotest.RunSpec
---@param result neotest.StrategyResult
---@param tree neotest.Tree
---@return table<string, neotest.Result>
function adapter.Adapter.results(spec, result, tree)
return require('neotest-jdtls.impl.results').results(spec, result, tree)
end

return adapter.Adapter
return adapter
51 changes: 51 additions & 0 deletions lua/neotest-jdtls/junit/reports/junit.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
local class = require('neotest-jdtls.utils.class')
local log = require('neotest-jdtls.utils.log')
local ResultParserFactory =
require('neotest-jdtls.junit.results.result-parser-factory')

---@class java_test.JUnitTestReport
---@field private conn uv_tcp_t
---@field private result_parser java_test.TestParser
---@field private result_parser_fac java_test.TestParserFactory
local JUnitReport = class()

function JUnitReport:_init()
self.conn = nil
self.result_parser_fac = ResultParserFactory()
end

---Returns the test results
---@return java_test.TestResults[]
function JUnitReport:get_results()
return self.result_parser:get_test_details()
end

---Returns a stream reader function
---@param conn uv_tcp_t
---@return fun(err: string, buffer: string) # callback function
function JUnitReport: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()
end
end)
end

---Runs on connection update
---@private
---@param text string
function JUnitReport:on_update(text)
log.trace('on_update', text)
self.result_parser:parse(text)
end

return JUnitReport
7 changes: 7 additions & 0 deletions lua/neotest-jdtls/junit/results/execution-status.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---@enum java_test.TestExecutionStatus
local TestStatus = {
Started = 'started',
Ended = 'ended',
}

return TestStatus
30 changes: 30 additions & 0 deletions lua/neotest-jdtls/junit/results/message-id.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---@enum MessageId
local MessageId = {
-- Notification about a test inside the test suite.
-- TEST_TREE + testId + "," + testName + "," + isSuite + "," + testCount + "," + isDynamicTest +
-- "," + parentId + "," + displayName + "," + parameterTypes + "," + uniqueId

-- isSuite = "true" or "false"
-- isDynamicTest = "true" or "false"
-- parentId = the unique id of its parent if it is a dynamic test, otherwise can be "-1"
-- displayName = the display name of the test
-- parameterTypes = comma-separated list of method parameter types if applicable, otherwise an
-- empty string
-- uniqueId = the unique ID of the test provided by JUnit launcher, otherwise an empty string

TestTree = '%TSTTREE',
TestStart = '%TESTS',
TestEnd = '%TESTE',
TestFailed = '%FAILED',
TestError = '%ERROR',
ExpectStart = '%EXPECTS',
ExpectEnd = '%EXPECTE',
ActualStart = '%ACTUALS',
ActualEnd = '%ACTUALE',
TraceStart = '%TRACES',
TraceEnd = '%TRACEE',
IGNORE_TEST_PREFIX = '@Ignore: ',
ASSUMPTION_FAILED_TEST_PREFIX = '@AssumptionFailure: ',
}

return MessageId
14 changes: 14 additions & 0 deletions lua/neotest-jdtls/junit/results/result-parser-factory.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
local class = require('neotest-jdtls.utils.class')
local TestParser = require('neotest-jdtls.junit.results.result-parser')

---@class java_test.TestParserFactory
local TestParserFactory = class()

---Returns a test parser of given type
---@param args any
---@return java_test.TestParser
function TestParserFactory.get_parser(_args)
return TestParser()
end

return TestParserFactory
Loading

0 comments on commit 25438fe

Please sign in to comment.