bneumann / CppUTest-Test-Adapter

A test adapter for Visual Studio Code for the C/C++ Unit Test framework CppUTest.
MIT License
16 stars 8 forks source link

Getting test runner working with Linux and CMake #59

Open tank104 opened 2 months ago

tank104 commented 2 months ago

Hi, I am trying to get this test runner working on Linux (WSL to be precise) and we use CMake.

To do the build I do:

cd {projectpath}\build\cpputests_tests cmake ../../ make

and that runs the build and tests.

I can't see any .exe file (as on linux), and don't even know where the runner would go.

Test source code is in:

{projectpath}\tests\cpputest

CMakeLists.txt looks like:


# (1) Look for installed version of CppUTest
if(DEFINED ENV{CPPUTEST_HOME})
    message(STATUS "Using CppUTest home: $ENV{CPPUTEST_HOME}")
    set(CPPUTEST_INCLUDE_DIRS $ENV{CPPUTEST_HOME}/include)
    set(CPPUTEST_LIBRARIES $ENV{CPPUTEST_HOME}/lib)
    set(CPPUTEST_LDFLAGS CppUTest CppUTestExt)
else()
    find_package(PkgConfig REQUIRED)
    pkg_search_module(CPPUTEST REQUIRED cpputest>=3.8)
    message(STATUS "Found CppUTest version ${CPPUTEST_VERSION}")
endif()

# (2) Our unit tests sources
set(TEST_APP_NAME ${APP_NAME}_tests)
set(TEST_SOURCES
    ../mocks/ActivityMock.cpp
    ../mocks/ChoreMock.cpp
    ../mocks/FriendMock.cpp
    ../mocks/MessageMock.cpp
    ../mocks/PocketMoneyMock.cpp
    ./common/DeviceSummaryTest.cpp
    main.cpp
)

# (3) Take care of include directories
include_directories(${CPPUTEST_INCLUDE_DIRS} 
    ../../src/common
    ../../include
)
link_directories(${CPPUTEST_LIBRARIES})

# (4) Build the unit tests objects and link then with the app library
add_executable(${TEST_APP_NAME} ${TEST_SOURCES})
target_link_libraries(${TEST_APP_NAME} ${APP_LIB_NAME} ${CPPUTEST_LDFLAGS})

# (5) Run the test once the build is done
add_custom_command(TARGET ${TEST_APP_NAME} COMMAND ./${TEST_APP_NAME} POST_BUILD)
tank104 commented 2 months ago

Just to add the below:

add_custom_command(TARGET ${TEST_APP_NAME} COMMAND ./${TEST_APP_NAME} POST_BUILD)

seems to delete the "exe" after it runs. If I disable that step for now then I get an "exe" called "esp32_withtestsApp_tests" in "build\cpputests_tests\tests\cpputest"

However tried various combinations for Test Executable: "${workspaceFolder}\build\cpputests_tests\tests\cpputest\esp32_withtestsApp_tests" and Text Executable Path: "${workspaceFolder}\build\cpputests_tests\tests\cpputest"

without any luck )still get "ERROR LOADING TESTS"

bneumann commented 1 month ago

Hey, I removed the check for ".exe" under windows in the last version. Can you see if you get it to run?

tank104 commented 1 month ago

Unfortunately I can't see the runner at all now - not sure if related to : https://github.com/bneumann/CppUTest-Test-Adapter/issues/65

Basically what I used to see was (v1.3.4):

cpputest1 3 4

For each later version I see (basically it looks like missing):

image

In your logs I see:

[2024-10-07 20:38:09.967] [INFO] Test Explorer found [2024-10-07 20:38:09.967] [INFO] Creating adapter for /home/tank104/git/FamilyHub/Device [2024-10-07 20:38:09.967] [INFO] Initializing adapter [2024-10-07 20:38:09.967] [INFO] Registering adapter for /home/tank104/git/FamilyHub/Device [2024-10-07 20:38:09.975] [INFO] Loading tests [2024-10-07 20:38:09.975] [INFO] Initialization finished [2024-10-07 20:38:15.664] [INFO] replacing config variabe "${workspaceFolder}\build\cpputests_tests\tests\cpputest\FamilyHub_Device_Cpputest_Tests_tests" [2024-10-07 20:38:15.664] [INFO] replaced variable is now "/home/tank104/git/FamilyHub/Device\build\cpputests_tests\tests\cpputest\FamilyHub_Device_Cpputest_Tests_tests" [2024-10-07 20:38:15.678] [INFO] Tests loaded

bneumann commented 1 month ago

Okay thanks. I have a hunch that the backslashes are the culprit here. Can you replace your test executable path with: ${workspaceFolder}/build/cpputests_tests/tests/cpputest/FamilyHub_Device_Cpputest_Tests_tests ? It looks like you are working under WSL or linux, so backslashes are generally a bad idea.