#!/bin/sh

set -eux

# tests fail in C.UTF-8
export LC_COLLATE=C

if [ $(id -un) = root ]; then
    chmod -R go+rwX regress
    exec su -c debian/tests/installcheck postgres
fi

if ! make installcheck PG_CONFIG=/usr/lib/postgresql/18/bin/pg_config; then
    head -n 10000 regress/regression.diffs regress/log/*.log
    DEB_HOST_ARCH_ENDIAN=$(dpkg-architecture -qDEB_HOST_ARCH_ENDIAN)
    case $DEB_HOST_ARCH_ENDIAN in
        little) exit 1 ;;
        big) echo "Ignoring test failure on big-endian architecture"; exit 0 ;;
    esac
fi
