aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2025-10-11 10:07:06 -0400
committerEugene Triguba <hello@eugenetriguba.com>2025-10-11 10:07:06 -0400
commit76d0bf47de70f6fa473a5845eb7dcbaf919f6ff0 (patch)
treedac041d0a1cc0b23cf97695b49d5d4b24130b98d /scripts
parentAdd note about --keepdb to contributing (diff)
downloadcli-76d0bf47de70f6fa473a5845eb7dcbaf919f6ff0.zip
Add ability to exclude bolttest from test coverage statistics
We don't care about the test coverage for bolttest because it itself is test code.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/test.sh54
1 files changed, 53 insertions, 1 deletions
diff --git a/scripts/lib/test.sh b/scripts/lib/test.sh
index 1cef37a..52d3ac1 100644
--- a/scripts/lib/test.sh
+++ b/scripts/lib/test.sh
@@ -112,7 +112,6 @@ test_run_go_tests() {
cmd="$cmd ./..."
- # For database tests, generate DSN and set environment variables
if [[ -n "$database_type" ]]; then
local dsn
dsn=$(docker_generate_dsn "$database_type")
@@ -121,6 +120,9 @@ test_run_go_tests() {
if eval "$cmd"; then
log_success "Tests completed successfully!"
+ if [[ -n "$coverage_file" && -f "$coverage_file" ]]; then
+ test_filter_coverage "$coverage_file"
+ fi
else
log_error "Tests failed!"
return 1
@@ -158,6 +160,56 @@ test_combine_coverage() {
log_success "Combined coverage report created: $output_file"
}
+# Filter coverage file based on .covignore patterns
+#
+# DESCRIPTION:
+# Reads .covignore file and removes matching lines from coverage file.
+# Patterns are matched using grep against file paths in coverage output.
+#
+# ARGUMENTS:
+# $1 - coverage_file: Coverage file to filter
+#
+# RETURN:
+# 0 - Filtering successful or no .covignore file
+# 1 - Filtering failed
+#
+test_filter_coverage() {
+ local coverage_file="$1"
+ local covignore_file="${PATH_PROJECT_DIR}/.covignore"
+
+ # If no .covignore file exists, nothing to filter
+ [[ ! -f "$covignore_file" ]] && return 0
+ # If coverage file exists but is empty, nothing to filter
+ [[ ! -s "$coverage_file" ]] && return 0
+
+ local temp_file="${coverage_file}.tmp"
+ local patterns=()
+ while IFS= read -r line; do
+ # Skip comments and empty lines
+ [[ "$line" =~ ^[[:space:]]*# ]] && continue
+ [[ -z "${line// /}" ]] && continue
+ patterns+=("$line")
+ done <"$covignore_file"
+ [[ ${#patterns[@]} -eq 0 ]] && return 0
+
+ local grep_cmd="grep --invert-match"
+ for pattern in "${patterns[@]}"; do
+ grep_cmd="$grep_cmd --patern '$pattern'"
+ done
+
+ if eval "$grep_cmd" "$coverage_file" >"$temp_file"; then
+ mv "$temp_file" "$coverage_file"
+ else
+ # If grep returns non-zero, it might be because all lines were filtered
+ # Check if temp file exists and has content
+ if [[ -f "$temp_file" ]]; then
+ mv "$temp_file" "$coverage_file"
+ fi
+ fi
+
+ return 0
+}
+
# Display coverage summary and HTML generation instructions
#
# ARGUMENTS: