| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #!/bin/bash
- # Meson test wrapper for the live PostgreSQL integration suite.
- #
- # Skips (exit 77) when no server is reachable, so default `meson test`
- # stays green on machines without PostgreSQL. When PG_TEST_FORCE=1 the
- # ensure script's failure to bring a server up is a hard error instead.
- set -u
- SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
- ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
- if [ "${PG_TEST_FORCE:-0}" = "1" ]; then
- "$SCRIPT_DIR/ensure-postgres.sh" || exit 1
- else
- "$SCRIPT_DIR/ensure-postgres.sh" || {
- echo "# PostgreSQL integration tests: server unavailable, skipping"
- exit 77
- }
- fi
- export PG_TEST_CONN="${PG_TEST_CONN:-postgresql://postgres@/sqltest?host=/tmp/pgrun&port=5433}"
- # Best-effort cleanup of leftover isolation schemas (t_<seed>_<n>) created
- # by the dual-backend ORM/migration/projection suites. Harmless when none
- # exist or when psql is unavailable.
- if command -v psql >/dev/null 2>&1; then
- psql -h "${PGHOST:-/tmp/pgrun}" -p "${PGPORT:-5433}" -U "${PGUSER:-postgres}" -d "${PGDATABASE:-sqltest}" -c 'DROP SCHEMA IF EXISTS t_schema_cleanup_dummy CASCADE; DO $$ DECLARE r record; BEGIN FOR r IN SELECT nspname FROM pg_namespace WHERE nspname ~ $$^t_[0-9]+_[0-9]+$$ LOOP EXECUTE $$DROP SCHEMA IF EXISTS $$ || quote_ident(r.nspname) || $$ CASCADE$$; END LOOP; END $$;' >/dev/null 2>&1 || true
- fi
- # Meson may pass the test executable as a build-dir-relative path; the
- # wrapper itself is invoked from the build directory, so resolve every
- # argument that points at an existing file to an absolute path before
- # exec'ing. Keeps manual invocation (absolute or $PATH) working too.
- args=()
- for a in "$@"; do
- if [ ! -z "$a" ] && [ ! -f "$a" ]; then
- if [ -f "$ROOT_DIR/$a" ]; then
- a="$ROOT_DIR/$a"
- elif [ -f "$ROOT_DIR/build/$a" ]; then
- a="$ROOT_DIR/build/$a"
- fi
- fi
- args+=("$a")
- done
- exec "${args[@]}"
|