3 # from ckmame:runtest,v 1.22 2005/12/27 09:41:51 dillo Exp
5 # runtest -- run regression tests
6 # Copyright (C) 2002-2007 Dieter Baron and Thomas Klausner
8 # This file is part of libzip, a library to manipulate ZIP archives.
9 # The authors can be contacted at <libzip@nih.at>
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in
18 # the documentation and/or other materials provided with the
20 # 3. The names of the authors may not be used to endorse or promote
21 # products derived from this software without specific prior
24 # THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
25 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
28 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
30 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
32 # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 # TESTNAME.test: test scenario
42 # Lines beginning with # are comments.
44 # The following commands are recognized; return and args must
45 # appear exactly once, the others are optional.
48 # run program with command line arguments ARGS
51 # description of what test is for
54 # copy file IN as TEST, compare against OUT after program run.
57 # copy file IN as TEST, check that it is removed by program.
60 # check that file TEST is created by program and compare
64 # create directory NAME with permissions MODE.
70 # RET is the expected exit code
73 # program is expected to produce the error message TEXT. If
74 # multiple stderr commands are used, the messages are
75 # expected in the order given.
78 # program is expected to print TEXT to stdout. If multiple
79 # stdout commands are used, the messages are expected in
83 # runtest uses the following exit codes:
87 # 77: test was skipped
89 # environment variables:
90 # VERBOSE: if set, be more verbose (e. g., output diffs)
91 # NOCLEANUP: if set, don't delete directory test is run in
100 if [ ! -z "${VERBOSE}" ]
102 echo "${TEST} -- FAILED: $*";
109 if [ ! -z "${VERBOSE}" ]
111 echo "${TEST} -- skipped: $*";
118 if [ ! -z "${VERBOSE}" ]
120 echo "${TEST} -- passed";
128 if [ -z "${NOCLEANUP}" ]
130 chmod -R u+rw ${DIR};
135 check_in_out_exists() {
138 fail "missing output file: '$2'"
141 die "cannot find input file '$1'"
146 check_in_out_exists "$1" "$2"
147 out=`../dbdump "$2" | sort | diff ${DIFF_FLAGS} "$1" -`
160 check_in_out_exists "$1" "$2"
161 out=`diff ${DIFF_FLAGS} "$1" "$2"`
173 check_in_out_exists "$1" "$2"
175 ${ZIPCMP} -t ${ZIPCMP_FLAGS} "$1" "$2" 2>/dev/null
185 die "directive $2 appeared twice in test file"
192 die "required directive $2 missing in test file"
201 die "source file '$src' does not exist"
211 # GNU sort behaves differently on locales other than C, breaking tests
215 #testdir=`dirname $1`
216 TEST=`echo $1 | sed -e s',.*/,,' -e 's/\.test$//'`
220 if [ -z "${srcdir}" ]
224 # XXX: fix for absolute srcdir?
228 if [ -z "${ZIPCMP}" ]
232 if expr "${ZIPCMP}" : '[^/].*/' > /dev/null
234 ZIPCMP="../${ZIPCMP}"
238 if [ -z "${VERBOSE}" ]
247 # XXX: set up trap to cleanup
249 mkdir ${DIR} || ( die "cannot create test directory ${DIR}" )
250 cd ${DIR} || ( die "cannot cd to test directory ${DIR}" )
267 test_empty "${ARGS}" args
270 test_empty "${DESCR}" description
275 FILES="${FILES} ${srcdir}/$3!$1";;
278 copy_file "$2" "$1";;
281 FILES="${FILES} ${srcdir}/$2!$1";;
284 mkdir "$2" && chmod "$1" "$2";;
288 test_empty "${RET}" return
291 echo "${PROGRAM}: $arg" >> stderr;;
293 echo "$arg" >> stdout;;
295 die "unknown directive '$cmd'"
299 test_set "${RET}" return
300 test_set "${ARGS}" args
302 if [ -z "${PROGRAM}" ]
304 die no program to run given
307 if [ ! -z "${SETUP_ONLY}" ]
313 if [ ! -z "${VERBOSE}" ]
315 echo "${TEST}: ${DESCR}"
316 echo "running: ${PROGRAM} ${ARGS}"
319 ${PROGRAM} ${ARGS} > gotout 2> goterr
322 if [ $ret -ne ${RET} ]
324 if [ ! -z "${VERBOSE}" ]
329 fail "unexpected exit status: got $ret, expected ${RET}"
332 FILES_SHOULD="${FILES_SHOULD} stderr stdout gotout goterr"
334 checkfile stderr goterr "unexpected error output"
335 checkfile stdout gotout "unexpected output"
337 if [ ! -z "${FILES}" ]
341 set -- `echo ${fs} | tr '!' ' '`
342 FILES_SHOULD="${FILES_SHOULD} $2"
345 checkdb "$1" "$2" "database $2 wrong";;
347 checkzip "$1" "$2" "zip file $2 wrong";;
349 checkfile "$1" "$2" "file $2 wrong";;
354 # check that no additional files exist
355 echo gotfiles shouldfiles ${FILES_SHOULD} | tr ' ' '\012' | sort > shouldfiles
357 find . -type f -print | sed 's!^./!!' | sort > gotfiles
359 checkfile shouldfiles gotfiles "unexpected/missing files"
363 } < ${srcdir}/${TEST}.test