Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting test runner working with Linux and CMake #59

Open
tank104 opened this issue Sep 2, 2024 · 4 comments
Open

Getting test runner working with Linux and CMake #59

tank104 opened this issue Sep 2, 2024 · 4 comments

Comments

@tank104
Copy link

tank104 commented Sep 2, 2024

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
Copy link
Author

tank104 commented Sep 2, 2024

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
Copy link
Owner

bneumann commented Oct 7, 2024

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

@tank104
Copy link
Author

tank104 commented Oct 7, 2024

Unfortunately I can't see the runner at all now - not sure if related to : #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
Copy link
Owner

bneumann commented Oct 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants