#!/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/*
  exit 0
fi
