Skip to content

Commit

Permalink
Merge pull request #106 from saxbophone/josh/97-valgrind-on-ci
Browse files Browse the repository at this point in the history
Attempting to add an additional github-actions build that also runs t…
  • Loading branch information
saxbophone authored Jun 5, 2022
2 parents 1d0ed8f + ce6ed66 commit 8f9b0bd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 34 deletions.
50 changes: 20 additions & 30 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ 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
Expand All @@ -37,46 +38,25 @@ 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

# - name: Cache CMake dependency source code
# uses: actions/cache@v2
# env:
# cache-name: cache-cmake-dependency-sources
# with:
# # CMake cache is at ${{github.workspace}}/build/_deps but we only will cache folders ending in '-src' to cache source code
# path: ${{github.workspace}}/build/_deps/*-src
# # Cache hash is dependent on CMakeLists files anywhere as these can change what's in the cache, as well as cmake modules files
# key: ${{ env.cache-name }}-${{ hashFiles('**/CMakeLists.txt', 'cmake/**') }}
# # it's acceptable to reuse caches for different CMakeLists content if exact match is not available and unlike build caches, we
# # don't need to restrict these by OS or compiler as it's only source code that's being cached
# restore-keys: |
# ${{ env.cache-name }}-

# - name: Cache CMake dependency build objects
# uses: actions/cache@v2
# env:
# cache-name: cache-cmake-dependency-builds
# with:
# # CMake cache is at ${{github.workspace}}/build/_deps but we only care about the folders ending in -build or -subbuild
# path: |
# ${{github.workspace}}/build/_deps/*-build
# ${{github.workspace}}/build/_deps/*-subbuild
# # Cache hash is dependent on CMakeLists files anywhere as these can change what's in the cache, as well as cmake modules files
# key: ${{ env.cache-name }}-${{ matrix.os }}-${{ matrix.cxx }}-${{ hashFiles('**/CMakeLists.txt', 'cmake/**') }}
# # it's acceptable to reuse caches for different CMakeLists content if exact match is not available
# # as long as the OS and Compiler match exactly
# restore-keys: |
# ${{ env.cache-name }}-${{ matrix.os }}-${{ matrix.cxx }}-

# when building on master branch and not a pull request, build and test in release mode (optimised build)
- name: Set Build Mode to Release
shell: bash
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 }}
Expand All @@ -96,12 +76,22 @@ 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
Expand Down
8 changes: 4 additions & 4 deletions tests/Nat/casting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ TEMPLATE_TEST_CASE(
CHECK_THROWS_AS((TestType)value, std::range_error);
}

TEST_CASE("Casting arby::Nat to other type - uint8_t", "[casting]",) {
TEST_CASE("Casting arby::Nat to other type - uint8_t", "[casting]") {
auto value = GENERATE(take(1000, random((std::uint16_t)0, (std::uint16_t)std::numeric_limits<std::uint8_t>::max())));

CHECK((std::uint8_t)arby::Nat((uintmax_t)value) == (std::uint8_t)value);
}

TEST_CASE("Casting arby::Nat to other type - int8_t", "[casting]",) {
TEST_CASE("Casting arby::Nat to other type - int8_t", "[casting]") {
auto value = GENERATE(take(1000, random((std::int16_t)0, (std::int16_t)std::numeric_limits<std::int8_t>::max())));

CHECK((std::int8_t)arby::Nat((uintmax_t)value) == (std::int8_t)value);
Expand Down Expand Up @@ -116,7 +116,7 @@ TEST_CASE("arby::Nat::from_float() with positive value", "[casting]") {
CHECK((long double)object == Approx(std::trunc(value)));
}

TEST_CASE("arby::Nat can be constructed from unsigned types smaller than uintmax_t - uint8_t",) {
TEST_CASE("arby::Nat can be constructed from unsigned types smaller than uintmax_t - uint8_t", "[casting]") {
// workaround for Catch bug: https://github.com/catchorg/Catch2/issues/2433
std::uint16_t input = GENERATE(take(1000, random((std::uint16_t)0x00, (std::uint16_t)0xFF)));

Expand All @@ -127,7 +127,7 @@ TEST_CASE("arby::Nat can be constructed from unsigned types smaller than uintmax

TEMPLATE_TEST_CASE(
"arby::Nat can be constructed from unsigned types smaller than uintmax_t",
"",
"[casting]",
std::uint16_t, std::uint32_t, std::uint64_t
) {
TestType input = GENERATE(take(1000, random((TestType)0, std::numeric_limits<TestType>::max())));
Expand Down

0 comments on commit 8f9b0bd

Please sign in to comment.