#! /bin/bash
set -euo pipefail

# run a GTest in tap mode. The test binary is passed as $1
# use /var/tmp so we can use xattrs in case /tmp is on tmpfs

srcd=$(cd $(dirname $1) && pwd)
bn=$(basename $1)
test_tmpdir=$(mktemp -d /var/tmp/tap-test.XXXXXX)
function cleanup () {
  if test -z "${TEST_SKIP_CLEANUP:-}"; then
    if test -f ${test_tmpdir}/.test; then
      rm "${test_tmpdir}" -rf
    fi
  else
    echo "Skipping cleanup of ${test_tmpdir}"
  fi
}
trap cleanup EXIT
cd ${test_tmpdir}
touch .test
${srcd}/${bn} -k --tap
