f619316470
Lower match to if-else for literals, ranges, enum tags, and wildcards. Fix bootstrap literal arms that always matched; port real arm AST/parser and Lcx_LowerMatch to selfhost with last-expression return. Expand pattern_matching example and add parse/use-after-move/double-mut golden diagnostics. Selfhost-loop remains binary-identical.
58 lines
1.5 KiB
Bash
Executable File
58 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Golden tests for Rust-style compiler diagnostics.
|
|
# Usage: from repo root: tests/error_golden/run.sh [path/to/buxc]
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
BUXC="${1:-$ROOT/buxc}"
|
|
DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
|
|
if [[ ! -x "$BUXC" ]]; then
|
|
echo "error: buxc not found at $BUXC (run make build first)"
|
|
exit 1
|
|
fi
|
|
|
|
passed=0
|
|
failed=0
|
|
|
|
normalize() {
|
|
# Replace absolute paths with FILE (location markers and "in <path>" lines).
|
|
# Drop trailing blank lines.
|
|
sed -E \
|
|
-e "s|$DIR/[^:[:space:]]+:|FILE:|g" \
|
|
-e "s|$ROOT/[^:[:space:]]+:|FILE:|g" \
|
|
-e "s|$DIR/[^:[:space:]]+|FILE|g" \
|
|
-e "s|$ROOT/[^:[:space:]]+|FILE|g" \
|
|
-e "s|//+|/|g" \
|
|
| sed -e :a -e '/^\n*$/{$d;N;ba' -e '}'
|
|
}
|
|
|
|
for case_dir in "$DIR"/*/; do
|
|
name="$(basename "$case_dir")"
|
|
[[ -f "$case_dir/expected.err" ]] || continue
|
|
[[ -f "$case_dir/bux.toml" ]] || continue
|
|
|
|
out="$("$BUXC" build "$case_dir" --color off 2>&1 || true)"
|
|
got="$(printf '%s\n' "$out" | normalize)"
|
|
exp="$(cat "$case_dir/expected.err")"
|
|
|
|
# Compare ignoring full absolute path differences already normalized
|
|
if [[ "$got" == "$exp" ]]; then
|
|
echo " PASS $name"
|
|
passed=$((passed + 1))
|
|
else
|
|
echo " FAIL $name"
|
|
echo "---- expected ----"
|
|
printf '%s\n' "$exp"
|
|
echo "---- got ----"
|
|
printf '%s\n' "$got"
|
|
echo "--------------"
|
|
failed=$((failed + 1))
|
|
fi
|
|
done
|
|
|
|
echo "Error golden tests: $passed passed, $failed failed"
|
|
if [[ $failed -gt 0 ]]; then
|
|
exit 1
|
|
fi
|