Skip to content

Commit 91070cb

Browse files
committed
test(lint-mem): run the warning-suffix gate test on every leg
scripts/test.sh lists every shell contract test explicitly and does not glob tests/, so tests/test_lint_mem_gate.sh never ran on any leg. Register it as Step 0e4, next to the other gate contract (Step 0e3), in the same two-line shape as its neighbours. Step 0 runs in every default scripts/test.sh leg (macOS, Linux, Windows) and in the PR contracts-only job. The wiring, Windows included, is a maintainer decision (R1). Make the test portable to the Windows leg. There python3 is a native MSYS2 build: MSYS converts path arguments for it, but never the diagnostic text on stdin, so the absolute fixture path inside the finding does not resolve there, and a C:/ path would not parse (the file field of FINDING_RE ends at the first colon). The gate now runs from inside the fixture directory, in a subshell, with relative paths. CRLF from a native python3 is stripped from the --hash output, the whitelist is written once the hash is known (no placeholder rewrite), the gate exit status is asserted, and every failed assertion is reported together with the gate output. Refs DeusData#2442 Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent b11f542 commit 91070cb

2 files changed

Lines changed: 59 additions & 15 deletions

File tree

‎scripts/test.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ bash "$ROOT/tests/test_activation_diagnostic_contract.sh"
267267
echo "=== Step 0e3: security gate fail-closed contract ==="
268268
bash "$ROOT/tests/test_security_gate_fail_closed.sh"
269269

270+
echo "=== Step 0e4: memory-analyzer gate warning-suffix contract (#2442) ==="
271+
bash "$ROOT/tests/test_lint_mem_gate.sh"
272+
270273
echo "=== Step 0f: tree-sitter runtime Makefile dependencies ==="
271274
bash "$ROOT/tests/test_makefile_ts_runtime_dependencies.sh"
272275

‎tests/test_lint_mem_gate.sh‎

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,80 @@
11
#!/usr/bin/env bash
2-
# Regression contract for clang-tidy's `,-warnings-as-errors` diagnostic suffix.
2+
# Regression contract for clang-tidy's `,-warnings-as-errors` diagnostic suffix
3+
# (#2442). With WarningsAsErrors enabled, clang-tidy prints an analyzer check as
4+
# [clang-analyzer-<check>,-warnings-as-errors]; a gate that only accepts
5+
# [<check>] drops every such line and reports a clean gate. A suffixed finding
6+
# WITH an argued whitelist entry must be counted under its plain check name and
7+
# suppressed (exit 0, "1 argued false positive"). Every assertion is reported,
8+
# so a regression names what broke.
9+
#
10+
# The gate runs from inside the fixture directory with RELATIVE paths. On the
11+
# Windows leg python3 is a native MSYS2 build: MSYS converts path ARGUMENTS for
12+
# it, but never the diagnostic text on stdin, so an absolute /c/... path in a
13+
# finding would not resolve there, and a C:/... one would not parse (the file
14+
# field ends at the first colon).
315
set -euo pipefail
416

517
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
18+
GATE="$ROOT/scripts/lint-mem-gate.py"
619
FIX="$(mktemp -d "${TMPDIR:-/tmp}/lint-mem-gate.XXXXXX")"
720
trap 'rm -rf "$FIX"' EXIT
821

22+
failures=0
23+
fail() {
24+
echo "FAIL: $*" >&2
25+
failures=$((failures + 1))
26+
}
27+
28+
show() {
29+
sed 's/^/ | /' "$1" >&2
30+
}
31+
32+
# A subshell, so the test's own shell never sits inside $FIX (Windows cannot
33+
# remove a directory that is a process's working directory).
34+
run_gate() {
35+
(cd "$FIX" && LINT_MEM_WHITELIST=whitelist.txt python3 "$GATE" "$@")
36+
}
37+
938
cat > "$FIX/sample.c" <<'EOF'
1039
int sample(int *value) {
1140
return *value;
1241
}
1342
EOF
1443

44+
# A native Windows python3 writes CRLF; strip it before the hash is reused.
45+
HASH="$(run_gate --hash sample.c sample | tr -d '\r' | awk '/^segment-sha256:/ {print $2}')"
46+
if [[ ! "$HASH" =~ ^[0-9a-f]{64}$ ]]; then
47+
echo "FAIL: lint-mem-gate.py --hash sample.c sample printed no segment hash (got '$HASH')" >&2
48+
exit 1
49+
fi
50+
1551
cat > "$FIX/whitelist.txt" <<EOF
16-
## $FIX/sample.c :: sample :: clang-analyzer-core.NullDereference
17-
segment-sha256: PLACEHOLDER
52+
## sample.c :: sample :: clang-analyzer-core.NullDereference
53+
segment-sha256: $HASH
1854
why: |
1955
The test deliberately models a diagnostic that is suppressed by the fixture whitelist.
2056
This text is long enough to exercise the gate's normal argument validation path.
2157
tried: |
2258
The fixture is intentionally minimal and only verifies diagnostic parsing.
2359
EOF
2460

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
61+
SUFFIX='[clang-analyzer-core.NullDereference,-warnings-as-errors]'
3462

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"
63+
# Whitelisted: counted under the plain check name, then suppressed.
64+
rc=0
65+
printf '%s\n' "sample.c:2:12: warning: possible null dereference $SUFFIX" \
66+
| run_gate > /dev/null 2> "$FIX/whitelisted.err" || rc=$?
67+
if [ "$rc" -ne 0 ]; then
68+
fail "a whitelisted suffixed finding left the gate at exit $rc, expected 0"
69+
show "$FIX/whitelisted.err"
70+
fi
71+
if ! grep -q 'memory gate clean (1 argued false positive' "$FIX/whitelisted.err"; then
72+
fail "a whitelisted suffixed finding was not counted as 1 argued false positive"
73+
show "$FIX/whitelisted.err"
74+
fi
3775

38-
grep -q 'memory gate clean (1 argued false positive' "$FIX/stderr"
76+
if [ "$failures" -ne 0 ]; then
77+
echo "lint-mem-gate warning suffix contract: $failures assertion(s) failed" >&2
78+
exit 1
79+
fi
3980
echo 'lint-mem-gate warning suffix contract passed'

0 commit comments

Comments
 (0)