C++20 compatible polyfill for <expected>
#825
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: coverage | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
paths: | |
- '.github/workflows/coverage.yml' | |
- 'include/**' | |
- 'tests/**' | |
- 'CMakeLists.txt' | |
- 'cmake/**' | |
- '.codecov.yml' | |
workflow_dispatch: | |
jobs: | |
coverage: | |
runs-on: | |
group: intel-runners | |
container: libfn/ci-build-gcc:14 | |
strategy: | |
fail-fast: false | |
env: | |
CC: /usr/local/bin/gcc | |
CXX: /usr/local/bin/g++ | |
GCOV: /usr/local/bin/gcov | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Verify compiler compatibility | |
env: | |
SOURCE: | | |
#include <optional> | |
#include <expected> | |
#include <cstdio> | |
int main() { | |
using type1=std::expected<int, const char*>; | |
using type2=std::optional<int>; | |
return type1{1}.and_then([](int i) -> type1 { std::puts("OK expected"); return {i-1}; }).value() | |
+ type2{2}.and_then([](int i) -> type2 { std::puts("OK optional"); return {i-2}; }).value(); | |
} | |
run: | | |
printf "CXX=%s\nCXXFLAGS=%s\n" "$CXX" "$CXXFLAGS" | |
$CXX --version | head -1 | |
FILE=$(mktemp --tmpdir XXXXXX.cpp) | |
printf "$SOURCE\n" > $FILE | |
OUT=$(mktemp --tmpdir XXXXXX) | |
$CXX -std=c++2b $CXXFLAGS -Wall $FILE -o $OUT | |
$OUT | |
- name: Prepare build | |
shell: bash | |
env: | |
CMAKE_GENERATOR: Ninja | |
CMAKE_BUILD_TYPE: Debug | |
COVERAGE_OPTS: "-g --coverage -fprofile-abs-path -fno-early-inlining" | |
run: | | |
mkdir .build | |
cd .build | |
cmake -DCMAKE_C_FLAGS="$COVERAGE_OPTS" -DCMAKE_CXX_FLAGS="$COVERAGE_OPTS" .. | |
COMPILER=$( grep -iE "^CMAKE_CXX_COMPILER:FILEPATH=" CMakeCache.txt | sed -n 's/^[^=]*=//p' ) | |
FLAGS=$( grep -iE "^CMAKE_CXX_FLAGS(_${{ matrix.configuration }})?:STRING" CMakeCache.txt | sed -n 's/^[^=]*=//p' | tr '\n' ' ' ) | |
printf "C++ compiler path: %s\n" "$COMPILER" | |
$COMPILER --version | |
printf "C++ compilation options: %s\n" "$FLAGS" | |
printf "gcov version: %s\n" "$( $GCOV --version | head -1 )" | |
- name: Run coverage target | |
shell: bash | |
run: | | |
cd .build | |
cmake --build . | |
ctest -L 'tests_p?fn' -j1 # generate .gcda files | |
$GCOV -pbc -r -s $( realpath .. ) $( find tests -type f -name '*.gcno' ) # generate .gcov files | |
- name: Upload .gcov files | |
uses: codecov/codecov-action@v4 | |
with: | |
fail_ci_if_error: true | |
disable_search: false | |
verbose: true | |
plugin: noop | |
token: ${{ secrets.CODECOV_TOKEN }} |