Skip to content

Commit 60adc7c

Browse files
hartworkcopybara-github
authored andcommitted
CMake: Stop building tests by default (related to #20539) (#24373)
#test-continuous Related to #20539, in reaction to #20539 (comment) CC @mkruskal-google Closes #24373 COPYBARA_INTEGRATE_REVIEW=#24373 from hartwork:cmake-stop-building-tests-by-default 6be6748 FUTURE_COPYBARA_INTEGRATE_REVIEW=#24373 from hartwork:cmake-stop-building-tests-by-default 6be6748 PiperOrigin-RevId: 831563407
1 parent acb18a2 commit 60adc7c

File tree

6 files changed

+40
-21
lines changed

6 files changed

+40
-21
lines changed

.github/scripts/validate_yaml.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,23 @@
4141

4242
print('PASSED: All jobs are in the list of blocking jobs.')
4343

44+
45+
def check_ctest(name, job, file, obj):
46+
"""Checks that the ctest command is not in a mode that allows missing tests to pass."""
47+
for key in obj:
48+
if (
49+
isinstance(obj[key], str)
50+
and 'ctest' in obj[key]
51+
and 'ctest --no-tests=error' not in obj[key]
52+
):
53+
raise ValueError(
54+
'Step %s in job %s from file %s runs ctest in a mode that'
55+
' allows missing tests to pass' % (name, job, file)
56+
)
57+
elif isinstance(obj[key], dict):
58+
check_ctest(name, job, file, obj[key])
59+
60+
4461
# Ensure every job with a continuous prefix conditions every step on whether we
4562
# are in a continuous run.
4663
for file in yaml_files:
@@ -72,4 +89,6 @@
7289
' condition but the job does not contain the continuous-prefix'
7390
% (name, job, file)
7491
)
92+
check_ctest(name, job, file, step)
93+
7594
print('PASSED: All steps in all jobs check the continuous-run condition.')

.github/workflows/test_cpp.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ jobs:
146146
-c "set -ex;
147147
sccache -z;
148148
cmake . -DWITH_PROTOC=/workspace/${{ steps.cross-compile.outputs.protoc }}
149+
-Dprotobuf_BUILD_TESTS=ON
149150
-Dprotobuf_BUILD_CONFORMANCE=ON -DCMAKE_CXX_STANDARD=17
150151
-Dprotobuf_WITH_ZLIB=OFF ${{ env.SCCACHE_CMAKE_FLAGS }};
151152
cmake --build . --parallel 20;
152-
ctest --parallel 20;
153+
ctest --no-tests=error --parallel 20;
153154
sccache -s"
154155
155156
linux-cmake:
@@ -191,7 +192,7 @@ jobs:
191192
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
192193
uses: protocolbuffers/protobuf-ci/docker@v5
193194
with:
194-
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/cmake:3.16.9-e0df73e51131ccaf53451355d22577f377357604
195+
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/cmake:3.16.9-9626718698895971df3953d4aa2321d7425f3c5f
195196
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
196197
command: >-
197198
/test.sh ${{ matrix.flags}} ${{ env.SCCACHE_CMAKE_FLAGS }}
@@ -234,7 +235,7 @@ jobs:
234235
uses: protocolbuffers/protobuf-ci/docker@v5
235236
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
236237
with:
237-
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/cmake:3.16.9-e0df73e51131ccaf53451355d22577f377357604
238+
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/cmake:3.16.9-9626718698895971df3953d4aa2321d7425f3c5f
238239
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
239240
command: >-
240241
/install.sh -DCMAKE_CXX_STANDARD=17 ${{ env.SCCACHE_CMAKE_FLAGS }}
@@ -332,12 +333,12 @@ jobs:
332333
if: ${{ inputs.continuous-run }}
333334
uses: protocolbuffers/protobuf-ci/docker@v5
334335
with:
335-
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/cmake:3.16.9-e0df73e51131ccaf53451355d22577f377357604
336+
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/cmake:3.16.9-9626718698895971df3953d4aa2321d7425f3c5f
336337
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
337338
command: >-
338339
/install.sh -DCMAKE_CXX_STANDARD=17 ${{ env.SCCACHE_CMAKE_FLAGS }}
339340
-Dprotobuf_LOCAL_DEPENDENCIES_ONLY=OFF
340-
-Dprotobuf_BUILD_EXAMPLES=OFF \&\&
341+
-Dprotobuf_BUILD_EXAMPLES=OFF -Dprotobuf_BUILD_TESTS=ON \&\&
341342
mkdir examples/build \&\&
342343
cd examples/build \&\&
343344
cmake .. -DCMAKE_CXX_STANDARD=17 \&\&
@@ -381,9 +382,9 @@ jobs:
381382
-c 'set -ex;
382383
cd /workspace;
383384
sccache -z;
384-
cmake . ${{ matrix.flags }} ${{ env.SCCACHE_CMAKE_FLAGS }};
385+
cmake . -Dprotobuf_BUILD_TESTS=ON ${{ matrix.flags }} ${{ env.SCCACHE_CMAKE_FLAGS }};
385386
cmake --build . --parallel 20;
386-
ctest --verbose --parallel 20;
387+
ctest --no-tests=error --verbose --parallel 20;
387388
sccache -s'
388389
389390
linux-cmake-32-bit:
@@ -407,13 +408,14 @@ jobs:
407408
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/32bit@sha256:d6028ab408c49932836cdc514116f06886d7f6868a4d430630aa52adc5aee2fc
408409
platform: linux/386
409410
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
411+
entrypoint: bash
410412
command: >-
411-
/bin/bash -cex '
413+
-c 'set -ex;
412414
cd /workspace;
413415
sccache -z;
414-
cmake . -DCMAKE_CXX_STANDARD=17 ${{ env.SCCACHE_CMAKE_FLAGS }};
416+
cmake . -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=ON ${{ env.SCCACHE_CMAKE_FLAGS }};
415417
cmake --build . --parallel 20;
416-
ctest --verbose --parallel 20;
418+
ctest --no-tests=error --verbose --parallel 20;
417419
sccache -s'
418420
419421
non-linux:
@@ -530,7 +532,7 @@ jobs:
530532
bazel-version: 8.0.1
531533
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
532534
command: >-
533-
cmake . -DCMAKE_CXX_STANDARD=17 ${{ matrix.install-flags }}
535+
cmake . -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=ON ${{ matrix.install-flags }}
534536
${{ env.SCCACHE_CMAKE_FLAGS }} -Dprotobuf_ALLOW_CCACHE=ON
535537
- name: Build for install
536538
if: ${{ matrix.install-flags && (!matrix.continuous-only || inputs.continuous-run) }}
@@ -556,7 +558,7 @@ jobs:
556558
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
557559
bazel-version: 8.0.1
558560
command: >-
559-
cmake . -DCMAKE_CXX_STANDARD=17 ${{ matrix.flags }}
561+
cmake . -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_TESTS=ON ${{ matrix.flags }}
560562
${{ env.SCCACHE_CMAKE_FLAGS }} -Dprotobuf_ALLOW_CCACHE=ON
561563
562564
- name: Build
@@ -567,7 +569,7 @@ jobs:
567569
- name: Test
568570
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
569571
shell: bash
570-
run: ctest --verbose --parallel 20 -C Debug
572+
run: ctest --no-tests=error --verbose --parallel 20 -C Debug
571573

