1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
|
#!/bin/sh
#
# $Id: script_tests.sh,v 1.15 2010/12/28 20:18:40 dan Exp $
#
# Copyright (c) 2006, 2007, 2010 Dan McMahill
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by Dan McMahill
# 4. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
regen=no
noclean=no
usage() {
cat <<EOF
$0 -- Run automated tests on the scripts which are part of the
LaTeX-Mk package.
USAGE:
$0 -h|--help
$0 [options] [tests]
OPTIONS:
-h|--help Display this help message and exit
--noclean After running the test, do not remove the run directory
or the files contained there. This is useful for debugging
a failure.
-r|--regen Regenerate the 'golden' reference files. This option needs
to be used with caution. Any changes to the golden files
need to be verified by hand.
EOF
}
while test -n "$1"
do
case "$1"
in
-h|--help)
usage
exit 0
;;
--noclean)
noclean=yes
shift
;;
-r|--regen)
# regenerate the 'golden' output files. Use this with caution.
# In particular, all differences should be noted and understood.
regen=yes
shift
;;
-*)
echo "unknown option: $1"
exit 1
;;
*)
break
;;
esac
done
if [ "X$regen" = "Xyes" ]; then
sufx="ref"
else
sufx="log"
fi
LATEX_MK_DIR=${top_srcdir:-..}
LATEX_MK_DIR=`cd ${LATEX_MK_DIR} && echo $PWD`
export LATEX_MK_DIR
echo "LATEX_MK_DIR = $LATEX_MK_DIR"
# printenv
# golden directory
REF=latex_mk_ref
tmpdir=${TMPDIR:-/tmp}/latex-mk.$$
mkdir -m 0700 -p ${tmpdir}
rc=$?
if test $rc -ne 0 ; then
echo "Failed to create temp directory ${tmpdir}"
exit 1
fi
#######################################
#
# Here we have to clean out some environment variables
# which may mess up the test results
#
BIBTEX=bibtex
BIBTEX_FLAGS=
LATEX=latex
LATEX_FLAGS=
MAKEIDX=makeindex
MAKEIDX_FLAGS=
PDFLATEX=pdflatex
PDFLATEX_FLAGS=
TEX2PAGE=tex2page
TEX2PAGE_FLAGS=
export BIBTEX
export BIBTEX_FLAGS
export LATEX
export LATEX_FLAGS
export MAKEIDX
export MAKEIDX_FLAGS
export PDFLATEX
export PDFLATEX_FLAGS
export TEX2PAGE
export TEX2PAGE_FLAGS
# these should just not be set at all
LATEX_MK_LOG=x ; unset LATEX_MK_LOG
TEXMFOUTPUT=x ; unset TEXMFOUTPUT
TEXINPUTS=x ; unset TEXINPUTS
BIBINPUTS=x ; unset BIBINPUTS
#
#
#######################################
# make sure we have the right paths when running this from inside the
# source tree and also from outside the source tree.
here=${PWD}
here=`cd $here && echo $PWD`
srcdir=${srcdir:-$here}
srcdir=`cd $srcdir && echo $PWD`
rundir=${here}/run
if [ ! -d ${REF} ]; then
mkdir ${REF}
fi
TESTLIST=${srcdir}/script_tests.list
if [ ! -f $TESTLIST ]; then
echo "ERROR: ($0) Test list $TESTLIST does not exist"
exit 1
fi
# fail/pass/total counts
fail=0
pass=0
skip=0
tot=0
if test -z "$1" ; then
all_tests=`awk 'BEGIN{FS="|"} /^#/{next} /^[ \t]*$/{next} {print $1}' $TESTLIST | sed 's; ;;g'`
else
all_tests=$*
fi
echo "Starting tests in $here."
echo "Source directory is $srcdir"
echo "Syntax check on the shell scripts..."
sfail=0
spass=0
stot=0
for s in \
${here}/../ieee-copyout \
${here}/../latex-mk \
${srcdir}/run_tests.sh \
${srcdir}/script_tests.sh
do
echo "Script: ${s}"
sh -n ${s}
rc=$?
if test $rc -ne 0 ; then
echo "FAILED: return code = ${rc}"
sfail=`expr $sfail + 1`
else
spass=`expr $spass + 1`
echo "PASS"
fi
done
stot=`expr $sfail + $spass`
echo "latex-mk script tests..."
# See if we are running as root or not. If we are running as root we have
# to skip a few tests. The tests in question are ones where we try to write
# to a read only directory. root is allowed to go ahead and do this which
# throws off the tests.
for i in "${ID}" /usr/xpg4/bin/id /usr/bin/id /bin/id ; do
if test -x "${i}" ; then
ID="${i}"
break
fi
done
echo "Set ID=${ID}"
uid=`${ID} -u`
if test ${uid} -eq 0 ; then
root_user=yes
else
root_user=no
fi
for t in $all_tests ; do
grep "^[ \t]*${t}[ \t]*|" $TESTLIST >/dev/null
if test $? -ne 0 ; then
echo "$0: Error, specified test ${t} does not exist in ${TESTLIST}" >/dev/stderr
exit 1
fi
tot=`expr $tot + 1`
# test_name | directories to create | files needed | arguments to latex-mk | env vars
dirs=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | awk 'BEGIN{FS="|"} {print $2}'`
files=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | awk 'BEGIN{FS="|"} {print $3}'`
args=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | awk 'BEGIN{FS="|"} {print $4}'`
vars=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | awk 'BEGIN{FS="|"} {print $5}'`
ret=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | awk 'BEGIN{FS="|"} {print $6}' | sed 's; ;;g'`
root=`grep "^[ \t]*${t}[ \t]*|" $TESTLIST | awk 'BEGIN{FS="|"} {print $7}' | sed 's; ;;g'`
if test "X${root}" = "Xno" -a "X${root_user}" = "Xyes" ; then
echo "Skipping ${t} which will fail if run as root (and you are running as root)"
skip=`expr $skip + 1`
continue
fi
if test "X${ret}" = "X" ; then
ret=0
fi
# create temporary run directory
rm -fr ${rundir}
mkdir -p $rundir
# Create the subdirectories needed
if [ ! -z "$dirs" ]; then
for dir in $dirs ; do
d=`echo $dir | sed 's;:.*;;g'`
#echo "mkdir -p ${rundir}/${d}"
mkdir -p ${rundir}/${d}
done
fi
# Create the files needed
if [ ! -z "$files" ]; then
# this horrible ugly hack is supposed to deal with allowing file names that have
# spaces in them. Surely there is a better way but it eludes me at the moment.
cat > ${tmpdir}/files << EOF
for f in ${files} ; do
#echo "f = \"\${f}\""
echo "cp -f \"${srcdir}/texfiles/\${f}\" ${rundir}"
cp -f "${srcdir}/texfiles/\${f}" ${rundir}
done
EOF
#cat ${tmpdir}/files
. ${tmpdir}/files
fi
# Set the permissions on the subdirectories
if [ ! -z "$dirs" ]; then
for dir in $dirs ; do
d=`echo $dir | sed 's;:.*;;g'`
m=`echo $dir | awk 'BEGIN{FS=":"} {print $2}'`
if [ "X${m}" != "X" ]; then
#echo "chmod ${m} ${rundir}/${d}"
chmod ${m} ${rundir}/${d}
fi
done
fi
# run the test
echo "Test: $t"
testlog="/tmp/script_tests.$$$$"
#echo "cd ${rundir} && env ${vars} ${here}/../latex-mk --testlog ${testlog} $args"
# We redirect from /dev/null because if the latex installation isn't quite
# right we may end up with latex waiting for input from stdin but we don't
# ever want to do that. This is especially important since we are redirecting
# stdout and stderr so the user won't even see whats going on.
cat > ${tmpdir}/run << EOF
cd ${rundir} && env ${vars} ${here}/../latex-mk --testlog ${testlog} $args 2>&1 \
> ${here}/${REF}/${t}.dlog < /dev/null
rc=\$?
EOF
cat ${tmpdir}/run
. ${tmpdir}/run
if test $rc -ne $ret -a "X$regen" != "Xyes" ; then
echo "FAIL due to wrong return code. Received $rc, expected $ret"
fi
# take care of some absolute paths which may appear in the test log file.
if test -f ${testlog} ; then
sed -e "s;${here};HERE;g" -e "s;current directory:.*run;current directory: HERE/run;g" \
${testlog} > ${here}/${REF}/${t}.${sufx}
rm ${testlog}
else
echo "latex-mk returned $rc" > ${here}/${REF}/${t}.${sufx}
sed -e "s;${here};HERE;g" -e "s;current directory:.*run;current directory: HERE/run;g" \
${here}/${REF}/${t}.dlog >> ${here}/${REF}/${t}.${sufx}
fi
if [ "X$regen" != "Xyes" ]; then
if [ -f ${srcdir}/${REF}/${t}.ref ]; then
if diff -w ${srcdir}/${REF}/${t}.ref ${here}/${REF}/${t}.log >/dev/null ; then
echo "PASS"
pass=`expr $pass + 1`
else
echo "FAILED: See diff -w ${srcdir}/${REF}/${t}.ref ${here}/${REF}/${t}.log"
fail=`expr $fail + 1`
fi
else
echo "No reference file. Skipping"
skip=`expr $skip + 1`
fi
else
echo "Regenerated"
fi
cd $here
# clean up the rundirectory
chmod -R a+w ${rundir}
if test "X${noclean}" != "Xyes" ; then
rm -fr ${rundir}
else
echo "Keeping run directory ${rundir}"
fi
done
echo "LaTeX-Mk shell script syntax: Passed $spass, failed $sfail out of $stot tests."
echo "LaTeX-Mk latex-mk script: Passed $pass, failed $fail, skipped $skip out of $tot tests."
rc=0
if [ $spass -ne $stot ]; then
rc=1
fi
if [ $fail -ne 0 ]; then
rc=1
fi
rm -fr ${tmpdir}
exit $rc
|