66 lines
1.9 KiB
Lua
66 lines
1.9 KiB
Lua
local lib = require("neotest.lib")
|
|
|
|
local has_cpp_parser = false
|
|
local ok_parsers, parsers = pcall(require, "nvim-treesitter.parsers")
|
|
if ok_parsers and parsers.has_parser then
|
|
has_cpp_parser = parsers.has_parser("cpp")
|
|
end
|
|
|
|
if not has_cpp_parser then
|
|
vim.schedule(function()
|
|
vim.notify(
|
|
"neotest-gtest needs Treesitter cpp parser. Run :TSInstall cpp",
|
|
vim.log.levels.WARN
|
|
)
|
|
end)
|
|
return
|
|
end
|
|
|
|
require("neotest").setup({
|
|
adapters = {
|
|
require("neotest-gtest").setup({
|
|
root = lib.files.match_root_pattern(
|
|
"CMakeLists.txt",
|
|
".git"
|
|
),
|
|
debug_adapter = "codelldb",
|
|
is_test_file = function(file)
|
|
local normalized = file:gsub("\\", "/")
|
|
local is_in_tests_dir = normalized:match("/tests/") ~= nil
|
|
local has_test_suffix = normalized:match("_test%.cpp$")
|
|
or normalized:match("_test%.cc$")
|
|
or normalized:match("_test%.cxx$")
|
|
or normalized:match("_test%.c%+%+$")
|
|
|
|
return is_in_tests_dir and has_test_suffix ~= nil
|
|
end,
|
|
filter_dir = function(name, rel_path)
|
|
if rel_path == "" then
|
|
return true
|
|
end
|
|
|
|
local blocked = {
|
|
[".git"] = true,
|
|
[".cache"] = true,
|
|
["build"] = true,
|
|
["out"] = true,
|
|
["_deps"] = true,
|
|
}
|
|
|
|
if blocked[name] then
|
|
return false
|
|
end
|
|
|
|
if rel_path:match("^build/") or rel_path:match("^out/") then
|
|
return false
|
|
end
|
|
|
|
return true
|
|
end,
|
|
mappings = {
|
|
configure = "C",
|
|
},
|
|
}),
|
|
},
|
|
})
|