Files
JetCore/tests/runlinttests.sh
T
brad ArantandClaude Opus 5.5 2847ce5fa7 Add jetc --lint-sql to find <sql> that pastes values (phase 2)
Implements phase 2 of docs/design-sql-bound-parameters.md. jetc --lint-sql
[--strict] <file|dir>... lists each <sql> whose statement contains a $[...]
or #[...] reference instead of a <bind>, with file:line and where each value
comes from. Row values ($[.col], $[session.col], $[?N], $[#]) are only
reported with --strict. References in <bind>, <if>, <set> and the other
attribute-only tags, <comment> and |> <| are skipped. A custom tag defined
as <sql><container></sql> (barant.com's <showtable>) is checked at each use.
Exit status is 0 for none found, 1 for findings, 2 for an unreadable path.

- jetc/JetLint.*: the scanner; jetc.cpp: the option
- build scripts and runbindtests.sh: link JetLint.cpp
- tests/runlinttests.sh and tests/lintsql/: fixtures and expected output
- docs: worklist for the local copies of both sites, design doc status,
  manual note on the lint

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 20:29:28 -08:00

35 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Tests for jetc --lint-sql (docs/design-sql-bound-parameters.md, phase 2).
# Runs the lint over tests/lintsql/ and compares with the .expected files.
# Needs no database.
set -u
T="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
JC="$(cd "$T/.." && pwd)"
WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
fail=0
g++ -g -std=c++23 -o "$WORK/jetc" "$JC/jetc/jetc.cpp" "$JC/jetc/JetParser.cpp" "$JC/jetc/JetCodegen.cpp" "$JC/jetc/JetLint.cpp" || exit 1
# check NAME EXPECTED_EXIT ARGS... - output is compared with lintsql/NAME.expected
check() {
local name="$1" want="$2"; shift 2
(cd "$T/lintsql" && "$WORK/jetc" --lint-sql "$@") > "$WORK/$name.out" 2>&1
local got=$?
if [ "$got" != "$want" ]; then
echo "FAIL $name: exit $got, expected $want"; fail=1
elif ! diff -u "$T/lintsql/$name.expected" "$WORK/$name.out"; then
echo "FAIL $name: output differs"; fail=1
else
echo "PASS $name"
fi
}
check site 1 site
check strict 1 --strict site
check clean 0 clean
check missing 2 clean no-such-dir
[ $fail = 0 ] && echo "ALL PASSED" || echo "FAILURES"
exit $fail