#!/bin/sh

# Wrapper script for running jsunit test

# 1: path to perl exe
# 2: to perl thunderbird exe
# 3 - n parameters to thunderbird

TMPFILE=jsunit.result
perlpath=$1
tbpath=$2
shift 2

if [ "$OSTYPE" = "msys" ]; then
  ## Special handling for Windows (msys): get native Windows path from msys path
  cwd=$(pwd)

  cd $(dirname ${perlpath})
  plPath=$(pwd -W | sed 's/\//\\\\/g')
  perlpath=$plPath\\\\$(basename ${perlpath}).exe
  cd $cwd
fi

PL_PATH=${perlpath} "${tbpath}" "$@" | tee ${TMPFILE}
echo ""

if [ `grep -c "^TestResult: failed   : 0" ${TMPFILE}` -eq 0 ]; then
  echo "========================================="
  echo "Tests failed"
  echo "Testfile: "`pwd`"/${TMPFILE}"
  echo "========================================="
  echo ""
  #grep -v Succeed ${TMPFILE}
  egrep 'TestResult:|Error:|Succeed.*OK|Executing sub-test' ${TMPFILE}
  echo ""
  echo "Testfile: "`pwd`"/${TMPFILE}"
  res=1
else
  echo "========================================="
  echo "All tests succeeded"
  echo "========================================="
  rm -f ${TMPFILE}
  res=0
fi

exit ${res}
