|
2 | 2 | # Regression test: missing critical tier config yields a clear error. |
3 | 3 | set -euo pipefail |
4 | 4 |
|
5 | | -root="$(mktemp -d)" |
6 | | -trap 'rm -rf "$root"' EXIT |
| 5 | +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
7 | 6 |
|
8 | | -mkdir -p "$root/scripts" |
9 | | -cp "$(dirname "$0")/check-coverage.sh" "$(dirname "$0")/check-coverage-aggregate.awk" \ |
10 | | - "$root/scripts/" |
| 7 | +run_config_case() { |
| 8 | + local conf_body="$1" |
| 9 | + local label="$2" |
11 | 10 |
|
12 | | -cat >"$root/scripts/coverage-tiers.conf" <<'EOF' |
13 | | -TOTAL_MIN=90 |
| 11 | + local root |
| 12 | + root="$(mktemp -d)" |
| 13 | + # shellcheck disable=SC2064 |
| 14 | + trap "rm -rf '$root'" RETURN |
| 15 | + |
| 16 | + mkdir -p "$root/scripts" |
| 17 | + cp "$script_dir/check-coverage.sh" "$script_dir/check-coverage-aggregate.awk" \ |
| 18 | + "$root/scripts/" |
| 19 | + |
| 20 | + cat >"$root/scripts/coverage-tiers.conf" <<EOF |
| 21 | +${conf_body} |
14 | 22 | EOF |
15 | 23 |
|
16 | | -cat >"$root/coverage.out" <<'EOF' |
| 24 | + cat >"$root/coverage.out" <<'EOF' |
17 | 25 | mode: atomic |
18 | 26 | example.com/pkg/main.go:1.1,2.1 2 2 |
19 | 27 | EOF |
20 | 28 |
|
21 | | -output="" |
22 | | -code=0 |
23 | | -output="$(bash "$root/scripts/check-coverage.sh" "$root/coverage.out" 2>&1)" || code=$? |
24 | | - |
25 | | -if [[ "$code" -ne 2 ]]; then |
26 | | - echo "FAIL: expected exit 2 for incomplete config, got ${code}" >&2 |
27 | | - echo "$output" >&2 |
28 | | - exit 1 |
29 | | -fi |
30 | | - |
31 | | -if ! grep -q "must set CRITICAL_RULES or CRITICAL_MIN + CRITICAL_PREFIXES" <<<"$output"; then |
32 | | - echo "FAIL: expected descriptive config error, got:" >&2 |
33 | | - echo "$output" >&2 |
34 | | - exit 1 |
35 | | -fi |
| 29 | + local output="" |
| 30 | + local code=0 |
| 31 | + output="$(bash "$root/scripts/check-coverage.sh" "$root/coverage.out" 2>&1)" || code=$? |
| 32 | + |
| 33 | + if [[ "$code" -ne 2 ]]; then |
| 34 | + echo "FAIL (${label}): expected exit 2, got ${code}" >&2 |
| 35 | + echo "$output" >&2 |
| 36 | + return 1 |
| 37 | + fi |
| 38 | + |
| 39 | + if ! grep -q "must set CRITICAL_RULES or CRITICAL_MIN + CRITICAL_PREFIXES" <<<"$output"; then |
| 40 | + echo "FAIL (${label}): expected descriptive config error, got:" >&2 |
| 41 | + echo "$output" >&2 |
| 42 | + return 1 |
| 43 | + fi |
| 44 | + |
| 45 | + return 0 |
| 46 | +} |
| 47 | + |
| 48 | +run_config_case "TOTAL_MIN=90" "no critical tier keys" || exit 1 |
| 49 | +run_config_case $'TOTAL_MIN=90\nCRITICAL_MIN=95' "CRITICAL_MIN without CRITICAL_PREFIXES" || exit 1 |
36 | 50 |
|
37 | 51 | echo "PASS: incomplete critical tier config reports clear error" |
0 commit comments