#!/usr/bin/bash

die() { echo "$*" 1>&2 ; exit 1; }

export XPRA_NOTTY=1
export XPRA_UTIL_DEBUG=${XPRA_UTIL_DEBUG:-0}
export XPRA_TEST_DEBUG=${XPRA_TEST_DEBUG:-0}
export XPRA_HIDE_SUBPROCESS_OUTPUT=${XPRA_HIDE_SUBPROCESS_OUTPUT:-1}
#SAVED_PYTHONPATH=$PYTHONPATH

UNITTESTS_DIR=`dirname $(readlink -f $0)`
SRC_DIR=`dirname $UNITTESTS_DIR`

INSTALL_ROOT="$SRC_DIR/dist/python2"
pushd $SRC_DIR
python2 ./setup.py install --without-nvenc --with-scripts --home=$INSTALL_ROOT || die "failed to build"
popd

export PATH=$INSTALL_ROOT/bin:$PATH
export XPRA_COMMAND=$INSTALL_ROOT/bin/xpra
export XPRA_CONF_DIR=$INSTALL_ROOT/etc/xpra/

pushd $UNITTESTS_DIR
export PYTHONPATH=`ls -d $INSTALL_ROOT/lib*/python`:`pwd`
python2 ./unit/run.py "$@"
popd
