msgndebug() { msgprintf "${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
msgtest() { msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
msgpass() { printf "${CPASS}PASS${CNORMAL}\n"; }
-msgskip() {
+msgreportheader() {
if [ -n "$MSGTEST_MSG" ]; then
+ test "$1" != 'msgfailoutput' || echo
+ if [ -n "$MSGTEST_MSGMSG" ]; then
+ echo "$MSGTEST_MSGMSG"
+ fi
+ if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
+ echo "${CFAIL}Part of the test group: $MSGTEST_GRP"
+ fi
echo -n "$MSGTEST_MSG"
unset MSGTEST_MSG
fi
+}
+msgskip() {
+ msgreportheader 'msgskip'
if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
}
msgfail() {
- if [ -n "$MSGTEST_MSG" ]; then
- if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
- echo "Part of the test group: $MSGTEST_GRP"
- fi
- echo -n "$MSGTEST_MSG"
- unset MSGTEST_MSG
- fi
+ msgreportheader 'msgfail'
if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
if [ -n "$APT_DEBUG_TESTS" ]; then
msgnwarn() { true; }
fi
if [ $MSGLEVEL -le 2 ]; then
- msgmsg() { true; }
+ msgmsg() {
+ MSGTEST_MSGMSG="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")"
+ }
msgnmsg() { true; }
msgtest() {
MSGTEST_MSG="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")"
aptmark) CMD="apt-mark";;
apthelper) CMD="apt-helper";;
aptftparchive) CMD="apt-ftparchive";;
+ dpkg) shift; runapt ${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg "$@"; return;;
*) CMD="$1";;
esac
shift
- runapt command gdb --quiet -ex run "${BUILDDIRECTORY}/$CMD" --args "${BUILDDIRECTORY}/$CMD" "$@"
+ if [ "${CMD##*/}" = "$CMD" ]; then
+ CMD="${BUILDDIRECTORY}/${CMD}"
+ fi
+ runapt command gdb --quiet -ex run "$CMD" --args "$CMD" "$@"
}
exitwithstatus() {
export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so"
fi
fi
-exec fakeroot dpkg --root="${TMPWORKINGDIRECTORY}/rootdir" \\
+exec fakeroot ${DPKG:-dpkg} --root="${TMPWORKINGDIRECTORY}/rootdir" \\
--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log \\
--force-not-root --force-bad-path "\$@"
EOF
- chmod +x "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
+ cat << EOF > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg"
+#!/bin/sh
+set -e
+if [ -r "${TMPWORKINGDIRECTORY}/noopchroot.so" ]; then
+ if [ -n "\$LD_PRELOAD" ]; then
+ export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so \${LD_PRELOAD}"
+ else
+ export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so"
+ fi
+fi
+exec fakeroot gdb --quiet -ex run "${DPKG:-dpkg}" --args "${DPKG:-dpkg}" --root="${TMPWORKINGDIRECTORY}/rootdir" \\
+ --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log \\
+ --force-not-root --force-bad-path "\$@"
+EOF
+ chmod +x "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg"
echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir/etc/apt/apt.conf.d/99dpkg
{
fi
}
+testoutputequal() {
+ local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
+ local COMPAREFILE="$1"
+ shift
+ if "$@" 2>&1 | checkdiff $COMPAREFILE - >"$OUTPUT" 2>&1; then
+ msgpass
+ else
+ echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
+ cat "$COMPAREFILE" >>"${OUTPUT}"
+ msgfailoutput '' "$OUTPUT" "$@"
+ fi
+}
+
testfileequal() {
- msggroup "$0"
+ msggroup 'testfileequal'
local MSG='Test for correctness of file'
if [ "$1" = '--nomsg' ]; then
MSG=''
fi
local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
if [ -z "$*" ]; then
- if echo -n "" | checkdiff - $FILE >"$OUTPUT" 2>&1; then
- msgpass
- else
- msgfailoutput '' "$OUTPUT"
- fi
+ testoutputequal "$FILE" echo -n ''
else
- if echo "$*" | checkdiff - $FILE >"$OUTPUT" 2>&1; then
- msgpass
- else
- msgfailoutput '' "$OUTPUT"
- fi
+ testoutputequal "$FILE" echo "$*"
fi
msggroup
}
testempty() {
- msggroup "$0"
+ msggroup 'testempty'
msgtest "Test for no output of" "$*"
local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
- if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
+ if ("$@" >$COMPAREFILE 2>&1 || true) && test ! -s $COMPAREFILE; then
msgpass
else
- msgfailoutput '' "$COMPAREFILE"
+ msgfailoutput '' "$COMPAREFILE" "$@"
fi
aptautotest 'testempty' "$@"
msggroup
}
testequal() {
- msggroup "$0"
+ msggroup 'testequal'
local MSG='Test of equality of'
if [ "$1" = '--nomsg' ]; then
MSG=''
if [ -n "$MSG" ]; then
msgtest "$MSG" "$*"
fi
- local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
- if "$@" 2>&1 | checkdiff $COMPAREFILE - >"$OUTPUT" 2>&1; then
- msgpass
- else
- msgfailoutput '' "$OUTPUT"
- fi
+ testoutputequal "$COMPAREFILE" "$@"
aptautotest 'testequal' "$@"
msggroup
}
testequalor2() {
- msggroup "$0"
+ msggroup 'testequalor2'
local COMPAREFILE1="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
local COMPAREFILE2="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
local COMPAREAGAINST="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
}
testshowvirtual() {
- msggroup "$0"
+ msggroup 'testshowvirtual'
local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
local PACKAGE="$1"
shift
local ARCH="$(getarchitecture 'native')"
echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
- if aptcache show -q=0 "$PACKAGE" 2>&1 | checkdiff "$COMPAREFILE" - >"$OUTPUT" 2>&1; then
- msgpass
- else
- msgfailoutput '' "$OUTPUT"
- fi
+ testoutputequal "$COMPAREFILE" aptcache show -q=0 "$PACKAGE"
msggroup
}
testnopackage() {
- msggroup "$0"
+ msggroup 'testnopackage'
msgtest "Test for non-existent packages" "apt-cache show $*"
local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
if [ -n "$SHOWPKG" ]; then
}
testdpkgstatus() {
- msggroup "$0"
+ msggroup 'testdpkgstatus'
local STATE="$1"
local NR="$2"
shift 2
}
testdpkginstalled() {
- msggroup "$0"
+ msggroup 'testdpkginstalled'
testdpkgstatus 'ii' "$#" "$@"
msggroup
}
testdpkgnotinstalled() {
- msggroup "$0"
+ msggroup 'testdpkgnotinstalled'
testdpkgstatus 'ii' '0' "$@"
msggroup
}
testmarkedauto() {
- msggroup "$0"
+ msggroup 'testmarkedauto'
local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
if [ -n "$1" ]; then
msgtest 'Test for correctly marked as auto-installed' "$*"
msgtest 'Test for correctly marked as auto-installed' 'no package'
echo -n > $COMPAREFILE
fi
- local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.output"
- if aptmark showauto 2>&1 | checkdiff $COMPAREFILE - >"$OUTPUT" 2>&1; then
- msgpass
- else
- msgfailoutput '' "$OUTPUT"
- fi
+ testoutputequal "$COMPAREFILE" aptmark showauto
msggroup
}
testmarkedmanual() {
- msggroup "$0"
+ msggroup 'testmarkedmanual'
local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
if [ -n "$1" ]; then
msgtest 'Test for correctly marked as manually installed' "$*"
msgtest 'Test for correctly marked as manually installed' 'no package'
echo -n > $COMPAREFILE
fi
- local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.output"
- if aptmark showmanual 2>&1 | checkdiff $COMPAREFILE - >"$OUTPUT" 2>&1; then
- msgpass
- else
- msgfailoutput '' "$OUTPUT"
- fi
+ testoutputequal "$COMPAREFILE" aptmark showmanual
msggroup
}
msgfailoutput() {
- if [ -n "$MSGTEST_MSG" ]; then
- echo
- if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
- echo "${CFAIL}Part of the test group: $MSGTEST_GRP"
- fi
- echo -n "$MSGTEST_MSG"
- unset MSGTEST_MSG
- fi
+ msgreportheader 'msgfailoutput'
local MSG="$1"
local OUTPUT="$2"
shift 2
if expr match "$1" "$FILEFLAGS" >/dev/null; then
echo "#### stat(2) of file: $2 ####"
stat "$2" || true
+ if test -e "$2"; then
+ echo "#### Complete file: $2 ####"
+ cat >&2 "$2" || true
+ fi
fi
}
msgfailoutputstatfile "$2" "$3"
}
testsuccess() {
- msggroup "$0"
+ msggroup 'testsuccess'
if [ "$1" = '--nomsg' ]; then
shift
else
msggroup
}
testwarning() {
- msggroup "$0"
+ msggroup 'testwarning'
if [ "$1" = '--nomsg' ]; then
shift
else
msggroup
}
testfailure() {
- msggroup "$0"
+ msggroup 'testfailure'
if [ "$1" = '--nomsg' ]; then
shift
else
msggroup
}
-testsuccessequal() {
- msggroup "$0"
- local CMP="$1"
- shift
- testsuccess "$@"
- testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$CMP"
+testreturnstateequal() {
+ local STATE="$1"
+ msggroup "${STATE}equal"
+ if [ "$2" != '--nomsg' ]; then
+ local CMP="$2"
+ shift 2
+ "$STATE" "$@"
+ testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
+ else
+ local CMP="$3"
+ shift 3
+ "$STATE" --nomsg "$@"
+ testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
+ fi
msggroup
}
+testsuccessequal() {
+ testreturnstateequal 'testsuccess' "$@"
+}
testwarningequal() {
- msggroup "$0"
- local CMP="$1"
- shift
- testwarning "$@"
- testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" "$CMP"
- msggroup
+ testreturnstateequal 'testwarning' "$@"
}
testfailureequal() {
- msggroup "$0"
- local CMP="$1"
- shift
- testfailure "$@"
- testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" "$CMP"
- msggroup
+ testreturnstateequal 'testfailure' "$@"
}
testfailuremsg() {
- msggroup "$0"
+ msggroup 'testfailuremsg'
local CMP="$1"
shift
testfailure "$@"
msgtest 'Check that the output of the previous failed command has expected' 'failures and warnings'
local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
grep '^\(W\|E\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
- local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.output"
- if echo "$CMP" | checkdiff - "${COMPAREFILE}" >"$OUTPUT" 2>&1; then
- msgpass
- else
- echo '### Complete output ###' >"$OUTPUT"
- cat "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" >"$OUTPUT"
- msgfailoutput '' "$OUTPUT"
- fi
+ testoutputequal "$COMPAREFILE" echo "$CMP"
msggroup
}
testfilestats() {
- msggroup "$0"
+ msggroup 'testfilestats'
msgtest "Test that file $1 has $2 $3" "$4"
if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
msgpass
msggroup
}
testaccessrights() {
- msggroup "$0"
+ msggroup 'testaccessrights'
testfilestats "$1" '%a' '=' "$2"
msggroup
}
testwebserverlaststatuscode() {
- msggroup "$0"
+ msggroup 'testwebserverlaststatuscode'
local DOWNLOG='rootdir/tmp/webserverstatus-testfile.log'
local STATUS='downloaded/webserverstatus-statusfile.log'
rm -f "$DOWNLOG" "$STATUS"