|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +cd "$(dirname "$0")/../" |
| 5 | +PROJECT_DIR="$(pwd)" |
| 6 | +DIFF_DIR="$PROJECT_DIR/.test-helpers/tests/diff" |
| 7 | +BASELINE="$PROJECT_DIR/.reference/gnu-test-failures.txt" |
| 8 | +UPDATE_BASELINE=false |
| 9 | +EMPTY_BASELINE=false |
| 10 | + |
| 11 | +for arg in "$@"; do |
| 12 | + case "$arg" in |
| 13 | + --update-baseline) UPDATE_BASELINE=true ;; |
| 14 | + *) echo "Unknown argument: $arg" >&2; exit 2 ;; |
| 15 | + esac |
| 16 | +done |
| 17 | + |
| 18 | +# Collect current failures (exclude .err companion files) |
| 19 | +current_tmp=$(mktemp) |
| 20 | +trap 'rm -f "$current_tmp"' EXIT |
| 21 | +if [[ -d "$DIFF_DIR" ]]; then |
| 22 | + find "$DIFF_DIR" -mindepth 2 -maxdepth 2 -type f ! -name "*.err" -print0 \ |
| 23 | + | sort -z \ |
| 24 | + | while IFS= read -r -d '' path; do |
| 25 | + echo "${path#"$DIFF_DIR/"}" |
| 26 | + done > "$current_tmp" |
| 27 | +fi |
| 28 | + |
| 29 | +# --update-baseline mode |
| 30 | +if [[ "$UPDATE_BASELINE" == true ]]; then |
| 31 | + { |
| 32 | + echo "# Known GNU test failures - format: util/testname" |
| 33 | + echo "# Update with: ./scripts/check-new-gnu-failures.sh --update-baseline" |
| 34 | + cat "$current_tmp" |
| 35 | + } > "$BASELINE" |
| 36 | + count=$(wc -l < "$current_tmp") |
| 37 | + echo "Baseline updated: $BASELINE ($count failures recorded)" |
| 38 | + exit 0 |
| 39 | +fi |
| 40 | + |
| 41 | +# Load baseline (strip comments and blank lines) |
| 42 | +baseline_tmp=$(mktemp) |
| 43 | +trap 'rm -f "$current_tmp" "$baseline_tmp"' EXIT |
| 44 | +if [[ -f "$BASELINE" ]]; then |
| 45 | + grep -v '^\s*#' "$BASELINE" | grep -v '^\s*$' | sort > "$baseline_tmp" |
| 46 | +else |
| 47 | + echo "WARNING: Baseline not found: $BASELINE" >&2 |
| 48 | + echo " Run with --update-baseline to create it." >&2 |
| 49 | + touch "$baseline_tmp" |
| 50 | + EMPTY_BASELINE=true |
| 51 | +fi |
| 52 | + |
| 53 | +# comm: -13 = lines only in current (new failures), -23 = lines only in baseline (fixed) |
| 54 | +new_failures=$(comm -13 "$baseline_tmp" "$current_tmp") |
| 55 | +fixed_tests=$(comm -23 "$baseline_tmp" "$current_tmp") |
| 56 | + |
| 57 | +# Report |
| 58 | +echo "--- GNU test failure summary ---" |
| 59 | +echo "Baseline failures: $(wc -l < "$baseline_tmp")" |
| 60 | +echo "Current failures: $(wc -l < "$current_tmp")" |
| 61 | +echo "" |
| 62 | + |
| 63 | +if [[ "$EMPTY_BASELINE" == true ]]; then |
| 64 | + mkdir -p "$(dirname "$BASELINE")" |
| 65 | + { |
| 66 | + echo "# Known GNU test failures - format: util/testname" |
| 67 | + echo "# Update with: ./scripts/check-new-gnu-failures.sh --update-baseline" |
| 68 | + cat "$current_tmp" |
| 69 | + } > "$BASELINE" |
| 70 | + count=$(wc -l < "$current_tmp") |
| 71 | + echo "Initial baseline created: $BASELINE ($count failures recorded)" |
| 72 | + exit 0 |
| 73 | +fi |
| 74 | + |
| 75 | +if [[ -n "$fixed_tests" ]]; then |
| 76 | + echo "Tests newly FIXED:" |
| 77 | + awk '{print " [FIXED] " $0}' <<< "$fixed_tests" |
| 78 | + echo "" |
| 79 | +fi |
| 80 | + |
| 81 | +if [[ -n "$new_failures" ]]; then |
| 82 | + echo "Tests newly FAILING:" |
| 83 | + awk '{print " [NEW FAILURE] " $0}' <<< "$new_failures" |
| 84 | + echo "" |
| 85 | + count=$(wc -l <<< "$new_failures") |
| 86 | + echo "ERROR: $count new test failure(s) detected." >&2 |
| 87 | + echo " Fix the regression, or if intentional, update the baseline:" >&2 |
| 88 | + echo " ./scripts/check-new-gnu-failures.sh --update-baseline" >&2 |
| 89 | + exit 1 |
| 90 | +fi |
| 91 | + |
| 92 | +echo "No new failures. All current failures are known." |
| 93 | +if [[ -n "$fixed_tests" ]]; then |
| 94 | + echo "Consider updating the baseline to remove fixed tests:" |
| 95 | + echo " ./scripts/check-new-gnu-failures.sh --update-baseline" |
| 96 | +fi |
0 commit comments