diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 49a69a3..2ebb490 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -25,7 +25,6 @@ jobs: matrix: os: [ubuntu-20.04] cxx: [g++-10, clang++] - memcheck: [false] include: # macos has two separate versions for the different compilers because # the new macos image needed for clang using a new version of XCode @@ -38,12 +37,11 @@ jobs: cxx: clang++ - os: windows-2019 cxx: msvc - - os: ubuntu-20.04 - cxx: g++-10 - memcheck: true # memory-testing on Linux only steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + with: + submodules: true # when building on master branch and not a pull request, build and test in release mode (optimised build) - name: Set Build Mode to Release @@ -51,12 +49,6 @@ jobs: if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/master' }} run: echo "BUILD_TYPE=Release" >> $GITHUB_ENV - - name: Install Valgrind - if: ${{ matrix.memcheck }} - run: | - sudo apt-get update - sudo apt-get install valgrind - - name: Configure CMake env: CXX: ${{ matrix.cxx }} @@ -76,22 +68,12 @@ jobs: run: cmake --build . --config $BUILD_TYPE - name: Test - if: ${{ !matrix.memcheck }} working-directory: ${{github.workspace}}/build shell: bash # Execute tests defined by the CMake configuration. # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail run: ctest -C $BUILD_TYPE --no-tests=error - - name: Test with Valgrind - if: ${{ matrix.memcheck }} - working-directory: ${{github.workspace}}/build - shell: bash - # run ctest with memcheck mode to check for memory errors with Valgrind - # exclude the one test case for arby::Nat::from_float with NaN/Inf because it fails on Valgrind - # due to lack of long double support - run: ctest -C $BUILD_TYPE -T memcheck -j3 -E "with non-finite value throws" --no-tests=error - - name: Test Install working-directory: ${{github.workspace}}/build shell: bash diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..1a8e97d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "cmake/Modules/externals/sanitizers-cmake"] + path = cmake/Modules/externals/sanitizers-cmake + url = git@github.com:arsenm/sanitizers-cmake.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 11ff47c..953c041 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,7 +115,7 @@ else() # GCC/Clang warning option enable_cxx_compiler_flag_if_supported("-Wno-unknown-pragmas") # if tests are enabled, enable converting all warnings to errors too if (ENABLE_TESTS) - enable_cxx_compiler_flag_if_supported("-Werror") + # enable_cxx_compiler_flag_if_supported("-Werror") # exclude the following kinds of warnings from being converted into errors # unknown-pragma is useful to have as a warning but not as an error, if you have # pragmas which are for the consumption of one compiler only @@ -128,11 +128,14 @@ else() # GCC/Clang warning option enable_cxx_compiler_flag_if_supported("-Wno-error=unused-but-set-variable") # Clang's now introduced a "helpful" analysis of for-loops that increment a variable twice enable_cxx_compiler_flag_if_supported("-Wno-error=for-loop-analysis") + # XXX: make sanitizer force quit + # enable_cxx_compiler_flag_if_supported("-fno-sanitize-recover=all") endif() endif() # add custom dependencies directory set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/externals/sanitizers-cmake/cmake") # a better way to load dependencies include(CPM) diff --git a/arby/include/arby/Nat.hpp b/arby/include/arby/Nat.hpp index b1f42b1..e304dbf 100644 --- a/arby/include/arby/Nat.hpp +++ b/arby/include/arby/Nat.hpp @@ -213,6 +213,8 @@ namespace com::saxbophone::arby { */ constexpr Nat() : _digits{0} { _validate_digits(); + int i = std::numeric_limits::max(); + ++i; } /** * @brief Integer-constructor, initialises with the given integer value diff --git a/cmake/Modules/externals/sanitizers-cmake b/cmake/Modules/externals/sanitizers-cmake new file mode 160000 index 0000000..c3dc841 --- /dev/null +++ b/cmake/Modules/externals/sanitizers-cmake @@ -0,0 +1 @@ +Subproject commit c3dc841af4dbf44669e65b82cb68a575864326bd diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b228398..19882d2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,6 +5,13 @@ CPMFindPackage( EXCLUDE_FROM_ALL YES ) +if (NOT MSVC) # Sanitizers package doesn't seem to work well with MSVC on CI... + set(SANITIZE_ADDRESS ON) + set(SANITIZE_UNDEFINED ON) + + find_package(Sanitizers) +endif() + # common option-propagating target to use for test suite sub-targets add_library(tests-config INTERFACE) target_link_libraries( @@ -14,6 +21,9 @@ target_link_libraries( arby Catch2::Catch2 # unit testing framework ) +if (NOT MSVC) # Sanitizers package doesn't seem to work well with MSVC on CI... + add_sanitizers(tests-config) +endif() # every sub-part of the test suite add_subdirectory(DivisionResult) diff --git a/tests/DivisionResult/CMakeLists.txt b/tests/DivisionResult/CMakeLists.txt index b85f3a2..79955ae 100644 --- a/tests/DivisionResult/CMakeLists.txt +++ b/tests/DivisionResult/CMakeLists.txt @@ -1,3 +1,3 @@ add_library(DivisionResult OBJECT division_result.cpp) target_link_libraries(DivisionResult PRIVATE tests-config) -target_precompile_headers(DivisionResult PRIVATE ) +# target_precompile_headers(DivisionResult PRIVATE ) diff --git a/tests/Interval/CMakeLists.txt b/tests/Interval/CMakeLists.txt index e12d4da..e63d517 100644 --- a/tests/Interval/CMakeLists.txt +++ b/tests/Interval/CMakeLists.txt @@ -1,3 +1,3 @@ add_library(Interval OBJECT interval.cpp) target_link_libraries(Interval PRIVATE tests-config) -target_precompile_headers(Interval PRIVATE ) +# target_precompile_headers(Interval PRIVATE ) diff --git a/tests/Nat/CMakeLists.txt b/tests/Nat/CMakeLists.txt index 17271cc..e3a349f 100644 --- a/tests/Nat/CMakeLists.txt +++ b/tests/Nat/CMakeLists.txt @@ -17,5 +17,6 @@ add_library( stringification.cpp user_defined_literals.cpp ) +add_sanitizers(Nat) target_link_libraries(Nat PRIVATE tests-config) -target_precompile_headers(Nat PRIVATE ) +# target_precompile_headers(Nat PRIVATE )