559 lines (524 with data), 16.1 kB
#!/bin/bash
#############################################################
# testlurch
#
# A bash script to (a) get the latest lurch source code from
# Sourceforge's svn repository, (b) run all of the built-in
# lurch test programs, (c) run all of the Qt script tests,
# (d) recompile all utilities and (e) rebuild the doxygen
# documentation.
#
# Syntax: testlurch [options]
#
# where [options] can be any of the following
#
# -l <lurchbasefolder>
#
# where <lurchbasefolder> is the local folder where svn puts the
# Lurch code. If this option is not specified the script looks for
# an environment variable $lurchbase and uses that, otherwise
# a default of ~/ is used. If the directory specified
# does not exist an error is returned.
#
# -v show version
#
# -h show this help file
#
# -s fetch the latest Lurch from svn
#
# -t run all Lurch tests
#
# -r rebuild the utils and tests
#
# -d run doxygen to make the docs
#
# -c run "make clean" on all util and test folders
#
# -q run quietly. Supresses most compiler and doxygen messages
#
# These options can appear in any combination. In addition there are two special
# invocations. The command
#
# testlurch
#
# with no arguments is equivalent to
#
# testlurch -c -s -r -t -d
#
# and the command
#
# testlurch -q
#
# is equivalent to
#
# testlurch -c -s -r -t -d -q
#
#############################################################
##################################
# Process options to this script
##################################
showversion=false
getcode=false
runtests=false
rundox=false
cleanup=false
rebuild=false
quiet=false
help=false
while getopts "vstrdcqhl:" option; do
[ $option = "v" ] && showversion=true
[ $option = "s" ] && getcode=true
[ $option = "t" ] && runtests=true
[ $option = "r" ] && rebuild=true
[ $option = "d" ] && rundox=true
[ $option = "c" ] && cleanup=true
[ $option = "q" ] && quiet=true
[ $option = "h" ] && help=true
[ $option = "l" ] && lurchbase=$OPTARG
if [[ ($option == '?') || ($option == "h") ]] ; then
echo
echo "NAME"
echo " testlurch - fetch, compile, and test the Lurch project code"
echo
echo "SYNTAX"
echo
echo " testlurch [options]"
echo
echo "Available options:"
echo " -v Show version"
echo " -h Show this help information"
echo " -s Get code from SVN"
echo " -t Run all tests"
echo " -r Rebuild all code"
echo " -d Make Doxygen docs"
echo " -c Clean all folders"
echo " -q Run quietly"
echo " -l dirname Specify Lurch folder"
echo
exit 0
fi
done
# two special cases: no arguments or just -q
if ! ( $showversion || $getcode || $runtests || $rebuild || $rundox || $cleanup ); then
getcode=true
runtests=true
rundox=true
cleanup=true
rebuild=true
fi
# make sure they want to clean!!
if $cleanup ; then
echo "Cleaning all folders and rebuilding will take a very long time."
read -p "Are you sure you want to clean all folders? <y/n> " prompt
if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]] ; then
echo ""
else
echo ""
echo "testlurch was canceled by the user."
exit 1
fi
fi
# if lurchbase was already set (by an option or env var)
# then keep it, otherwise give it a default
# Note: the path should include the final / character
if [ ! "$lurchbase" ] ; then
lurchbase=~/
fi
# define the other paths
docpath=${lurchbase}Lurch/
libpath=${lurchbase}Lurch/branches/qt-wp/libraries/
testpath=${lurchbase}Lurch/branches/qt-wp/tests/
doctests=${testpath}doc_tests/
validationtests=${testpath}validation-tests/
scriptpath=${testpath}script_tests/
utilpath=${lurchbase}Lurch/branches/qt-wp/utils/
simplescriptpath=${utilpath}simple_script/
doctestpath=${utilpath}doctest/
lurchutils=${lurchbase}Lurch/branches/qt-wp/libraries/jsutils/lurchutils.js
lurch=${utilpath}Lurch/Lurch
#############################################################################
#############################################################################
# Define useful functions
#############################################################################
#############################################################################
#############################################################################
# getcodefromsvn
#############################################################################
# check out the code from svn
function getcodefromsvn {
cd "$lurchbase"
echo "----------------------------------"
echo "Getting latest Lurch code from svn"
echo "----------------------------------"
if [ -d $lurchbase/Lurch ] ; then
echo $lurchbase"Lurch exists, so doing svn update Lurch"
if ! svn update Lurch ; then
echo "------------------------------------------------"
echo "FAIL: unable to update Lurch code from svn"
echo "------------------------------------------------"
exit 1
fi
else
echo "$lurchbase/Lurch does not exist, so doing svn checkout https://..."
if ! svn checkout https://lurch.svn.sourceforge.net/svnroot/lurch . ; then
echo "------------------------------------------------"
echo "FAIL: unable to checkout Lurch code from svn"
echo "------------------------------------------------"
exit 1
fi
fi
}
#############################################################################
# makedocs
#############################################################################
# run doxygen
function makedocs {
cd "$docpath"
# check that there is a Doxyfile
if [ -f "$docpath/Doxyfile" ]; then
if $quiet; then
doxygen 1>>/dev/null 2>>/dev/null
else
doxygen
fi
echo
echo "-----------------------------------------------------"
echo "Doxygen successfully rebuilt the latest documentation"
echo "-----------------------------------------------------"
else
echo "ERROR: missing Doxyfile!"
exit 1
fi
}
#############################################################################
# cleanall
#############################################################################
# clean all test and util folders
function cleanall {
cd "$testpath"
echo
echo "---------------------------------------------------------------------"
echo "Cleaning all test folders in "
echo " "$testpath
echo "---------------------------------------------------------------------"
# loop through all of the test subfolders
for testname in test_*; do
cd "$testname"
# if there is no Makefile, there is nothing to clean
if [ -f Makefile ]; then
if ! $quiet; then
echo
fi
echo "Cleaning folder "$testname
echo "-------------------------------"
if $quiet; then
make clean 1>>/dev/null 2>>/dev/null
else
make clean
fi
fi
cd ..
done
cd "$utilpath"
echo
echo "---------------------------------------------------------------------"
echo "Cleaning all utility folders in "
echo " "$utilpath
echo "---------------------------------------------------------------------"
# loop through all of the util subfolders
for utilname in *; do
if [ -d "$utilname" ]; then
cd "$utilname"
# if there is no Makefile, there is nothing to clean
if [ -f Makefile ]; then
if ! $quiet; then
echo
fi
echo "Cleaning folder "$utilname
echo "-------------------------------"
if $quiet; then
make clean 1>>/dev/null 2>>/dev/null
else
make clean
fi
fi
cd ..
fi
done
}
#############################################################################
# rebuild_all
#############################################################################
declare -i failedcmps
failedcmps=0
declare -a badcmps
# remake all the util folders and test folders
function rebuild_all {
cd "$utilpath"
echo
echo "---------------------------------------------------------------------"
echo "Remaking all utilities in "
echo " "$utilpath
echo "---------------------------------------------------------------------"
# loop through all of the util subfolders
for utilname in *; do
if [ -d "$utilname" ]; then
cd "$utilname"
if $quiet; then
echo -n "Rebuilding "${utilname}" ... "
qmake -Wnone QMAKE_CXXFLAGS_WARN_ON=-w
if ! make --quiet 2>>/dev/null; then
badcmps[$failedcmps]="$utilname"
failedcmps+=1
fi
echo " done."
else
echo
echo "Rebuilding "+$utilname+" ... "
qmake QMAKE_CXXFLAGS_WARN_ON=-w
if ! make; then
badcmps[$failedcmps]="$utilname"
failedcmps+=1
fi
echo "... done."
fi
cd ..
fi
done
# loop through all of the test subfolders
cd "$testpath"
echo
echo "---------------------------------------------------------------------"
echo " Rebuilding all tests in "
echo " "$testpath
echo "---------------------------------------------------------------------"
for testname in test_*; do
if [ -d "$testname" ]; then
cd "$testname"
if $quiet; then
echo -n "Rebuilding "${testname}" ... "
qmake -Wnone QMAKE_CXXFLAGS_WARN_ON=-w 2>>/dev/null
if ! make --quiet 2>>/dev/null; then
if ! make; then
badcmps[$failedcmps]="$testname"
failedcmps+=1
fi;
fi
echo " done."
else
echo
echo "Rebuilding "${testname}" ... "
qmake QMAKE_CXXFALGS_WARN_ON=-w
if ! make; then
badcmps[$failedcmps]="$testname"
failedcmps+=1
fi
echo "... done."
fi
cd ..
fi
done
}
#############################################################################
# runalltests
#############################################################################
declare -i failedtests
failedtests=0
declare -a badtests
# run all test scripts and save the output to a file for later use
function runalltests {
cd "$testpath"
echo
echo "---------------------------------------------------------------------"
echo "Running all tests in "
echo " "$testpath
echo "---------------------------------------------------------------------"
for testname in test_*; do
cd "$testname"
echo
if ! xvfb-run "${testpath}$testname/$testname" 2> /dev/null; then
if ! "${testpath}$testname/$testname"; then
badtests[$failedtests]="$testname"
failedtests+=1
fi
fi
cd ..
done
# run the doctest document tests
echo
cd $doctests
for testname in *.lurch; do
echo
if ! ${doctestpath}doctest -P$libpath "$testname"; then
badtests[$failedtests]="doctest ($testname)"
failedtests+=1
fi
done
echo
# run the script tests with simple_script
cd "$scriptpath"
echo
echo "---------------------------------------------------------------------"
echo "Running all script tests in "
echo " "$scriptpath
echo "---------------------------------------------------------------------"
for scriptname in test_*.js; do
echo
if $quiet; then
qarg="quiet=true"
else
qarg="quiet=false"
fi
scriptargs="-D$qarg"
if ! "${simplescriptpath}simple_script" --batch "$scriptargs" < "$scriptname"; then
echo "*************************"
echo " "$scriptname
echo "*************************"
echo "FAIL! : test script "$scriptname" did not run successfully."
echo "*************************"
badtests[$failedtests]="$scriptname"
failedtests+=1
fi
done
# run the validation tests
cd "$validationtests"
echo
echo "---------------------------------------------------------------------"
echo "Running all validation tests in "
echo " "$validationtests
echo "---------------------------------------------------------------------"
for testfile in test_*.lurch; do
echo
if ! xvfb-run "$lurch" --batch --test-validation "${validationtests}$testfile"; then
echo "*************************"
echo " "$testfile
echo "*************************"
echo "FAIL! : validation test file "$testfile" did not run successfully."
echo "*************************"
badtests[$failedtests]="$testfile"
failedtests+=1
fi
done
}
#############################################################################
# Carry out our orders
#############################################################################
# Define the file to save the results and errors and clean out the previous results
resultsfile=${lurchbase}.last_results.txt
errorfile=${lurchbase}.last_errors.txt
echo -n "" > $resultsfile
echo -n "" > $errorfile
# show the version number if requested
if $showversion; then
echo
echo 'Welcome to testlurch: version 1.1 (Authentic Addams)'
fi
# check that the lurchbase folder exists. If not, exit.
if [ -d "$lurchbase" ]; then
if ! $quiet; then
echo >> $resultsfile
echo "Using Lurch base folder "$lurchbase >> $resultsfile
fi
else
echo
echo "Lurch base folder does not exist"
exit 1
fi
# Clean if we must and have something to clean
if $cleanup && [ -d "$testpath" ]; then
echo >> $resultsfile
echo "Cleaning all folders... " >> $resultsfile
cleanall >> $resultsfile 2>> $errorfile
fi
# fetch the code if we must
# note that we leave recompiling to the run_test.sh scripts
if $getcode; then
echo >> $resultsfile
# "Fetching latest Lurch code ... " >> $resultsfile
getcodefromsvn >> $resultsfile 2>> $errorfile
fi
# recompile the tests if we must
if $rebuild; then
echo >> $resultsfile
echo "Rebuilding all tests and utilities ... " >> $resultsfile
# check that there is something to run
if [ -d "$testpath" ]; then
rebuild_all >> $resultsfile 2>> $errorfile
else
echo "ERROR: nothing to run!" >> $errorfile
exit 1
fi
fi
# run the tests if we must
if $runtests; then
echo >> $resultsfile
echo "Running all tests ... " >> $resultsfile
# check that there is something to run
if [ -d "$testpath" ]; then
runalltests 2>> $errorfile >> $resultsfile
else
echo "ERROR: nothing to run!" >> $errorfile
exit 1
fi
fi
# make the docs if we must
if $rundox; then
echo >> $resultsfile
echo "Building Doxygen documentation ... " >> $resultsfile
# check that there is a Doxyfile
if [ -f "$docpath/Doxyfile" ]; then
makedocs >> $resultsfile 2>> $errorfile
else
echo "ERROR: missing Doxyfile!" >> $errorfile
exit 1
fi
fi
if $runtests && [ $failedcmps -eq 0 ] && [ $failedtests -eq 0 ]; then
echo
echo "All Lurch tests: PASSED."
fi
if [ $failedcmps -ne 0 ]; then
echo
echo "The following compilations FAILED:"
printf " %s\n" "${badcmps[@]}"
fi
if [ $failedtests -ne 0 ]; then
echo
echo "The following tests FAILED:"
printf " %s\n" "${badtests[@]}"
fi
failfile=${lurchbase}.last_fails.txt
grep "^FAIL!\|^[[:space:]]*QDEBUG[[:space:]]*:.*NOTE:\|^[[:space:]]*Actual\|^[[:space:]]*Expected\|^[[:space:]]*Loc" < $resultsfile | sed '/^[[:space:]]*Loc/G' > $failfile
if [ -s $failfile ]; then
echo
echo "===================================="
echo " SUMMARY OF FAILED TESTS "
echo "===================================="
echo
cat $failfile
fi
if [ -e $failfile ]; then
rm $failfile
fi
if [ -s $errorfile ]; then
echo
echo "===================================="
echo " ALL of the Gory Errors "
echo "===================================="
cat $errorfile
echo
fi;
if [ -s $resultsfile ]; then
echo
echo "===================================="
echo " Non-error Details "
echo "===================================="
cat $resultsfile
fi
if $runtests || $rebuild ; then
echo
echo "Failed: Compilations "$failedcmps", Tests "$failedtests
fi
if [ -s $errorfile ]; then
exit 1
fi