1
0
Fork 0
gobject-generator/scripts/smoke-test.sh

71 lines
2 KiB
Bash
Executable file

#!/usr/bin/env bash
# smoke-test.sh - runtime smoke tests for the generated bindings.
#
# The compile gate proves the generated Swift type-checks. This goes further:
# it generates a selected tier's bindings, links them against the REAL C libraries via
# pkg-config, and runs hand-written swift-testing cases from the selected tier's
# regression/tier<N>/*.swift files. Tier 6 installs every tier's fixtures into one
# full-stack package.
#
# Usage: scripts/smoke-test.sh [tier|all] [--fresh]
#
# tier 1..6 (default 1). tier1 = GLib+GObject, tier2 = +GModule+Gio, ...
# tier 6/all installs the accumulated fixtures from tiers 1 through 6
# all alias for tier 6
# --fresh wipe the selected tier's output directory before generating
#
# Output goes to ${TMPDIR:-/tmp}/gobject-generator-smoke/tier-<N> (a stable path so
# incremental swift builds stay fast between runs).
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
TIER="1"
FRESH=0
for arg in "$@"; do
if [[ "$arg" == "--fresh" ]]; then
FRESH=1
else
TIER="$arg"
fi
done
if [[ "$TIER" == "all" ]]; then
TIER="6"
fi
if [[ "$TIER" == "1" ]]; then
SMOKE_TIERS=(1)
elif [[ "$TIER" == "6" ]]; then
SMOKE_TIERS=(1 2 3 4 5 6)
else
SMOKE_TIERS=(1 "$TIER")
fi
CONFIG="$ROOT/regression/tier${TIER}/config.toml"
OUT="${TMPDIR:-/tmp}/gobject-generator-smoke/tier-${TIER}"
if [[ ! -f "$CONFIG" ]]; then
echo "!! missing $CONFIG" >&2
exit 2
fi
[[ "$FRESH" == 1 ]] && rm -rf "$OUT"
mkdir -p "$OUT"
echo "==> Building generator"
swift build --package-path "$ROOT"
BIN="$(swift build --package-path "$ROOT" --show-bin-path)/generator"
echo "==> Generating tier $TIER bindings (with SmokeTests target) into $OUT"
"$BIN" --monorepo-config "$CONFIG" --output "$OUT" --smoke-target >"$OUT/generate.log" 2>&1
echo "==> Installing smoke tests"
mkdir -p "$OUT/Tests/SmokeTests"
for smoke_tier in "${SMOKE_TIERS[@]}"; do
cp "$ROOT/regression/tier${smoke_tier}/"*.swift "$OUT/Tests/SmokeTests/"
done
echo "==> Running smoke tests against the real C libraries"
swift test --package-path "$OUT"