#!/bin/bash

failures=0

cd "$( dirname "${BASH_SOURCE[0]}" )"
cd ../
source ./localize.sh

function run_step    { >&2 echo -e "\033[1m\033[34m* $1\033[0m"; }
function run_substep { >&2 echo -e "\033[1m\033[36m* $1\033[0m"; }
function run_success { >&2 echo -e "\033[1m\033[32m* $1\033[0m"; }

run_step "Starting Mapnik tests"

run_substep "Running C++ Unit tests..."
./test/unit/run
failures=$((failures+$?))

run_substep "Running standalone C++ tests..."
if [ -n "$(find test/standalone/ -maxdepth 1 -name '*-bin' -print -quit)" ]; then
    for FILE in test/standalone/*-bin; do 
        ${FILE};
      failures=$((failures+$?))
    done
fi

run_substep "Running visual tests..."
if [ -z "$JOBS" ]; then
    JOBS=1
fi
./test/visual/run -j $JOBS
failures=$((failures+$?))

exit $failures
