1
0
Fork 0

Improve regression test script: portable path, cleanup trap, auto-build

This commit is contained in:
Brendan Szymanski 2026-07-01 18:56:37 -04:00
parent 34554c96c3
commit 0792f45c4c
2 changed files with 39 additions and 21 deletions

View file

@ -1,19 +1,37 @@
#!/usr/bin/env bash
# Regression test for swift-gtk-gen output.
# Run this after any change to CodeGen.swift to catch regressions.
#
# Steps:
# 1. Build the generator
# 2. Generate Gtk-4.0 wrapper from the system .gir file
# 3. Run unit tests
# 4. Try to build the generated wrapper; report dependency-ignored errors
# 5. Lint the generated wrapper
set -euo pipefail
cd "$(dirname "$0")/.."
TEST_DIR="/tmp/regression-test-$$"
BIN_PATH=".build/debug/swift-gtk-gen"
echo "=== swift-gtk-gen regression test ==="
echo "Test output directory: $TEST_DIR"
# Cleanup trap (runs on exit, even on failure)
trap 'rm -rf "$TEST_DIR" /tmp/build-output.log' EXIT
# Ensure binary is built
if [ ! -x "$BIN_PATH" ]; then
echo "Binary not found at $BIN_PATH — running 'swift build' first..."
swift build
fi
# Generate
rm -rf "$TEST_DIR"
mkdir -p "$TEST_DIR"
.build/x86_64-unknown-linux-gnu/debug/swift-gtk-gen \
"$BIN_PATH" \
--gir-file /usr/share/gir-1.0/Gtk-4.0.gir \
--output "$TEST_DIR" \
--generate-all 2>/dev/null
@ -21,7 +39,7 @@ mkdir -p "$TEST_DIR"
# Run unit tests
echo ""
echo "=== Unit tests ==="
swift test 2>&1 | tail -2
swift test 2>&1 | tail -5
# Count errors
echo ""
@ -29,25 +47,30 @@ echo "=== Generated output metrics ==="
file_count=$(find "$TEST_DIR" -name "*.swift" | wc -l)
echo "Generated Swift files: $file_count"
cd "$TEST_DIR"
if swift build 2>&1 > /tmp/build-output.log; then
# Try to build the generated code
echo ""
echo "=== Build generated code ==="
if swift build --package-path "$TEST_DIR" 2>&1 > /tmp/build-output.log; then
echo "Generated code BUILD: PASS"
else
cannot_find=$(grep "error:" /tmp/build-output.log | grep -c "cannot find" || echo 0)
total=$(grep -c "error:" /tmp/build-output.log || echo 0)
cannot_find=$(grep "error:" /tmp/build-output.log | grep -c "cannot find" || echo 0)
fixable=$((total - cannot_find))
echo "Generated code BUILD: FAIL ($total total errors, $cannot_find dependency-ignored, $fixable fixable)"
echo "Generated code BUILD: FAIL"
echo " Total errors: $total"
echo " Cannot find (deps): $cannot_find"
echo " Fixable errors: $fixable"
if [ "$fixable" -gt 0 ]; then
echo ""
echo "First 20 fixable errors:"
grep "error:" /tmp/build-output.log | grep -v "cannot find" | head -20
exit 1
fi
fi
# Lint
echo ""
echo "=== Lint ==="
cd -
cd "$(dirname "$0")/.."
lint_errors=$(swift format lint --configuration .swift-format --recursive "$TEST_DIR" 2>&1 | grep -c "error:" || echo 0)
echo "Lint errors: $lint_errors"
if [ "$lint_errors" -gt 0 ]; then
@ -55,7 +78,5 @@ if [ "$lint_errors" -gt 0 ]; then
swift format lint --configuration .swift-format --recursive "$TEST_DIR" 2>&1 | grep "error:" | head -10
fi
# Cleanup
rm -rf "$TEST_DIR"
echo ""
echo "=== Done ==="