ctest-telescope
is a simple plugin that integrates with CTest to allows you to fuzzy find your tests with telescope
and debug them via nvim-dap
.
If you are looking for a simple solution to run C++ tests with nvim-dap
through ctest
without having to manually specify an executable path, arguments, and the working directory, this plugin might be for you.
Install ctest-telescope
with your preferred package manager:
{
"SGauvin/ctest-telescope.nvim",
opts = {
-- Your config
}
}
You also must have ctest
installed on your local machine. If ctest
isn't available in your PATH, you can specify a path in the configuration.
ctest-telescope
comes with the following defaults:
{
-- Path to the ctest executable
ctest_path = "ctest",
-- Folder where your compiled executables will be found
build_folder = "build",
-- Configuration you would pass to require("dap").configurations.cpp
dap_config = {
type = "cppdbg",
request = "launch",
},
}
You can set the dap_config
field to specify parameters you want pass to dap
.
If you specify program
, cwd
, or args
, they will be overridden (since the goal of this plugin is to select those automatically).
You can learn more about what fields are available for cppdbg here.
It should be possible to override cppdbg
with codelldb
or any other debug adapter that works with C++, but this hasn't been tested yet:
dap_config = {
type = "codelldb",
},
Note: If you are using lazy.nvim
, you should pass these options to opts
(example) instead of explicitly passing them to setup
.
require("ctest-telescope").setup({
dap_config = {
stopAtEntry = true,
setupCommands = {
{
text = "-enable-pretty-printing",
description = "Enable pretty printing",
ignoreFailures = false,
},
},
},
})
ctest-telescope
exports one useful function: pick_test_and_debug
.
Here is an example on how you could integrate this in your own config:
vim.keymap.set("n", "<F5>", function()
local dap = require("dap")
if dap.session() == nil then
-- Only call this on C++ and C files
if vim.bo.filetype == "c" or vim.bo.filetype == "cpp" then
require("ctest-telescope").pick_test_and_debug()
end
else
dap.continue()
end
end, { desc = "Debug: Start/Continue" })
If this plugin isn't working for you, try running this in your terminal: ctest --test-dir <build_folder> --show-only=json-v1
.
Make sure your CMakeLists.txt
is set up properly with automatic tests registration.
For gtest, gtest_discover_tests
has to be used.
For catch2, catch_discover_tests
has to be used.
If this plugin still isn't working, feel free to make an issue or a pull request.
If you use only gtest, don't mind having to manually specify an executable, and don't mind a bit more configuration, you might want to try neotest-gtest, as it integrates with neotest.
If you're looking for a plugin that fully integrates CMake in Neovim, you might want to check out cmake-tools.nvim.