Skip to content
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
4 changes: 4 additions & 0 deletions lua/neotest-java/core/file_checker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ local FileChecker = function(dependencies)
local my_path = Path(file_path)
local base_dir = dependencies.root_getter()

if not base_dir then
return false
end

local relative_path = my_path:make_relative(base_dir)
if relative_path:contains("main") then
return false
Expand Down
2 changes: 2 additions & 0 deletions lua/neotest-java/core/root_finder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function RootFinder.find_root(dir, matcher)
"pom.xml",
"settings.gradle",
"settings.gradle.kts",
"build.gradle",
"build.gradle.kts",
".git",
}

Expand Down
11 changes: 11 additions & 0 deletions tests/unit/file_checker_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,15 @@ describe("file_checker", function()
}).is_test_file(file_path))
end
end)

it("should return false when root_getter returns nil", function()
local file_checker = FileChecker({
patterns = patterns,
root_getter = function()
return nil
end,
})

assert.is_false(file_checker.is_test_file("/any/path/Test.java"))
end)
end)
19 changes: 19 additions & 0 deletions tests/unit/root_finder_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,23 @@ describe("RootFinder", function()
-- then
assert.is_nil(actualRoot)
end)

it("should find build.gradle before .git for single-module Gradle projects", function()
local patterns_checked = {}
local matcher = function(pattern)
table.insert(patterns_checked, pattern)
return function(_)
if pattern == "build.gradle" then
return "/path/to/project"
end
return nil
end
end

local root = root_finder.find_root("/some/dir", matcher)

assert.are.same("/path/to/project", root)
assert.is_true(patterns_checked[#patterns_checked] == "build.gradle")
assert.is_true(patterns_checked[#patterns_checked - 1] ~= ".git")
end)
end)