Skip to content

Commit 24871ee

Browse files
committed
test(lint-mem): an unwhitelisted suffixed finding must fail the gate
The test only covered a whitelisted finding. The defect in DeusData#2442 is the other direction: on main clang-tidy reported findings that carry the ,-warnings-as-errors suffix, the old FINDING_RE matched none of them, and the gate reported clean. Pin that direction too: a second fixture function with no whitelist entry, a suffixed finding inside it, and the gate must exit 1 and report the finding under its plain check name ([clang-analyzer-core.NullDereference], the whitelist key form) as an entry missing for unlisted(). With the suffix group of FINDING_RE reverted, this case exits 0 with "memory gate clean" and the test fails, naming all three assertions. A parser that accepts the line but keeps the suffix inside the check name fails it as well. The negative assertion is a maintainer decision (R1). Refs DeusData#2442 Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 91070cb commit 24871ee

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

‎tests/test_lint_mem_gate.sh‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
# Regression contract for clang-tidy's `,-warnings-as-errors` diagnostic suffix
33
# (#2442). With WarningsAsErrors enabled, clang-tidy prints an analyzer check as
44
# [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.
5+
# [<check>] drops every such line and reports a clean gate. Both directions are
6+
# pinned, and every assertion is reported, so a regression names what broke:
7+
# 1. a suffixed finding WITH an argued whitelist entry is counted under its
8+
# plain check name and suppressed (exit 0, "1 argued false positive");
9+
# 2. a suffixed finding WITHOUT an entry fails the gate (exit 1) and is
10+
# reported under its plain check name. This is the negative assertion: a
11+
# parser that drops the suffixed line reports clean (exit 0) here.
12+
# Reverting the suffix group in FINDING_RE (scripts/lint-mem-gate.py) turns
13+
# both red.
914
#
1015
# The gate runs from inside the fixture directory with RELATIVE paths. On the
1116
# Windows leg python3 is a native MSYS2 build: MSYS converts path ARGUMENTS for
@@ -39,6 +44,10 @@ cat > "$FIX/sample.c" <<'EOF'
3944
int sample(int *value) {
4045
return *value;
4146
}
47+
48+
int unlisted(int *value) {
49+
return *value;
50+
}
4251
EOF
4352

4453
# A native Windows python3 writes CRLF; strip it before the hash is reused.
@@ -60,7 +69,7 @@ EOF
6069

6170
SUFFIX='[clang-analyzer-core.NullDereference,-warnings-as-errors]'
6271

63-
# Whitelisted: counted under the plain check name, then suppressed.
72+
# 1. Whitelisted: counted under the plain check name, then suppressed.
6473
rc=0
6574
printf '%s\n' "sample.c:2:12: warning: possible null dereference $SUFFIX" \
6675
| run_gate > /dev/null 2> "$FIX/whitelisted.err" || rc=$?
@@ -73,8 +82,24 @@ if ! grep -q 'memory gate clean (1 argued false positive' "$FIX/whitelisted.err"
7382
show "$FIX/whitelisted.err"
7483
fi
7584

85+
# 2. Not whitelisted: the gate must fail and name the finding.
86+
rc=0
87+
printf '%s\n' "sample.c:6:12: warning: possible null dereference $SUFFIX" \
88+
| run_gate > /dev/null 2> "$FIX/unlisted.err" || rc=$?
89+
if [ "$rc" -ne 1 ]; then
90+
fail "an unwhitelisted suffixed finding left the gate at exit $rc, expected 1" \
91+
"(exit 0 = the suffixed line was parsed as no finding, #2442)"
92+
show "$FIX/unlisted.err"
93+
fi
94+
if ! grep -qF 'sample.c:6: possible null dereference [clang-analyzer-core.NullDereference]' "$FIX/unlisted.err" ||
95+
! grep -qF 'no whitelist entry for unlisted()' "$FIX/unlisted.err" ||
96+
! grep -qF '1 finding(s) unaccounted for' "$FIX/unlisted.err"; then
97+
fail "the gate did not report the unwhitelisted suffixed finding under its plain check name"
98+
show "$FIX/unlisted.err"
99+
fi
100+
76101
if [ "$failures" -ne 0 ]; then
77102
echo "lint-mem-gate warning suffix contract: $failures assertion(s) failed" >&2
78103
exit 1
79104
fi
80-
echo 'lint-mem-gate warning suffix contract passed'
105+
echo 'lint-mem-gate warning suffix contract passed (whitelisted + unwhitelisted suffixed findings)'

0 commit comments

Comments
 (0)