1# Copyright (C) 2003, 2004, 2005, 2006, 2008, 2012 2# Rocky Bernstein <rocky@gnu.org> 3# 4# This program is free software: you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation, either version 3 of the License, or 7# (at your option) any later version. 8# 9# This program is distributed in the hope that it will be useful, 10# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# GNU General Public License for more details. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program. If not, see <http://www.gnu.org/licenses/>. 16# 17# Common routines and setup for regression testing. 18SKIP_TEST_EXITCODE=77 19 20# Some output changes depending on TZ and locale. Set this so we get known 21# results 22TZ=CUT 23# both 'en_US' and 'en_US.utf8' might be defined on some platforms 24if locale -a >/dev/null 2>&1 ; then 25 # Note: Solaris 10's shell can't handle $(..) so we use `...` 26 LC_TIME=`locale -a | grep 'en_US' | grep -v 'utf8' | grep -v 'iso88591' &2>/dev/null` 27fi 28[ -z "$LC_TIME" ] && { 29 LC_TIME=${LC_TIME:-en_US} 30}>/dev/null 2>&1 31 32export TZ LC_TIME 33 34DIFF="@DIFF@" 35DIFF_OPTS="@DIFF_OPTS@" 36RM="@RM@" 37 38check_result() { 39 RC=$1 40 shift 41 msg=$1 42 shift 43 cmdline="$cmd $*" 44 if test $RC -ne 0 ; then 45 if test $RC -ne $SKIP_TEST_EXITCODE ; then 46 echo "$0: $msg failed." 47 if test -n "$cmdline" ; then 48 echo "$0: failed command:" 49 echo " $cmdline" 50 fi 51 exit $RC 52 else 53 echo "-- $0: $msg skipped." 54 fi 55 else 56 echo "-- $0: $msg ok." 57 fi 58} 59 60test_common() { 61 62 cmdname="$1" 63 cmd="../src/${cmdname}@EXEEXT@" 64 opts="$2" 65 outfile="$3" 66 rightfile="$4" 67 68 if [ ! -x "${cmd}" ]; then 69 echo "-- $0: No ${cmd}" 70 return 1 71 fi 72 73 cmdline="${cmd}" 74 if "${cmd}" --no-header ${opts} >"${outfile}" 2>&1 ; then 75 if test "@DIFF@" != no; then 76 if @DIFF@ @DIFF_OPTS@ "${outfile}" "${rightfile}" ; then 77 rm -f "${outfile}" 78 return 0 79 else 80 return 3 81 fi 82 else 83 echo "$0: No diff(1) or cmp(1) found - cannot test ${cmdname}" 84 rm -f "${outfile}" 85 return $SKIP_TEST_EXITCODE 86 fi 87 else 88 echo "$0 failed running: ${cmdname} ${opts}" 89 return 2 90 fi 91 92} 93 94test_cdinfo() { 95 test_common cd-info "$@" 96} 97 98test_iso_info() { 99 test_common iso-info "$@" 100} 101 102test_cd_read() { 103 test_common cd-read "$@" 104} 105 106test_iso_read() { 107 108 # not test_common, as we use an output file not stdout. 109 110 opts="$1" 111 outfile="$2" 112 rightfile="$3" 113 114 ISO_READ="../src/iso-read@EXEEXT@" 115 116 if [ ! -x ${ISO_READ} ]; then 117 echo "-- $0: No ${ISO_READ}" 118 return 1 119 fi 120 121 if "${ISO_READ}" ${opts} -o "${outfile}" 2>&1 ; then 122 if test "@DIFF@" != no; then 123 if @DIFF@ @DIFF_OPTS@ "${outfile}" "${rightfile}" ; then 124 rm -f "${outfile}" 125 return 0 126 else 127 return 3 128 fi 129 else 130 echo "$0: No diff(1) or cmp(1) found - cannot test ${ISO_READ}" 131 rm -f "${outfile}" 132 return 77 133 fi 134 else 135 echo "$0 failed running: ${ISO_READ} ${opts} -o ${outfile}" 136 return 2 137 fi 138 139} 140 141test_legal_header() { 142 143 cmdname="$1" 144 cmd="../src/${cmdname}@EXEEXT@" 145 opts="$2" 146 outfile="$3" 147 148 if test "@GREP@" = no; then 149 echo "$0: No grep(1) found - cannot test ${cmd}." 150 echo "$0: Legal header test skipped." 151 exit $SKIP_TEST_EXITCODE 152 fi 153 "${cmd}" ${opts} > ${outfile} 2>&1 154 while read line; do 155 @GREP@ "${line}" ${outfile} >/dev/null 2>&1 156 if [ "$?" -ne 0 ] ; then 157 echo "$0: Legal header test failed due to missing expected line:" 158 echo " ${line}" 159 echo "$0: Failed command:" 160 echo " ${cmd} ${opts}" 161 exit 4 162 fi 163 done < ${srcdir}/check_legal.regex 164 rm -f ${outfile} 165 echo "-- $0: Legal header of ${cmd} ${opts} ok." 166 167} 168 169#;;; Local Variables: *** 170#;;; mode:shell-script *** 171#;;; eval: (sh-set-shell "bash") *** 172#;;; End: *** 173