#!/bin/bash

echo "
 #########################
      Extension Tests
 #########################"

cd "$(dirname "$0")"

has_py_coverage=false
py_cover_files=$( mktemp )

if coverage.py -e >/dev/null 2>/dev/null; then
  has_py_coverage=true
  cover_py_cmd=coverage.py
else
  if coverage -e >/dev/null 2>/dev/null; then
    has_py_coverage=true
    cover_py_cmd=coverage
  fi
fi

#if $has_py_coverage; then
#  $cover_py_cmd -e
#fi

function run_py_test() {
  echo -e "\n>> Testing $1"
  if $has_py_coverage; then
    $cover_py_cmd -x "$1.test.py"
    echo "../$1.py" >> $py_cover_files
  else
    python "$1.test.py"
  fi
}

run_py_test svgcalendar
run_py_test foldablebox

echo ""
if $has_py_coverage; then
  cat $py_cover_files | xargs $cover_py_cmd -r
fi

rm $py_cover_files
