Skip to content

Commit f4c7a3d

Browse files
authored
ci: Add minimal code coverage workflow (#3876)
Signed-off-by: Julien Jerphanion <[email protected]>
1 parent 60ad28a commit f4c7a3d

File tree

3 files changed

+150
-44
lines changed

3 files changed

+150
-44
lines changed

.github/workflows/coverage.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Code Coverage
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- feat/*
8+
pull_request:
9+
branches:
10+
- main
11+
- feat/*
12+
paths-ignore:
13+
- "docs/**"
14+
- "**.md"
15+
merge_group:
16+
types: [checks_requested]
17+
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.ref }}
20+
cancel-in-progress: true
21+
22+
defaults:
23+
run:
24+
# micromamba activation
25+
shell: bash -l -eo pipefail {0}
26+
27+
jobs:
28+
coverage:
29+
name: Code Coverage
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout mamba repository
33+
uses: actions/checkout@v4
34+
- name: Create build environment
35+
uses: mamba-org/setup-micromamba@v2
36+
with:
37+
environment-file: ./dev/environment-dev.yml
38+
environment-name: build_env
39+
cache-environment: true
40+
- name: Install dev-extra environment
41+
run: micromamba install -n build_env -y -f ./dev/environment-dev-extra.yml
42+
- name: Install micromamba-static environment
43+
run: micromamba install -n build_env -y -f ./dev/environment-micromamba-static.yml
44+
- uses: hendrikmuhs/ccache-action@main
45+
with:
46+
variant: sccache
47+
key: ${{ github.job }}-${{ github.runner.os }}
48+
restore-keys: |
49+
ccache-libmamba-${{ github.runner.os }}
50+
- name: Build mamba with coverage
51+
run: |
52+
cmake -B build/ -G Ninja \
53+
--preset mamba-unix-shared-debug \
54+
-D CMAKE_CXX_COMPILER_LAUNCHER=sccache \
55+
-D CMAKE_C_COMPILER_LAUNCHER=sccache \
56+
-D MAMBA_WARNING_AS_ERROR=ON \
57+
-D BUILD_LIBMAMBAPY=ON \
58+
-D BUILD_MICROMAMBA=ON \
59+
-D ENABLE_MAMBA_ROOT_PREFIX_FALLBACK=OFF \
60+
-D CMAKE_BUILD_TYPE=Debug \
61+
-D CMAKE_CXX_FLAGS_DEBUG="-g -O0 -fno-omit-frame-pointer --coverage" \
62+
-D CMAKE_C_FLAGS_DEBUG="-g -O0 -fno-omit-frame-pointer --coverage"
63+
cmake --build build/ --parallel
64+
- name: Show build cache statistics
65+
run: sccache --show-stats
66+
- name: Run C++ tests with coverage
67+
continue-on-error: true
68+
run: |
69+
unset CONDARC # Interferes with tests
70+
./build/libmamba/ext/solv-cpp/tests/test_solv_cpp
71+
./build/libmamba/tests/test_libmamba
72+
- name: Install lcov
73+
run: |
74+
sudo apt-get update
75+
sudo apt-get install -y lcov
76+
- name: Generate C++ coverage report
77+
run: |
78+
lcov --directory . --capture --output-file cpp_coverage.info
79+
lcov --remove cpp_coverage.info '/usr/*' '*/tests/*' '*/build/*' --output-file cpp_coverage.info --ignore-errors unused
80+
lcov --summary cpp_coverage.info --ignore-errors mismatch
81+
- name: Install libmambapy
82+
run: |
83+
cmake --install build/ --prefix "${CONDA_PREFIX}"
84+
python -m pip install --no-deps --no-build-isolation ./libmambapy
85+
- name: Run Python tests with coverage
86+
continue-on-error: true
87+
run: |
88+
# Run libmambapy tests with coverage
89+
python -m pytest libmambapy/tests/ --cov=libmambapy --cov-report=xml --cov-report=term-missing
90+
# Run micromamba tests with coverage
91+
export TEST_MAMBA_EXE=$(pwd)/build/micromamba/mamba
92+
python -m pytest micromamba/tests/ --cov=micromamba --cov-report=xml --cov-report=term-missing
93+
- name: Upload coverage to Codecov
94+
uses: codecov/codecov-action@v4
95+
with:
96+
files: |
97+
./cpp_coverage.info
98+
./coverage.xml
99+
fail_ci_if_error: true
100+
token: ${{ secrets.CODECOV_TOKEN }}

dev/environment-dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies:
3232
- pytest-timeout
3333
- pytest-xprocess
3434
- pytest-rerunfailures
35+
- pytest-cov
3536
- memory_profiler
3637
- requests
3738
- sel(win): pywin32

libmamba/tests/src/util/test_cast.cpp

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,11 @@
1414

1515
using namespace mamba::util;
1616

17-
using WidenTypes = std::tuple<
18-
// integers
19-
std::pair<char, int>,
20-
std::pair<unsigned char, int>,
21-
std::pair<unsigned char, unsigned int>,
22-
std::pair<int, long long int>,
23-
std::pair<unsigned int, long long int>,
24-
std::pair<unsigned int, unsigned long long int>,
25-
// floats
26-
std::pair<float, double>,
27-
// Mixed
28-
std::pair<char, float>,
29-
std::pair<unsigned char, float>,
30-
std::pair<int, double>,
31-
std::pair<unsigned int, double>>;
32-
33-
using OverflowLowestTypes = std::tuple<
34-
// integers
35-
std::pair<char, unsigned char>,
36-
std::pair<char, unsigned int>,
37-
std::pair<int, char>,
38-
std::pair<int, unsigned long long int>,
39-
// floats
40-
std::pair<double, float>,
41-
// mixed
42-
std::pair<double, int>,
43-
std::pair<float, char>>;
44-
4517
namespace
4618
{
47-
template <typename T>
19+
template <typename From, typename To>
4820
void check_exact_num_cast_widen()
4921
{
50-
using From = typename T::first_type;
51-
using To = typename T::second_type;
5222
static constexpr auto from_lowest = std::numeric_limits<From>::lowest();
5323
static constexpr auto from_max = std::numeric_limits<From>::max();
5424

@@ -58,38 +28,73 @@ namespace
5828
REQUIRE(safe_num_cast<To>(from_max) == static_cast<To>(from_max));
5929
}
6030

61-
TEMPLATE_LIST_TEST_CASE("Exact num cast widen", "", WidenTypes)
31+
TEST_CASE("Exact num cast widen - integers")
6232
{
63-
check_exact_num_cast_widen<TestType>();
33+
check_exact_num_cast_widen<char, int>();
34+
check_exact_num_cast_widen<unsigned char, int>();
35+
check_exact_num_cast_widen<unsigned char, unsigned int>();
36+
check_exact_num_cast_widen<int, long long int>();
37+
check_exact_num_cast_widen<unsigned int, long long int>();
38+
check_exact_num_cast_widen<unsigned int, unsigned long long int>();
6439
}
6540

66-
template <typename T>
41+
TEST_CASE("Exact num cast widen - floats")
42+
{
43+
check_exact_num_cast_widen<float, double>();
44+
}
45+
46+
TEST_CASE("Exact num cast widen - mixed")
47+
{
48+
check_exact_num_cast_widen<char, float>();
49+
check_exact_num_cast_widen<unsigned char, float>();
50+
check_exact_num_cast_widen<int, double>();
51+
check_exact_num_cast_widen<unsigned int, double>();
52+
}
53+
54+
template <typename From, typename To>
6755
void check_exact_num_cast_narrow()
6856
{
69-
using From = typename T::second_type; // inversed
70-
using To = typename T::first_type; // inversed
7157
REQUIRE(safe_num_cast<To>(From(0)) == To(0));
7258
REQUIRE(safe_num_cast<To>(From(1)) == To(1));
7359
}
7460

75-
TEMPLATE_LIST_TEST_CASE("Exact num cast narrow", "", WidenTypes)
61+
TEST_CASE("Exact num cast narrow - integers")
7662
{
77-
check_exact_num_cast_narrow<TestType>();
63+
check_exact_num_cast_narrow<int, char>();
64+
check_exact_num_cast_narrow<unsigned int, unsigned char>();
65+
check_exact_num_cast_narrow<long long int, int>();
66+
check_exact_num_cast_narrow<unsigned long long int, unsigned int>();
7867
}
7968

80-
template <typename T>
69+
TEST_CASE("Exact num cast narrow - floats")
70+
{
71+
check_exact_num_cast_narrow<double, float>();
72+
}
73+
74+
template <typename From, typename To>
8175
void check_exact_num_cast_overflow()
8276
{
83-
using From = typename T::first_type;
84-
using To = typename T::second_type;
8577
static constexpr auto from_lowest = std::numeric_limits<From>::lowest();
86-
8778
REQUIRE_THROWS_AS(safe_num_cast<To>(from_lowest), std::overflow_error);
8879
}
8980

90-
TEMPLATE_LIST_TEST_CASE("Exact num cast overflow", "", OverflowLowestTypes)
81+
TEST_CASE("Exact num cast overflow - integers")
82+
{
83+
check_exact_num_cast_overflow<char, unsigned char>();
84+
check_exact_num_cast_overflow<char, unsigned int>();
85+
check_exact_num_cast_overflow<int, char>();
86+
check_exact_num_cast_overflow<int, unsigned long long int>();
87+
}
88+
89+
TEST_CASE("Exact num cast overflow - floats")
90+
{
91+
check_exact_num_cast_overflow<double, float>();
92+
}
93+
94+
TEST_CASE("Exact num cast overflow - mixed")
9195
{
92-
check_exact_num_cast_overflow<TestType>();
96+
check_exact_num_cast_overflow<double, int>();
97+
check_exact_num_cast_overflow<float, char>();
9398
}
9499

95100
TEST_CASE("precision")

0 commit comments

Comments
 (0)