Skip to content

Commit

Permalink
Treat warnings as errors when building tests in the CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
FranckRJ committed Apr 27, 2024
1 parent e2cc030 commit ccd2589
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci_linux_clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
-DENABLE_TESTING=ON \
-DWARNINGS_AS_ERRORS_FOR_TESTS=ON \
-DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }} \
-DENABLE_SANITIZERS_IN_TESTS=${{ matrix.config.enable_sanitizers_in_tests }}
cmake --build build -j
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci_linux_gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ jobs:
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
-DENABLE_TESTING=ON \
-DWARNINGS_AS_ERRORS_FOR_TESTS=ON \
-DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }} \
-DENABLE_SANITIZERS_IN_TESTS=${{ matrix.config.enable_sanitizers_in_tests }}
cmake --build build -j
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci_macos_appleclang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
-DENABLE_TESTING=ON \
-DWARNINGS_AS_ERRORS_FOR_TESTS=ON \
-DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }} \
-DENABLE_SANITIZERS_IN_TESTS=${{ matrix.config.enable_sanitizers_in_tests }}
cmake --build build -j
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci_windows_msvc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
-G "${{ matrix.config.generator }}" \
-A ${{ matrix.config.architecture }} \
-DENABLE_TESTING=ON \
-DWARNINGS_AS_ERRORS_FOR_TESTS=ON \
-DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }}
cmake --build build --config ${{ matrix.config.build_type }} -j
- name: Run tests
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ project(FakeIt VERSION 2.4.0 LANGUAGES CXX)

option(ENABLE_TESTING "Enable build of tests." OFF)
set(OVERRIDE_CXX_STANDARD_FOR_TESTS "" CACHE STRING "Override the C++ standard used for building tests.")
option(WARNINGS_AS_ERRORS_FOR_TESTS "Treat warnings as errors when building tests." OFF)
option(ENABLE_SANITIZERS_IN_TESTS "Enable address / undefined sanitizers in tests." OFF)
option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang." OFF)

Expand Down
8 changes: 8 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ if(OVERRIDE_CXX_STANDARD_FOR_TESTS)
message(STATUS "Building tests in C++${OVERRIDE_CXX_STANDARD_FOR_TESTS}.")
endif()

if(WARNINGS_AS_ERRORS_FOR_TESTS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
target_compile_options(FakeIt_tests PRIVATE -Werror)
elseif(MSVC)
target_compile_options(FakeIt_tests PRIVATE /WX)
endif()
endif()

if(ENABLE_SANITIZERS_IN_TESTS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
target_compile_options(FakeIt_tests PRIVATE -fsanitize=address,undefined -fno-sanitize-recover=address,undefined)
Expand Down

0 comments on commit ccd2589

Please sign in to comment.