diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index da366b8b12..2366d4b427 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -297,6 +297,7 @@ if (protobuf_BUILD_TESTS OR protobuf_BUILD_CONFORMANCE OR protobuf_BUILD_EXAMPLE endif () if (protobuf_BUILD_TESTS) + enable_testing() include(tests.cmake) endif (protobuf_BUILD_TESTS) diff --git a/cmake/README.md b/cmake/README.md index d75012cff0..857d146aa0 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -164,7 +164,11 @@ Testing To run unit-tests, first you must compile protobuf as described above. Then run: - C:\Path\to\protobuf\cmake\build\release>nmake check + C:\Path\to\protobuf\cmake\build\release>ctest --progress --output-on-failure + +You can also build the `check` target (not idiomatic CMake usage, though): + + C:\Path\to\protobuf\cmake\build\release>cmake --build . --target check or @@ -183,7 +187,7 @@ You should see output similar to: [==========] 1546 tests from 165 test cases ran. (2529 ms total) [ PASSED ] 1546 tests. -To run specific tests: +To run specific tests, you need to pass some command line arguments to the test program itself: C:\Path\to\protobuf>cmake\build\release\tests.exe --gtest_filter=AnyTest* Running main() from gmock_main.cc diff --git a/cmake/tests.cmake b/cmake/tests.cmake index 2c9e38ee5a..7a359e268a 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -255,3 +255,7 @@ add_custom_target(check COMMAND tests DEPENDS tests test_plugin WORKING_DIRECTORY ${protobuf_source_dir}) + +add_test(NAME check + COMMAND tests + WORKING_DIRECTORY "${protobuf_source_dir}")