ctest complains about the test executable, but then deletes it?

Daniel Griscom
Tue, 12 Mar 2024 13:07:32 +0000
Usage

I’m taking over some code and trying to use it in a cross-platform compilation environment (building on Linux/x86, compiling to ARM). However, when I try to run the tests, ctest complains about the built executable and then immediately deletes it, making it awfully difficult to figure out what’s going wrong. (It’s likely being built for ARM and then run on x86, but I can’t tell.)

How can I keep cmake/ctest from deleting the executable?

Here’s what happens:

griscom@nob:~/git/nodes/_build$ ../run-docker make exmymod_tests
----snip----
[100%] Linking CXX executable exmymod_tests
/home/griscom/git/nodes/_build/MyCore/modules/mymod/exmymod_tests: 1: Syntax error: word unexpected (expecting ")")
CMake Error at /home/griscom/git/nodes/_build/_deps/catch2-src/extras/CatchAddTests.cmake:70 (message):
  Error running test executable
  '/home/griscom/git/nodes/_build/MyCore/modules/mymod/exmymod_tests':


    Result: 2
    Output:

Call Stack (most recent call first):
  /home/griscom/git/nodes/_build/_deps/catch2-src/extras/CatchAddTests.cmake:175 (catch_discover_tests_impl)


make[3]: *** [MyCore/modules/mymod/CMakeFiles/exmymod_tests.dir/build.make:113: MyCore/modules/mymod/exmymod_tests] Error 1
make[3]: *** Deleting file 'MyCore/modules/mymod/exmymod_tests'
make[2]: *** [CMakeFiles/Makefile2:3734: MyCore/modules/mymod/CMakeFiles/exmymod_tests.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:3741: MyCore/modules/mymod/CMakeFiles/exmymod_tests.dir/rule] Error 2
make: *** [Makefile:1226: exmymod_tests] Error 2
Cleaning up

Here’s the relevant section of the CMakeLists.txt:

# Add some tests
# temporary hack to get a properly functioning catch
Include(FetchContent)
FetchContent_Declare(
        Catch2
        GIT_REPOSITORY https://github.com/catchorg/Catch2.git
        GIT_TAG        v3.4.0
)

FetchContent_MakeAvailable(Catch2)
#-------------------------- end of temporary hack

include(Catch)

add_executable(${PROJECT_NAME}_tests unittests/utilTests.cpp)
target_include_directories(${PROJECT_NAME}_tests PRIVATE src)
#target_sources(${PROJECT_NAME}_tests PRIVATE src/myMod.cpp)
target_link_libraries(${PROJECT_NAME}_tests
        PUBLIC
        ${TGT_LINK_LIBS}
        MyCore::${GENERATED_LIBRARY_TARGET}
        MyCore::exnewlogger
        Catch2::Catch2WithMain
)
catch_discover_tests(${PROJECT_NAME}_tests)

9 posts - 3 participants