#!/bin/sh

set -eux

# remove test artifacts before possibly switching user (but keep pg_filedump)
rm -rf results tmp_check *.heap [1-9]*[0-9]

# switch to postgres when invoked as root
if [ "$(id -u)" = "0" ]; then
  mkdir -p results
  chmod 777 . results
  exec su -c $0 postgres
fi

if ! pg_virtualenv make installcheck; then
  head -n1000 regression.diffs tmp_check/log/*
  [ $(dpkg-architecture -qDEB_HOST_ARCH_ENDIAN) = "big" ] && exit 0 # ignore toast test failure on big-endian for now
  exit 1
fi
