Skip to content

Commit 18c951e

Browse files
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 9f447fc
1 parent 5a0887f commit 18c951e

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

cmake/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ if (protobuf_BUILD_TESTS OR protobuf_BUILD_CONFORMANCE OR protobuf_BUILD_EXAMPLE
297297
endif ()
298298

299299
if (protobuf_BUILD_TESTS)
300+
enable_testing()
300301
include(tests.cmake)
301302
endif (protobuf_BUILD_TESTS)
302303

cmake/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ Testing
164164
To run unit-tests, first you must compile protobuf as described above.
165165
Then run:
166166

167-
C:\Path\to\protobuf\cmake\build\release>nmake check
167+
C:\Path\to\protobuf\cmake\build\release>ctest --progress --output-on-failure
168+
169+
You can also build the `check` target (not idiomatic CMake usage, though):
170+
171+
C:\Path\to\protobuf\cmake\build\release>cmake --build . --target check
168172

169173
or
170174

@@ -183,7 +187,7 @@ You should see output similar to:
183187
[==========] 1546 tests from 165 test cases ran. (2529 ms total)
184188
[ PASSED ] 1546 tests.
185189

186-
To run specific tests:
190+
To run specific tests, you need to pass some command line arguments to the test program itself:
187191

188192
C:\Path\to\protobuf>cmake\build\release\tests.exe --gtest_filter=AnyTest*
189193
Running main() from gmock_main.cc

cmake/tests.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,7 @@ add_custom_target(check
255255
COMMAND tests
256256
DEPENDS tests test_plugin
257257
WORKING_DIRECTORY ${protobuf_source_dir})
258+
259+
add_test(NAME check
260+
COMMAND tests
261+
WORKING_DIRECTORY "${protobuf_source_dir}")

0 commit comments

Comments
 (0)