Skip to content

Commit a37446c

Browse files
fix: ignore string literals when matching Lean sorry/axiom (#526)
Resolves #517
1 parent 5fe9d38 commit a37446c

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

scripts/check-trusted-base.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ done
103103
echo "$proof_files" | grep -E '\.lean$' | while read -r f; do
104104
[ -z "$f" ] && continue
105105
grep -nE '\bsorry\b|^[[:space:]]*axiom[[:space:]]' "$f" 2>/dev/null | while IFS=: read -r ln rest; do
106+
# Strip string literals to avoid false positives (e.g. from keyword tables or debug strings)
107+
rest_no_strings="$(echo "$rest" | sed 's/"[^"]*"//g')"
108+
if ! echo "$rest_no_strings" | grep -qE '\bsorry\b|^[[:space:]]*axiom[[:space:]]'; then
109+
continue
110+
fi
106111
emit_marker "$f" "$ln" "lean-sorry-or-axiom" "$(echo "$rest" | head -c 80)"
107112
done
108113
done

tests/test_check_trusted_base.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
# SPDX-License-Identifier: MPL-2.0
3+
4+
set -euo pipefail
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
CHECK_SCRIPT="${SCRIPT_DIR}/../scripts/check-trusted-base.sh"
8+
9+
TEST_DIR=$(mktemp -d)
10+
trap 'rm -rf "$TEST_DIR"' EXIT
11+
12+
echo "Running check-trusted-base.sh tests..."
13+
14+
# Test 1: Should ignore 'sorry' in string literals
15+
cat << 'EOF' > "${TEST_DIR}/string_literal.lean"
16+
def my_keywords : List String := ["sorry", "axiom"]
17+
EOF
18+
19+
# Provide an empty proof-debt file to satisfy the script's basic requirements
20+
mkdir -p "${TEST_DIR}/docs"
21+
touch "${TEST_DIR}/docs/proof-debt.md"
22+
23+
if "${CHECK_SCRIPT}" "${TEST_DIR}" > /dev/null; then
24+
echo "PASS: Ignored 'sorry' in string literals."
25+
else
26+
echo "FAIL: Matched 'sorry' in string literals incorrectly."
27+
exit 1
28+
fi
29+
30+
# Test 2: Should flag actual 'sorry'
31+
cat << 'EOF' > "${TEST_DIR}/actual_sorry.lean"
32+
theorem fermat : a ^ n + b ^ n = c ^ n := by
33+
sorry
34+
EOF
35+
36+
if "${CHECK_SCRIPT}" "${TEST_DIR}" > /dev/null; then
37+
echo "FAIL: Failed to flag actual 'sorry'."
38+
exit 1
39+
else
40+
echo "PASS: Flagged actual 'sorry'."
41+
fi
42+
43+
echo "All tests passed!"

0 commit comments

Comments
 (0)