When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
20 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
most likely because you are not supposed to have your own main while using gtest
what actual code?
the std::cout << "whatever" line?
if you for some reason need to have a custom main then you need to not link with gtest_main and then have a main similar to this ```cpp
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
// your code
return RUN_ALL_TESTS();
}
but tbh I dont understand why would you want that
because each of the tests still need to be independent of each other (well not really but they should be)
Don't you run ctest after build?
That's what I do.
I don't see any add_test() in your CMake files either.
I could be reading stuff too fast (while trying to work) but from experience..
You have a CMakeLists.txt that builds the actual unit.
This has the option to enable testing.
If that option is selected, then you call enable_testing() and you call add_subdirectory() for the subdir where the CMakeLists.txt for the tests lives.
On speedy glance, that is what you are doing. 👍
In the CMakeLists.txt in this subdir you will create many targets (is project()). One for each test.
Each test in this CMakeLists.txt will be something along the lines of
project(test-zig LANGUAGES CXX)
message(STATUS "adding test: test-zig")
add_test(NAME zig COMMAND test-zig WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX})
add_executable(test-zig
test-zig.cpp
test-zig.h
)
target_link_libraries(test-zig PRIVATE {dependencies})
// repeat the above for other tests
You should not need to call enable_testing() again from this CMakeLists.txt.
But tests run in seperate processes, so each would have its own main()?
Maybe you're doing stuff differently, and all I am achieving is confusing matters.
I'll butt out.
you can have more than one main in the same project
just not in the same exe
the assumption is that you will have a separate main for your test suite
you may conceivably want for example one main per test which is what I would advise
That way you can run all or handpicked tests.
As mentioned, I think you want ctest for this.
Although some IDEs may also present a convenient view to run all or specific tests.
Thank you and let us know if you have any more questions!