572574
- name: Report sccache stats
573575
if: ${{ !matrix.continuous-only || inputs.continuous-run }}

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ endif()
2929

3030
# Options
3131
option(protobuf_INSTALL "Install protobuf binaries and files" ON)
32-
option(protobuf_BUILD_TESTS "Build tests" ON)
32+
option(protobuf_BUILD_TESTS "Build tests" OFF)
3333
option(protobuf_BUILD_CONFORMANCE "Build conformance tests" OFF)
3434
option(protobuf_BUILD_EXAMPLES "Build examples" OFF)
3535
option(protobuf_BUILD_PROTOBUF_BINARIES "Build protobuf libraries and protoc compiler" ON)

appveyor.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ echo Building MinGW
1212
set PATH=C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin;%PATH:C:\Program Files\Git\usr\bin;=%
1313
mkdir build_mingw
1414
cd build_mingw
15-
cmake -G "%generator%" -Dprotobuf_BUILD_SHARED_LIBS=%BUILD_DLL% -Dprotobuf_UNICODE=%UNICODE% -Dprotobuf_BUILD_TESTS=0 ../cmake
15+
cmake -G "%generator%" -Dprotobuf_BUILD_SHARED_LIBS=%BUILD_DLL% -Dprotobuf_UNICODE=%UNICODE% ../cmake
1616
mingw32-make -j8 all || goto error
1717
rem cd %configuration%
1818
rem tests.exe || goto error

cmake/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ downloading and building a copy from GitHub. To prevent this and make it an
8989
error condition, you can optionally set:
9090
`-Dprotobuf_LOCAL_DEPENDENCIES_ONLY=ON`.
9191

92-
### Disabling Tests
92+
### Enabling Tests
9393

94-
To disable building the unit tests completely, set the following flag:
94+
To enable building the unit tests, set the following flag:
9595

96-
* `-Dprotobuf_BUILD_TESTS=OFF`
96+
* `-Dprotobuf_BUILD_TESTS=ON`
9797

9898
### ZLib Support
9999

cmake/gtest.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,5 @@ endif()
2222

2323
if (NOT TARGET GTest::gmock)
2424
message(FATAL_ERROR
25-
"Cannot find googletest dependency that's needed to build tests.\n"
26-
"If instead you want to skip tests, run cmake with:\n"
27-
" cmake -Dprotobuf_BUILD_TESTS=OFF\n")
25+
"Cannot find googletest dependency that's needed to build tests.\n")
2826
endif()

0 commit comments

Comments
 (0)