Skip to content

Commit

Permalink
Enable testing via CTest (#8737)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
florin-crisan committed Feb 8, 2022
1 parent 5a0887f commit 18c951e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmake/CMakeLists.txt
Expand Up @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions cmake/README.md
Expand Up @@ -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

Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cmake/tests.cmake
Expand Up @@ -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}")

0 comments on commit 18c951e

Please sign in to comment.