Skip to content
Snippets Groups Projects
run_tests 3 KiB
Newer Older
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
#!/bin/zsh
# vim: set shiftwidth=4 softtabstop=4:
#
# This script is used to run tests on a database with demo data installed.
#
# Either provide the name of the database (first argument) or it will default to <project>_test
# The DB user can be overriden by setting ODOO_SCRIPTS_DB_USER.
here=$(dirname $0)
project_home=$(cd $here && cd .. && echo $PWD)
tested_modules=$(python -B -c "import ConfigParser ; c = ConfigParser.ConfigParser() ; c.read('${project_home}/setup.cfg') ; print ','.join(c.get('odoo_scripts', 'module_list_tests', '').split())")
if [[ "$tested_modules" != "" ]];
then 
    update="-u $tested_modules"
fi
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
dbname=$1
if [[ -z "$dbname" ]];
then
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
else
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
fi
if [[ -n "$ODOO_SCRIPTS_DB_USER" ]]
then
    echo "Using db user $ODOO_SCRIPTS_DB_USER"
    db_user_param="--db_user $ODOO_SCRIPTS_DB_USER"
fi

ODOO_TYPE=$(python -B -c "import ConfigParser ; c = ConfigParser.ConfigParser() ; c.read('${project_home}/setup.cfg') ; print c.get('odoo_scripts', 'odoo_type', 'odoo8')")
if [ "$ODOO_TYPE" = "odoo8" ];
then
    loglevel="--log-level=info"
else
    loglevel="--log-level=test"
fi
logfile=$(tempfile --suffix=.log)
# Catch both stdout & stderr here as Odoo 10 uses stderr, unlike previous Odoo versions.
$here/start $update -d $dbname $db_user_param  --test-enable $loglevel --max-cron=0 --stop-after-init $* 2>&1 | tee $logfile | sed -e 's/\(.*\) \(INFO\) \(.*\)/\o033[2m\1\o033[22m \o033[32m\o033[7m\2\o033[27m \3\o033[39m/' -e 's/\(.*\) \(DEBUG\) \(.*\)/\1 \o033[33m\o033[7m\2\o033[27m \2\o033[39m/' -e 's/\(.*\) \(WARNING\) \(.*\)/\o033[2m\1\o033[22m \o033[33m\o033[7m\2\o033[27m \3\o033[39m/' -e 's/\(.*\) \(ERROR\) \(.*\)/\1 \o033[31m\o033[7m\2\o033[27m \3\o033[0m/' -e 's/\(.*\) \(TEST\) \(.*\)/\1 \o033[34m\o033[7m\2\o033[27m \3 \o033[0m/' -e 's/ FAILED/ \o033[41m\o033[97m\o033[1mFAILED\o033[0m/' -e 's/ FAIL\(.*\)/ \o033[41m\o033[97m\o033[1mFAIL\o033[49m\o033[31m\1\o033[0m/' -e 's/\(.*\) \(CRITICAL\) \(.*\)/\o033[2m\1\o033[22m \o033[33m\o033[7m\2\o033[27m \3\o033[39m/'
ok=$(grep ' OK' $logfile -c)
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
# TODO detect yaml tests failures
failed=$(grep ' FAILED| CRITICAL' $logfile -c)
if [[ $failed -eq 0 ]];
then
    # simple way to detect yaml failure
    failed=$(grep 'openerp.modules.loading: At least one test failed when loading the modules.' $logfile -c)
fi
echo '\e[2m*****\e[22m \e[1mTest results\e[21m \e[2m*****\e[22m'
echo "$ok modules passing, $failed modules failing"
echo ''
    echo -e '\033[32mOK:\033[0m'

    # Highlight the "OK"s in green (32).
    GREP_COLOR='0;32' grep --color=always ' OK' $logfile || true
if [[ $failed -gt 0 ]];
then
    echo -e '\033[31mFAILED\033[0m:'

    # Highlight the failure matches in red (31).
    GREP_COLOR='0;31' grep --color=always "CRITICAL\|FAILED\|FAIL:" $logfile
    GREP_COLOR='0;31' grep --color=always "ERROR [^ ]* openerp\.tools\.yaml_import:" $logfile
echo ''
rm $logfile
if [[ $failed -gt 0 ]];
then
    exit 1
fi