Civitasv / cmake-tools.nvim

CMake integration in Neovim
GNU General Public License v3.0
380 stars 68 forks source link

neotest-ctest adapter #241

Open orjangj opened 5 months ago

orjangj commented 5 months ago

First of all, I want to thank you for making this plugin. I've been using it for quite some time now and it works like a charm so far.

Anyway, I found this issue https://github.com/Civitasv/cmake-tools.nvim/issues/68 and I noticed that neotest was brought up in the discussion.

I have written a neotest adapter for C/C++ using CTest as a test runner. You can find it here: https://github.com/orjangj/neotest-ctest. It currently supports basic test macros from both GoogleTest (TEST, TEST_F) and Catch2 (TEST_CASE, TEST_CASE_METHOD, SCENARIO). I plan to add support parameterized tests (if possible) and add support for more test frameworks as well.

I'm not sure where to take it from here, but I figured you might want to have a look at it and maybe reference it in the README?

Let me know what you think. If not, you can just close this issue :)

Civitasv commented 5 months ago

I think this is very interesting! Currently, we parse all tests using ctest command and no other dependencies, lacking some features. But I'm not familiar with neotest, to my understanding now, I think it's like a middleware which provides unified API to support multiple test framework, right?

orjangj commented 4 months ago

Yes, in short neotest provides a unified API and UI to run tests, while neotest adapters will take care of constructing commands to run tests in addition to parsing test results. One of the things that makes neotest such a great plugin is that you can use it for many different languages/frameworks (provided there is an adapter available) and that you get feedback on passing/failing test in the sign column. Neotest can also display test output (parsed by adapters) in a floating window, show errors through nvim's diagnostics (if supported by the adapter), and more.

neotest-ctest bridges neotest, ctest and a few supported C/C++ test frameworks. neotest-ctest is primarily limited by its ability to parse test cases through treesitter (which determines how neotest knows what tests you want to run). There's bound to be some shortcomings here considering that building treesitter queries can be quite challenging for some of the test case macros (especially parameterized tests). After that, the adapter will simply query ctest for runnable tests and build the appropriate ctest command(s) to run a single test case, all tests in a file or all tests in a directory/workspace depending on how you invoked neotest's API.

neotest-ctest does not manage cmake based projects or compile tests, which is why I've recommended cmake-tools.nvim as a companion plugin in my readme :)

mjrogozinski commented 3 months ago

I was looking for a plugin like this one. In the project with multiple test binaries, I would like to be able to say "run this test" and only the test binary (CMake target) containing the test would be rebuilt.

Integration of CMake with testing frameworks is needed. Thank you for your work.