#!/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.

# Copyright (C) 2007 - 2009 Canonical Ltd.
# Author: Martin Pitt <martin.pitt@ubuntu.com>
# 
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.  See http://www.gnu.org/copyleft/gpl.html for
# the full text of the license.

if [ "$1" = local ]; then
    export PYTHONPATH=.
    export APPORT_CRASHDB_CONF=./etc/apport/crashdb.conf
    export APPORT_DATA_DIR=./data
    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
    unset local
fi

mydir=`dirname "$0"`

modules="problem_report
apport/fileutils
apport/report
apport/hookutils 
apport_python_hook
apport/ui
apport/REThread
apport/crashdb_impl/memory
apport/packaging_impl
"

for m in $modules; do
    echo "--- Testing $m ---"
    if [ -n "$local" ]; then
	${PYTHON:=python} -tt ./${m}.py -v
    else
	${PYTHON:=python} -tt -m $m -v
    fi
done

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

if [ "$local" ]; then
    $mydir/java
fi

$mydir/crash
