#! /bin/sh

# This is a script for the CGAL test suite. Such a script must obey
# the following rules:
#
# - the name of the script is cgal_test_with_cmake
# - for every target two one line messages are written to the file 'error.txt'
#     the first one indicates if the compilation was successful
#     the second one indicates if the execution was successful
#   if one of the two was not successful, the line should start with 'ERROR:'
# - running the script should not require any user interaction
# - the script should clean up object files and executables

  ERRORFILE=error.txt

#---------------------------------------------------------------------#
#                    remove the previous error file
#---------------------------------------------------------------------#

rm -f ../$ERRORFILE
touch ../$ERRORFILE

#---------------------------------------------------------------------#
#                    compile_and_run <target>
#---------------------------------------------------------------------#
echo "Configuring... "
mkdir build_dir
cd build_dir
if eval 'cmake --no-warn-unused-cli ${INIT_FILE:+"-C${INIT_FILE}"} -DRUNNING_CGAL_AUTO_TEST=TRUE  \
                                   -DCGAL_DIR="$CGAL_RELEASE_DIR" -DCGAL_ENABLE_TESTING=ON -DWITH_tests=ON \
                                   ..' ; then

  echo "   successful configuration" >> ../$ERRORFILE
else
  echo "   ERROR:    configuration" >> ../$ERRORFILE
fi
cd ..

#---------------------------------------------------------------------#
#                    configure, compile and run the tests
#---------------------------------------------------------------------#

cd build_dir
ctest -L Installation_Tests -VV |tee res.txt
SUCCES="y"
FAILED=$(cat res.txt|grep "\*\*\*Failed")
if [ -z "$FAILED" ]; then
  echo "   successful run of Installation tests" >> ../$ERRORFILE
else
  echo "   ERROR:    run of Installation tests" >> ../$ERRORFILE
  SUCCES=""
fi
cat ../$ERRORFILE
