diff options
Diffstat (limited to 'test/Execute-Tests')
-rwxr-xr-x | test/Execute-Tests | 134 |
1 files changed, 100 insertions, 34 deletions
diff --git a/test/Execute-Tests b/test/Execute-Tests index 104853e5..9cbbe63f 100755 --- a/test/Execute-Tests +++ b/test/Execute-Tests @@ -2,11 +2,11 @@ # Confirm that PBM_TESTPREFIX is set. # PBM_TESTPREFIX is the directory with the Netpbm programs you want to -# test. This can be null, but this is not recommended. +# test. If set to null, executables will be sought from the default +# execution path ($PATH). Usually you should explicitly set this. # -# You can set it here by decommenting and modifying the next line: -# export PBM_TESTPREFIX="/usr/local/bin/" - +# You can set it here by de-commenting and modifying the next line: +#export PBM_TESTPREFIX="/usr/local/bin/" if [ -z $PBM_TESTPREFIX ] then @@ -20,7 +20,7 @@ elif [ ! -d $PBM_TESTPREFIX ] exit 1 else # append "/" to end of string if necessary - export PBM_TESTPREFIX=`echo $PBM_TESTPREFIX | sed '/\/$/!s@$@/@'` + export PBM_TESTPREFIX=$(echo $PBM_TESTPREFIX | sed '/\/$/!s@$@/@') fi # Set PBM_BINPREFIX. @@ -30,7 +30,8 @@ fi # # If testing a fresh install, this should be the same as PBM_TESTPREFIX. # If you are developing a single Netpbm program, you may want to -# set this to a directory with stable executables. +# set this to a directory with stable executables. (Final "/" is +# mandatory.) # If set to null, executables in the default execution path will # be used. @@ -47,19 +48,35 @@ if [ ! -z $PBM_BINPREFIX ] export PATH=${PBM_BINPREFIX}:$PATH fi -# Set tmpdir, which is used in some of the test scripts. -# This must be an existing directory. +# Set srcdir, which is the directory which contains Execute-Tests +# (this script), Test-Order *.test and *.ok files. + +srcdir=$(dirname $0) + +# Set tmpdir, which is used in some of the test scripts. By default +# this is created by mktemp. The user can override and specify tmpdir, +# but in this case it must be an existing directory and must not be +# either $srcdir or current work. if [ -z $tmpdir ] then - if [ -z $TMPDIR ] - then - export tmpdir=/tmp/ - else - export tmpdir=$TMPDIR + tmpdir_created=$(mktemp -p "" -d TestPBM-XXXXXXX) || exit 1; + export tmpdir=${tmpdir_created} + else + tmpdir_created=""; + if [ ! -d ${tmpdir} ] + then echo "Specified temporary directory $tmpdir does not exist." + exit 1; + elif [ ${tmpdir} -ef ${srcdir} ] + then echo "Temporary directory must not be $srcdir." + exit 1; + elif [ ${tmpdir} -ef $PWD ] + then echo "Temporary directory must not be current directory." + exit 1; fi fi + # If necessary set the RGBDEF environment variable. #export RGBDEF=/etc/rgb.txt #export RGBDEF=/usr/local/netpbm/lib/rgb.txt @@ -67,47 +84,96 @@ fi # Declare arrays used to count and report test results. # For now only "SUCCESS" and "FAILURE" are used. -declare -a array=(0 0 0 0 0) -declare -a status=("SUCCESS" "FAILURE" "UNEXPECTED SUCCESS" \ - "EXPECTED FAILURE" "NOT SUPPORTED") +declare -a array=(0 0 0 0 0 0) +declare -a status=("SUCCESS" "FAILURE" "UNEXPECTED SUCCESS" + "EXPECTED FAILURE" "NOT SUPPORTED" "TOTAL SUPPORTED") + +# Copy test files to the current work directory + +cp -n -t . ${srcdir}/testgrid.pbm ${srcdir}/testimg.ppm # Execute the tests, as described in the "Test-Order" file. # -# To execute just one test, or a few tests, replace the grep part -# within backquotes with names of tests you want to run like this: -# -# for t in pbmmake.test pgmmake.test ppmmake.test +# Each test outputs a ".out" file, which is compared against a +# corresponding ".ok" file. For example the output from "pbmmake.test" +# is "pbmmake.out" and when this matches "pbmmake.ok" we declare the +# test a success. +# In the error case the ".out" file is retained in the current work +# directory. +# +# All tests are self-contained. +# +# By defeault the tests are executed in the order described in the +# file Test-Order. Normally the Test-Order in the source directory +# will be used, but the user can override this with a file named +# Test-Order placed in the work directory. (This feature comes useful +# when you want to pare down the list.) + +if [ ! -f ./Test-Order ] +then cp ${srcdir}/Test-Order ./Test-Order +fi -for t in `grep -v "^#" Test-Order | grep "."` +for t in `grep -v "^#" ./Test-Order | fgrep ".test"` do echo == $t == -./$t > ${t%.test}.out ; let result=$? +${srcdir}/$t > ${t%.test}.out ; let result=$? case $result in -0) cmp --quiet ${t%.test}.out ${t%.test}.ok ; +0) cmp --quiet ${t%.test}.out ${srcdir}/${t%.test}.ok ; if [ $? -eq 0 ] then let result=0; rm ${t%.test}.out ; else let result=1; - fi ;; -1 | 2 | 3 ) ;; -*) let result=1 ;; + fi + let supported=1 ;; +*) let result=1 ; let supported=1;; esac -# Print out a summary report. + +# Report whether a single test succeeded or failed. +# Increment counters. echo $t: ${status[${result}]}; echo let array[${result}]=${array[${result}]}+1 +let array[5]=${array[5]}+$supported + done + +# Erase temporary directory and its contents, if it was created. + +if [ -n $tmpdir_created ] + then rm -rf $tmpdir_created +fi + + +# Erase test image files in the current (work) directory. +# (Do not erase them if we are working from the source directory.) + +if [ ! $PWD -ef ${srcdir} ] + then rm ./testimg.ppm ./testgrid.pbm +fi + + +# Calculate success / failure totals and print a summary report. +# Report date and time of completion. + echo "Test summary:" echo ================== -for s in 0 1 2 3 4 -do -if [[ ${array[${s}]} -gt 0 || s -eq 1 ]] -then -echo ${status[${s}]} ${array[${s}]} -fi -done +for s in 0 1 2 3 4 5 + do + if [[ ${array[${s}]} -gt 0 || s -eq 1 ]] + then echo ${status[${s}]} ${array[${s}]} + fi + done echo ================== echo "All tests done." +date --rfc-3339=seconds + + +# Exit with status 0 if all supported tests succeeded, 1 otherwise. + +if [[ ${array[0]} -eq ${array[5]} ]] +then exit 0 +else exit 1 +fi |