Git Product home page Git Product logo

ctest-telescope.nvim's Introduction

ctest-telescope

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.

Motivation

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.

Installation

Install ctest-telescope with your preferred package manager:

Lazy:

{
    "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.

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",
},

Example configuration to enable pretty-printing and stopAtEntry

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,
      },
    },
  },
})

Usage

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" })

Troubleshooting

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.

Alternatives

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.

ctest-telescope.nvim's People

Contributors

sgauvin avatar

Stargazers

 avatar Yuta Katayama avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.