diff --git a/.github/workflows/ci_linux_clang.yml b/.github/workflows/ci_linux_clang.yml index 2f13d7db..414220e8 100644 --- a/.github/workflows/ci_linux_clang.yml +++ b/.github/workflows/ci_linux_clang.yml @@ -68,6 +68,13 @@ jobs: cc: "clang-14", cxx: "clang++-14", cxx_standard: 20 } + - { + name: "Ubuntu 22.04 Clang with sanitizers", + os: ubuntu-22.04, + build_type: Debug, + cc: "clang", cxx: "clang++", + enable_sanitizers_in_tests: ON + } steps: - uses: actions/checkout@v2 - name: Build project @@ -75,7 +82,11 @@ jobs: CC: ${{ matrix.config.cc }} CXX: ${{ matrix.config.cxx }} run: | - cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -DENABLE_TESTING=ON -DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }} + cmake -S . -B build \ + -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \ + -DENABLE_TESTING=ON \ + -DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }} \ + -DENABLE_SANITIZERS_IN_TESTS=${{ matrix.config.enable_sanitizers_in_tests }} cmake --build build -j - name: Run tests run: | diff --git a/.github/workflows/ci_linux_gcc.yml b/.github/workflows/ci_linux_gcc.yml index b2ba4e02..1445cbad 100644 --- a/.github/workflows/ci_linux_gcc.yml +++ b/.github/workflows/ci_linux_gcc.yml @@ -62,6 +62,13 @@ jobs: cc: "gcc-12", cxx: "g++-12", cxx_standard: 20 } + - { + name: "Ubuntu 22.04 GCC with sanitizers", + os: ubuntu-22.04, + build_type: Debug, + cc: "gcc", cxx: "g++", + enable_sanitizers_in_tests: ON + } steps: - uses: actions/checkout@v2 - name: Build project @@ -69,7 +76,11 @@ jobs: CC: ${{ matrix.config.cc }} CXX: ${{ matrix.config.cxx }} run: | - cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -DENABLE_TESTING=ON -DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }} + cmake -S . -B build \ + -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \ + -DENABLE_TESTING=ON \ + -DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }} \ + -DENABLE_SANITIZERS_IN_TESTS=${{ matrix.config.enable_sanitizers_in_tests }} cmake --build build -j - name: Run tests run: | diff --git a/.github/workflows/ci_windows_msvc.yml b/.github/workflows/ci_windows_msvc.yml index 65e5a865..bdc1d56b 100644 --- a/.github/workflows/ci_windows_msvc.yml +++ b/.github/workflows/ci_windows_msvc.yml @@ -59,7 +59,11 @@ jobs: - uses: actions/checkout@v2 - name: Build project run: | - cmake -S . -B build -G "${{ matrix.config.generator }}" -A ${{ matrix.config.architecture }} -DENABLE_TESTING=ON -DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }} + cmake -S . -B build \ + -G "${{ matrix.config.generator }}" \ + -A ${{ matrix.config.architecture }} \ + -DENABLE_TESTING=ON \ + -DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }} cmake --build build --config ${{ matrix.config.build_type }} -j - name: Run tests run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index f94a3f85..8c4adb62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,9 +3,10 @@ cmake_minimum_required(VERSION 3.14) project(FakeIt VERSION 2.3.2 LANGUAGES CXX) -option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang." OFF) option(ENABLE_TESTING "Enable build of tests." OFF) option(OVERRIDE_CXX_STANDARD_FOR_TESTS "Override the C++ standard used for building tests." "") +option(ENABLE_SANITIZERS_IN_TESTS "Enable address / undefined sanitizers in tests." OFF) +option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang." OFF) # Directory containing main targets of FakeIt. add_subdirectory(include) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fb77acc1..51883ddd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -45,6 +45,17 @@ if(OVERRIDE_CXX_STANDARD_FOR_TESTS) message(STATUS "Building tests in C++${OVERRIDE_CXX_STANDARD_FOR_TESTS}.") 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) + target_link_options(FakeIt_tests PRIVATE -fsanitize=address,undefined -fno-sanitize-recover=address,undefined) + target_compile_definitions(FakeIt_tests PRIVATE FAKEIT_DISABLE_UBSAN_TRIGGERING_TESTS) + message(STATUS "Sanitizers enabled: address, undefined.") + else() + message(SEND_ERROR "Sanitizers requested but compiler is not compatible.") + endif() +endif() + if(ENABLE_COVERAGE) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$") target_compile_options(FakeIt_tests PRIVATE --coverage)