File: code-coverage

package info (click to toggle)
btllib 1.7.5%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,336 kB
  • sloc: cpp: 79,742; python: 941; sh: 302; makefile: 5
file content (40 lines) | stat: -rwxr-xr-x 1,198 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash

if [ -z "${MESON_BUILD_ROOT}" ]; then
  echo "[ERROR] This script can only be ran with meson!"
  exit 1
fi

set -euo pipefail

cd "${MESON_BUILD_ROOT}"

ninja coverage --quiet

# Set your desired coverage threshold (e.g., 80%)
COVERAGE_THRESHOLD=20

# Initialize the failed files list
failed_files=""

# Iterate through the lines and check the coverage for the specified directories
while read -r line; do
    if echo "$line" | grep -E "src/btllib/|include/btllib/.*\-inl.hpp" > /dev/null; then
        file_name=$(echo "$line" | awk '{print $1}')
        coverage_percent=$(echo "$line" | awk '{print $4}' | tr -d '%')

        if [[ -n "$coverage_percent" ]] && [ "$coverage_percent" -lt "$COVERAGE_THRESHOLD" ]; then
            failed_files+="$file_name: $coverage_percent% (threshold: $COVERAGE_THRESHOLD%)\n"
        fi
    fi
done < ../build/meson-logs/coverage.txt

# Print the results and exit with an appropriate status code
if [ -n "$failed_files" ]; then
    echo -e "\n\e[31mRed The following files do not meet the coverage threshold:\e[0m"
    echo -e "$failed_files"
    exit 1
else
    echo "All files meet the coverage threshold ($COVERAGE_THRESHOLD%)."
    exit 0
fi