From 18c951efb164400ea3c4233eb7375f04a56298e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florin=20Cri=C8=99an?= Date: Tue, 8 Feb 2022 03:38:38 +0200 Subject: [PATCH] Enable testing via CTest (#8737) Convenience feature: enable users to test via the familiar `ctest` command rather than making the `check` target. They would be able to use the familiar CMake pattern: ``` cmake -S source/protobuf -B build/protobuf ... cmake --build build/protobuf ctest --test-dir build/protobuf cmake --install build/protobuf ``` This is a follow-up to 9f447fc9d3da93da29b8301f1a8ca57b1ea812d7 --- cmake/CMakeLists.txt | 1 + cmake/README.md | 8 ++++++-- cmake/tests.cmake | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) 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}")