orjangj / neotest-ctest

A neotest adapter for C/C++ using CTest as a test runner. Supports GoogleTest, Catch2 and doctest test frameworks.
MIT License
8 stars 4 forks source link

ctest --tests-information produces error #25

Closed pcorbineau closed 4 months ago

pcorbineau commented 5 months ago

on my setup, Windows : 11 cmake : 3.28 neovim : 0.10.0

I found that line : local filter = string.format("-I 0,0,0,%s", table.concat(runnable_tests, ","))

produces an error from command line.

Indeed, If i test the command produces ( I remove the output args) ,I got :

#  ctest --test-dir D:\personal\workspace\test-sandbox\build\Debug -I 0,0,0,
Internal ctest changing into directory: D:/personal/workspace/test-sandbox/build/Debug
Test project D:/personal/workspace/test-sandbox/build/Debug
No tests were found!!!

if I remove the -I option it works :

#  ctest --test-dir D:\personal\workspace\test-sandbox\build\Debug
Internal ctest changing into directory: D:/personal/workspace/test-sandbox/build/Debug
Test project D:/personal/workspace/test-sandbox/build/Debug
    Start 1: lib.add_one
1/2 Test #1: lib.add_one ......................   Passed    0.01 sec
    Start 2: lib.failed
2/2 Test #2: lib.failed .......................***Failed    0.01 sec

50% tests passed, 1 tests failed out of 2

Total Test time (real) =   0.04 sec

The following tests FAILED:
          2 - lib.failed (Failed)
Errors while running CTest
Output from these tests are in: D:/personal/workspace/test-sandbox/build/Debug/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.
pcorbineau commented 5 months ago

As a temporary solution I removed this line.

diff --git a/lua/neotest-ctest/init.lua b/lua/neotest-ctest/init.lua
index d7226b8..205f28c 100644
--- a/lua/neotest-ctest/init.lua
+++ b/lua/neotest-ctest/init.lua
@@ -62,11 +62,9 @@ function adapter.build_spec(args)
   -- NOTE: The '-I Start,End,Stride,test#,test#,...' option runs the specified tests in the
   -- range starting from number Start, ending at number End, incremented by number Stride.
   -- If Start, End and Stride are set to 0, then CTest will run all test# as specified.
-  local filter = string.format("-I 0,0,0,%s", table.concat(runnable_tests, ","))

   local extra_args = config.extra_args or {}
   vim.list_extend(extra_args, args.extra_args or {})
-  local ctest_args = { filter, table.concat(extra_args, " ") }

   local command = ctest:command(ctest_args)
   local framework = require("neotest-ctest.framework").detect(position.path)
@@ -78,6 +76,8 @@ function adapter.build_spec(args)
       framework = framework,
     },
   }
+    -- local filter = string.format("-I 0,0,0,%s", table.concat(runnable_tests, ","))
+    local ctest_args = { table.concat(extra_args, " ") }
 end

 local function prepare_results(tree, testsuite, framework)
orjangj commented 5 months ago

Hi. Could you have a look at my comment in #24? I think this issue is related to the fix you provided in #24. If this is the case, then we can close this issue. Removing the --tests-information option shouldn't be necessary as long as ctest is running in the right build/binary tree.

orjangj commented 5 months ago

FYI, this command: ctest --test-dir D:\personal\workspace\test-sandbox\build\Debug -I 0,0,0, won't run any tests because it doesn't specify any test numbers/indexes to run.

I'm pretty sure you would see a different result if you run: ctest --test-dir D:\personal\workspace\test-sandbox\build\Debug -I 0,0,0,1,2 (which is the filter that neotest-ctest should have produced if it found runnable tests to execute).

orjangj commented 4 months ago

Should be fixed as part of #24 now.