|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Regression contract for clang-tidy's `,-warnings-as-errors` diagnostic suffix. |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 6 | +FIX="$(mktemp -d "${TMPDIR:-/tmp}/lint-mem-gate.XXXXXX")" |
| 7 | +trap 'rm -rf "$FIX"' EXIT |
| 8 | + |
| 9 | +cat > "$FIX/sample.c" <<'EOF' |
| 10 | +int sample(int *value) { |
| 11 | + return *value; |
| 12 | +} |
| 13 | +EOF |
| 14 | + |
| 15 | +cat > "$FIX/whitelist.txt" <<EOF |
| 16 | +## $FIX/sample.c :: sample :: clang-analyzer-core.NullDereference |
| 17 | +segment-sha256: PLACEHOLDER |
| 18 | +why: | |
| 19 | + The test deliberately models a diagnostic that is suppressed by the fixture whitelist. |
| 20 | + This text is long enough to exercise the gate's normal argument validation path. |
| 21 | +tried: | |
| 22 | + The fixture is intentionally minimal and only verifies diagnostic parsing. |
| 23 | +EOF |
| 24 | + |
| 25 | +HASH="$(LINT_MEM_WHITELIST="$FIX/whitelist.txt" python3 "$ROOT/scripts/lint-mem-gate.py" --hash "$FIX/sample.c" sample | awk '/^segment-sha256:/ {print $2}')" |
| 26 | +python3 - "$FIX/whitelist.txt" "$HASH" <<'PY' |
| 27 | +from pathlib import Path |
| 28 | +import sys |
| 29 | +
|
| 30 | +path = Path(sys.argv[1]) |
| 31 | +text = path.read_text(encoding="utf-8").replace("PLACEHOLDER", sys.argv[2]) |
| 32 | +path.write_text(text, encoding="utf-8") |
| 33 | +PY |
| 34 | + |
| 35 | +printf '%s\n' "$FIX/sample.c:2:12: warning: possible null dereference [clang-analyzer-core.NullDereference,-warnings-as-errors]" \ |
| 36 | + | LINT_MEM_WHITELIST="$FIX/whitelist.txt" python3 "$ROOT/scripts/lint-mem-gate.py" 2> "$FIX/stderr" |
| 37 | + |
| 38 | +grep -q 'memory gate clean (1 argued false positive' "$FIX/stderr" |
| 39 | +echo 'lint-mem-gate warning suffix contract passed' |
0 commit comments