#!/bin/sh -e
# Run all Apport self tests.
# Call without arguments to test the system instance, or with "local" to test
# the sources in the local tree.

if [ "$1" = local ]; then
    export PYTHONPATH=.
    export APPORT_CRASHDB_CONF=./etc/apport/crashdb.conf
    basedir=.
    local=1

    if [ ! -e apport/packaging_impl.py ]; then
	echo "You need to copy an appropriate packaging implementation from backends/ to apport/packaging_impl.py; run './setup.py build' for auto-detection." >&2
	exit 1
    fi
else
    basedir=`python -c 'import os.path; import problem_report; print os.path.dirname(problem_report.__file__)'`
    unset local
fi

mydir=`dirname "$0"`

set -x
python -tt $basedir/problem_report.py -v
python -tt $basedir/apport/fileutils.py -v
python -tt $basedir/apport/report.py -v
python -tt $basedir/apport/hookutils.py -v
python -tt $basedir/apport_python_hook.py -v
python -tt $basedir/apport/ui.py -v
python -tt $basedir/apport/REThread.py -v
python -tt $basedir/apport/chroot.py -v
python -tt $basedir/apport/crashdb_impl/memory.py -v
python -tt $basedir/apport/packaging_impl.py -v

if [ "$local" ]; then
    $mydir/hooks -l
else
    $mydir/hooks
fi

if [ "$local" ]; then
    $mydir/crash-digger
    python $mydir/../data/general-hooks/parse_segv.py -v
else
    python $mydir/../general-hooks/parse_segv.py -v
fi

$mydir/crash
