diff --git a/.gitignore b/.gitignore index 6f10e42..749d764 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /.idea/ /docs/ /coverage/ +/coverage/* /tools/config/override \ No newline at end of file diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 392e86b..dce8f89 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1,5 +1,7 @@ Include(FetchContent) +include(../code-coverage.cmake) + FetchContent_Declare( Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git @@ -13,6 +15,8 @@ target_link_libraries(tests PRIVATE LibSnugLog) target_link_libraries(tests PRIVATE Catch2::Catch2WithMain) include_directories(../LibSnugLog/public_include) +target_code_coverage(tests EXCLUDE catch2 Tests) + include(CTest) include(Catch) catch_discover_tests(tests) \ No newline at end of file diff --git a/tools/build_coverage.sh b/tools/build_coverage.sh index e69de29..9de797f 100644 --- a/tools/build_coverage.sh +++ b/tools/build_coverage.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +SNUGLOG_DIR=. + +if [ $# -ge 1 ]; then + SNUGLOG_DIR=$1 +fi + +SNUGLOG_DIR=$(realpath "$SNUGLOG_DIR") + +source "$SNUGLOG_DIR/tools/config/defaults" + +if [ $# -ge 2 ]; then + source "$2" +elif [ -f "$SNUGLOG_DIR/tools/config/override" ]; then + source "$SNUGLOG_DIR/tools/config/override" +fi + +BUILD_DIR="$SNUGLOG_DIR/coverage" + +IS_NOISY_CMAKE="" +if [ "$NOISY_CMAKE" -eq 1 ]; then + IS_NOISY_CMAKE="-DCMAKE_VERBOSE_MAKEFILE=ON" +fi + +if test "$MUST_REWRITE_PATHS" -eq 1 && test ! "$REWRITE_ENABLED" && [[ ! "$1" =~ /\s/g ]] && [[ ! "$2" =~ /\s/g ]]; then + export REWRITE_ENABLED=1 + (echo "$0 $@" | /usr/bin/env bash) 2>&1 | sed $REWRITE_PATHS + export REWRITE_ENABLED=0 +else + rm -rf "$BUILD_DIR" + mkdir -p "$BUILD_DIR" + + cd "$BUILD_DIR" || exit + + cmake \ + -DCODE_COVERAGE=ON \ + -DCMAKE_BUILD_TYPE=Debug \ + "-DCMAKE_C_COMPILER=$C_COMPILER" \ + "-DCMAKE_CXX_COMPILER=$CXX_COMPILER" \ + $IS_NOISY_CMAKE \ + "-DLLVM_COV_PATH=$LLVM_COV" \ + "-DLLVM_PROFDATA_PATH=$LLVM_PROFDATA" \ + "$SNUGLOG_DIR" + + make -j3 ccov-tests +fi \ No newline at end of file