diff --git a/.github/workflows/cpp-coverage.yml b/.github/workflows/cpp-coverage.yml index 674194f..bb16652 100644 --- a/.github/workflows/cpp-coverage.yml +++ b/.github/workflows/cpp-coverage.yml @@ -21,14 +21,14 @@ jobs: - name: Install Tools run: | - pip install gcovr + sudo apt-get install lcov - name: Check Tools run: | make --version cmake --version vcpkg --version - gcovr --version + lcov --version - name: Install dependencies run: | @@ -54,6 +54,6 @@ jobs: uses: codecov/codecov-action@v4 with: directory: ./coverage - files: coverage.lcov + files: coverage/lcov.info token: ${{ secrets.CODECOV_TOKEN }} # required verbose: true # optional (default = false) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index b385509..b5f5f9f 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -22,6 +22,7 @@ jobs: fetch-depth: 0 - name: Install Tools run: | + sudo apt-get install lcov pip install gcovr - name: Check Tools @@ -29,6 +30,7 @@ jobs: make --version cmake --version vcpkg --version + lcov --version gcovr --version - name: Install dependencies @@ -43,17 +45,13 @@ jobs: - name: Run build-wrapper run: | export VCPKG_ROOT=/usr/local/share/vcpkg - cmake --preset debug -B build - cmake --preset debug \ - -DCMAKE_TOOLCHAIN_FILE=/usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake \ - -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \ - build - build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build --verbose + build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} make build # yamllint enable rule:line-length - name: Run tests to generate coverage statistics run: | make coverage + - name: Collect coverage into one XML report run: | gcovr -e "src/tests/*" --sonarqube > coverage.xml diff --git a/.lcovrc b/.lcovrc new file mode 100644 index 0000000..fc5c018 --- /dev/null +++ b/.lcovrc @@ -0,0 +1,84 @@ +# Example LCOV configuration file +# +# External style sheet file +#genhtml_css_file = gcov.css + +# Coverage rate limits for line coverage +genhtml_hi_limit = 80 +genhtml_med_limit = 50 + +# Coverage rate limits for function coverage +genhtml_function_hi_limit = 90 +genhtml_function_med_limit = 75 + +# Width of overview image +genhtml_overview_width = 80 + +# Resolution of overview navigation +genhtml_nav_resolution = 4 + +# Offset for source code navigation +genhtml_nav_offset = 10 + +# Do not remove unused test descriptions if non-zero +genhtml_keep_descriptions = 0 + +# Do not remove prefix from directory names if non-zero +genhtml_no_prefix = 0 + +# Do not create source code view if non-zero +genhtml_no_source = 0 + +# Specify size of tabs +genhtml_num_spaces = 8 + +# Highlight lines with converted-only data if non-zero +genhtml_highlight = 0 + +# Include color legend in HTML output if non-zero +genhtml_legend = 0 + +# Include HTML file at start of HTML output +#genhtml_html_prolog = prolog.html + +# Include HTML file at end of HTML output +#genhtml_html_epilog = epilog.html + +# Use custom HTML file extension +#genhtml_html_extension = html + +# Compress all generated html files with gzip. +#genhtml_html_gzip = 1 + +# Include sorted overview pages +genhtml_sort = 1 + +# Include function coverage data display +genhtml_function_coverage = 1 + +# Location of the gcov tool +#geninfo_gcov_tool = gcov + +# Adjust test names if non-zero +#geninfo_adjust_testname = 0 + +# Calculate a checksum for each line if non-zero +geninfo_checksum = 0 + +# Enable libtool compatibility mode if non-zero +geninfo_compat_libtool = 0 + +# Directory containing gcov kernel files +lcov_gcov_dir = /proc/gcov + +# Location of the insmod tool +lcov_insmod_tool = /sbin/insmod + +# Location of the modprobe tool +lcov_modprobe_tool = /sbin/modprobe + +# Location of the rmmod tool +lcov_rmmod_tool = /sbin/rmmod + +# Location for temporary directories +lcov_tmp_dir = /tmp diff --git a/Dockerfile b/Dockerfile index bc45c1a..ce47eb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -72,7 +72,7 @@ ADD https://deb.nodesource.com/setup_22.x nodesource_setup.sh RUN bash nodesource_setup.sh && \ apt-get -y install --no-install-recommends --no-install-suggests nodejs && \ npm install -g --ignore-scripts markdownlint-cli && \ - apt-get -y install --no-install-recommends --no-install-suggests python3 python3-pip && \ + apt-get -y install --no-install-recommends --no-install-suggests python3-minimal python3-pip && \ rm /usr/lib/python3.*/EXTERNALLY-MANAGED && \ pip install --no-cache-dir yamllint && \ apt-get -y install --no-install-recommends --no-install-suggests cppcheck && \ @@ -98,7 +98,7 @@ CMD ["make", "lint"] FROM development AS testing RUN apt-get -y update && \ - apt-get -y install --no-install-recommends --no-install-suggests gcovr && \ + apt-get -y install --no-install-recommends --no-install-suggests lcov && \ rm -rf /var/lib/apt/lists/* COPY --from=builder ${WORKDIR}/build ${WORKDIR}/ diff --git a/Makefile b/Makefile index 5c47643..0c8ddb8 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ BUILDKIT_PROGRESS=plain DOCKER_COMPOSE=docker compose # TOOLS -COVERAGE_TOOL=gcovr -e "src/tests/*" -e "build/*" --exclude-throw-branches --exclude-unreachable-branches --exclude-noncode-lines --print-summary +COVERAGE_TOOL_OPTS=--config-file .lcovrc --rc branch_coverage=1 # C++ specific SRC_DIR = src @@ -94,11 +94,10 @@ test: env dependencies cd build && make test coverage: test - ${COVERAGE_TOOL} - ${COVERAGE_TOOL} --lcov coverage/coverage.lcov + lcov ${COVERAGE_TOOL_OPTS} -o coverage/lcov.info --no-external -c --exclude "build/vcpkg_installed" --exclude "test.cpp" -d . -coverage/html: - ${COVERAGE_TOOL} --html-details coverage/index.html +coverage/html: coverage + genhtml ${COVERAGE_TOOL_OPTS} -o coverage/ -s --legend coverage/lcov.info open coverage/index.html outdated: diff --git a/src/tests/unit/lib/hackerrank/warmup/a_very_big_sum.test.cpp b/src/tests/unit/lib/hackerrank/warmup/a_very_big_sum.test.cpp index da48957..8e732f9 100644 --- a/src/tests/unit/lib/hackerrank/warmup/a_very_big_sum.test.cpp +++ b/src/tests/unit/lib/hackerrank/warmup/a_very_big_sum.test.cpp @@ -9,7 +9,8 @@ #include using json = nlohmann::json; -TEST_CASE("aVeryBigSum JSON Test Cases", "[warmup]") { +TEST_CASE("aVeryBigSum JSON Test Cases", + "[hackerrank] [jsontestcase] [warmup]") { std::filesystem::path cwd = std::filesystem::current_path(); std::string path = cwd.string() + diff --git a/src/tests/unit/lib/hackerrank/warmup/birthday_cake_candles.test.cpp b/src/tests/unit/lib/hackerrank/warmup/birthday_cake_candles.test.cpp index 5f87726..a417b8c 100644 --- a/src/tests/unit/lib/hackerrank/warmup/birthday_cake_candles.test.cpp +++ b/src/tests/unit/lib/hackerrank/warmup/birthday_cake_candles.test.cpp @@ -9,7 +9,8 @@ #include using json = nlohmann::json; -TEST_CASE("birthdayCakeCandles JSON Test Cases", "[warmup]") { +TEST_CASE("birthdayCakeCandles JSON Test Cases", + "[hackerrank] [jsontestcase] [warmup]") { std::filesystem::path cwd = std::filesystem::current_path(); std::string path = cwd.string() + diff --git a/src/tests/unit/lib/hackerrank/warmup/compare_triplets.test.cpp b/src/tests/unit/lib/hackerrank/warmup/compare_triplets.test.cpp index 06175d7..208cc52 100644 --- a/src/tests/unit/lib/hackerrank/warmup/compare_triplets.test.cpp +++ b/src/tests/unit/lib/hackerrank/warmup/compare_triplets.test.cpp @@ -9,7 +9,8 @@ #include using json = nlohmann::json; -TEST_CASE("compareTriplets JSON Test Cases", "[warmup]") { +TEST_CASE("compareTriplets JSON Test Cases", + "[hackerrank] [jsontestcase] [warmup]") { std::filesystem::path cwd = std::filesystem::current_path(); std::string path = cwd.string() + @@ -27,7 +28,7 @@ TEST_CASE("compareTriplets JSON Test Cases", "[warmup]") { } } -TEST_CASE("compareTriplets EDGE CASE empty input", "[warmup]") { +TEST_CASE("compareTriplets EDGE CASE empty input", "[hackerrank] [warmup]") { std::vector a; std::vector b; diff --git a/src/tests/unit/lib/hackerrank/warmup/diagonal_difference.test.cpp b/src/tests/unit/lib/hackerrank/warmup/diagonal_difference.test.cpp index adcd79b..5fa143c 100644 --- a/src/tests/unit/lib/hackerrank/warmup/diagonal_difference.test.cpp +++ b/src/tests/unit/lib/hackerrank/warmup/diagonal_difference.test.cpp @@ -9,7 +9,8 @@ #include using json = nlohmann::json; -TEST_CASE("diagonalDifference JSON Test Cases", "[warmup]") { +TEST_CASE("diagonalDifference JSON Test Cases", + "[hackerrank] [jsontestcase] [warmup]") { std::filesystem::path cwd = std::filesystem::current_path(); std::string path = cwd.string() + diff --git a/src/tests/unit/lib/hackerrank/warmup/mini_max_sum.test.cpp b/src/tests/unit/lib/hackerrank/warmup/mini_max_sum.test.cpp index 4e7ac2e..72b06aa 100644 --- a/src/tests/unit/lib/hackerrank/warmup/mini_max_sum.test.cpp +++ b/src/tests/unit/lib/hackerrank/warmup/mini_max_sum.test.cpp @@ -11,7 +11,8 @@ #include using json = nlohmann::json; -TEST_CASE("miniMaxSum JSON Test Cases", "[warmup]") { +TEST_CASE("miniMaxSum JSON Test Cases", + "[hackerrank] [jsontestcase] [warmup]") { std::filesystem::path cwd = std::filesystem::current_path(); std::string path = cwd.string() + "/unit/lib/hackerrank/warmup/mini_max_sum.testcases.json"; @@ -30,7 +31,7 @@ TEST_CASE("miniMaxSum JSON Test Cases", "[warmup]") { } } -TEST_CASE("miniMaxSum Edge Cases", "[warmup]") { +TEST_CASE("miniMaxSum Edge Cases", "[hackerrank] [warmup]") { std::vector empty; CHECK_THROWS_AS(hackerrank::warmup::miniMaxSumCalculate(empty), std::invalid_argument); diff --git a/src/tests/unit/lib/hackerrank/warmup/plus_minus.test.cpp b/src/tests/unit/lib/hackerrank/warmup/plus_minus.test.cpp index a4eaed3..07c7c79 100644 --- a/src/tests/unit/lib/hackerrank/warmup/plus_minus.test.cpp +++ b/src/tests/unit/lib/hackerrank/warmup/plus_minus.test.cpp @@ -10,7 +10,7 @@ #include using json = nlohmann::json; -TEST_CASE("plusMinus JSON Test Cases", "[warmup]") { +TEST_CASE("plusMinus JSON Test Cases", "[hackerrank] [jsontestcase] [warmup]") { std::filesystem::path cwd = std::filesystem::current_path(); std::string path = cwd.string() + "/unit/lib/hackerrank/warmup/plus_minus.testcases.json"; diff --git a/src/tests/unit/lib/hackerrank/warmup/simple_array_sum.test.cpp b/src/tests/unit/lib/hackerrank/warmup/simple_array_sum.test.cpp index 28bf670..629d9d2 100644 --- a/src/tests/unit/lib/hackerrank/warmup/simple_array_sum.test.cpp +++ b/src/tests/unit/lib/hackerrank/warmup/simple_array_sum.test.cpp @@ -8,7 +8,8 @@ using json = nlohmann::json; -TEST_CASE("simpleArraySum", "[warmup]") { +TEST_CASE("simpleArraySum JSON Test Cases", + "[hackerrank] [jsontestcase] [warmup]") { std::filesystem::path cwd = std::filesystem::current_path(); std::string path = cwd.string() + diff --git a/src/tests/unit/lib/hackerrank/warmup/solve_me_first.test.cpp b/src/tests/unit/lib/hackerrank/warmup/solve_me_first.test.cpp index 1d1af4b..11ac71e 100644 --- a/src/tests/unit/lib/hackerrank/warmup/solve_me_first.test.cpp +++ b/src/tests/unit/lib/hackerrank/warmup/solve_me_first.test.cpp @@ -8,7 +8,8 @@ using json = nlohmann::json; -TEST_CASE("solveMeFirst", "[warmup]") { +TEST_CASE("solveMeFirst JSON Test Cases", + "[hackerrank] [jsontestcase] [warmup]") { std::filesystem::path cwd = std::filesystem::current_path(); std::string path = cwd.string() +