]> git.saurik.com Git - apt.git/blame - test/integration/framework
add wrapper around dpkg to be able to use it easily in the tests
[apt.git] / test / integration / framework
CommitLineData
8d876415
DK
1#!/bin/sh -- # no runable script, just for vi
2
3# we all like colorful messages
4CERROR="\e[1;31m" # red
5CWARNING="\e[1;33m" # yellow
6CMSG="\e[1;32m" # green
7CINFO="\e[1;96m" # light blue
8CDEBUG="\e[1;94m" # blue
9CNORMAL="\e[0;39m" # default system console color
10CDONE="\e[1;32m" # green
11CPASS="\e[1;32m" # green
12CFAIL="\e[1;31m" # red
13CCMD="\e[1;35m" # pink
14
15msgdie() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; }
16msgwarn() { echo "${CWARNING}W: $1${CNORMAL}" >&2; }
17msgmsg() { echo "${CMSG}$1${CNORMAL}" >&2; }
18msginfo() { echo "${CINFO}I: $1${CNORMAL}" >&2; }
19msgdebug() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; }
20msgdone() { echo "${CDONE}DONE${CNORMAL}" >&2; }
21msgnwarn() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; }
22msgnmsg() { echo -n "${CMSG}$1${CNORMAL}" >&2; }
23msgninfo() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; }
24msgndebug() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; }
25msgtest() { echo -n "${CINFO}$1 ${CCMD}$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} …${CNORMAL} " >&2; }
26msgpass() { echo "${CPASS}PASS${CNORMAL}" >&2; }
27msgskip() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
28msgfail() { echo "${CFAIL}FAIL${CNORMAL}" >&2; }
29
30# enable / disable Debugging
fc89263e
DK
31MSGLEVEL=${MSGLEVEL:-3}
32if [ $MSGLEVEL -le 0 ]; then
33 msgdie() { true; }
34fi
35if [ $MSGLEVEL -le 1 ]; then
36 msgwarn() { true; }
37 msgnwarn() { true; }
38fi
39if [ $MSGLEVEL -le 2 ]; then
40 msgmsg() { true; }
41 msgnmsg() { true; }
42fi
43if [ $MSGLEVEL -le 3 ]; then
44 msginfo() { true; }
45 msgninfo() { true; }
46fi
47if [ $MSGLEVEL -le 4 ]; then
48 msgdebug() { true; }
49 msgndebug() { true; }
50fi
51msgdone() {
52 if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
53 [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
54 [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
55 [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
56 [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
57 true;
58 else
59 echo "${CDONE}DONE${CNORMAL}" >&2;
60 fi
61}
8d876415
DK
62
63runapt() {
64 msgdebug "Executing: ${CCMD}$*${CDEBUG} "
7d0627b6
DK
65 if [ -f ./aptconfig.conf ]; then
66 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
67 else
68 LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
69 fi
8d876415
DK
70}
71aptconfig() { runapt apt-config $*; }
72aptcache() { runapt apt-cache $*; }
73aptget() { runapt apt-get $*; }
74aptftparchive() { runapt apt-ftparchive $*; }
158fda31
DK
75dpkg() {
76 $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log $*
77}
8d876415
DK
78
79setupenvironment() {
75954ae2 80 TMPWORKINGDIRECTORY=$(mktemp -d)
8f8169ac 81 local TESTDIR=$(readlink -f $(dirname $0))
8d876415 82 msgninfo "Preparing environment for ${CCMD}$0${CINFO} in ${TMPWORKINGDIRECTORY}… "
8f8169ac 83 BUILDDIRECTORY="${TESTDIR}/../../build/bin"
8d876415
DK
84 test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
85 local OLDWORKINGDIRECTORY=$(pwd)
f213b6ea
DK
86 CURRENTTRAP="cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY"
87 trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
8d876415 88 cd $TMPWORKINGDIRECTORY
cd725954 89 mkdir rootdir aptarchive keys
8d876415 90 cd rootdir
cffea9af
DK
91 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d var/cache
92 mkdir -p var/log/apt var/lib/apt
93 mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers
8f8169ac
DK
94 local STATUSFILE=$(echo "$(basename $0)" | sed 's/^test-/status-/')
95 if [ -f "${TESTDIR}/${STATUSFILE}" ]; then
96 cp "${TESTDIR}/${STATUSFILE}" var/lib/dpkg/status
97 else
98 touch var/lib/dpkg/status
99 fi
cd725954 100 touch var/lib/dpkg/available
8d876415
DK
101 mkdir -p usr/lib/apt
102 ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods
103 cd ..
8f8169ac
DK
104 local PACKAGESFILE=$(echo "$(basename $0)" | sed 's/^test-/Packages-/')
105 if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then
106 cp "${TESTDIR}/${PACKAGESFILE}" aptarchive/Packages
107 else
4bec02c2 108 touch aptarchive/Packages
8f8169ac 109 fi
cd725954
DK
110 cp $(find $TESTDIR -name '*.pub' -o -name '*.sec') keys/
111 ln -s ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
cffea9af 112 echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
8d876415
DK
113 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
114 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
cffea9af
DK
115 echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf
116 echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf
117 echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
118 echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
119 echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
120 echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
8d876415
DK
121 export LC_ALL=C
122 msgdone "info"
123}
124
125configarchitecture() {
126 local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf
127 echo "APT::Architecture \"$1\";" > $CONFFILE
128 shift
129 while [ -n "$1" ]; do
130 echo "APT::Architectures:: \"$1\";" >> $CONFFILE
131 shift
132 done
133}
134
75954ae2 135setupsimplenativepackage() {
ce9864a8
DK
136 local NAME="$1"
137 local ARCH="$2"
138 local VERSION="$3"
139 local RELEASE="${4:-unstable}"
140 local DEPENDENCIES="$5"
141 local DESCRIPTION="$6"
b7899b00
DK
142 local SECTION="${7:-others}"
143 local DISTSECTION
144 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
145 DISTSECTION="main"
146 else
147 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
148 fi
ce9864a8
DK
149 local BUILDDIR=incoming/${NAME}-${VERSION}
150 mkdir -p ${BUILDDIR}/debian/source
151 cd ${BUILDDIR}
152 echo "* most suckless software product ever" > FEATURES
b7899b00
DK
153 test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
154 test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
ce9864a8
DK
155
156 * Initial release
157
b7899b00
DK
158 -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog
159 test -e debian/control || echo "Source: $NAME
160Section: $SECTION
ce9864a8
DK
161Priority: optional
162Maintainer: Joe Sixpack <joe@example.org>
163Build-Depends: debhelper (>= 7)
164Standards-Version: 3.9.1
165
166Package: $NAME
b7899b00 167Architecture: $ARCH" > debian/control
ce9864a8
DK
168 test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
169 if [ -z "$DESCRIPTION" ]; then
170 echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
171 If you find such a package installed on your system,
172 YOU did something horribly wrong! They are autogenerated
173 und used only by testcases for APT and surf no other propose…" >> debian/control
174 else
175 echo "Description: $DESCRIPTION" >> debian/control
176 fi
b7899b00
DK
177 test -e debian/compat || echo "7" > debian/compat
178 test -e debian/source/format || echo "3.0 (native)" > debian/source/format
ce9864a8 179 test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
75954ae2
DK
180 cd - > /dev/null
181}
182
183buildsimplenativepackage() {
184 local NAME="$1"
185 local ARCH="$2"
186 local VERSION="$3"
187 local RELEASE="${4:-unstable}"
188 local DEPENDENCIES="$5"
189 local DESCRIPTION="$6"
190 local SECTION="${7:-others}"
191 local DISTSECTION
192 if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then
193 DISTSECTION="main"
194 else
195 DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)"
196 fi
197 setupsimplenativepackage "$NAME" "$ARCH" "$VERSION" "$RELEASE" "$DEPENDENCIES" "$DESCRIPTION" "$SECTION"
198 buildpackage "incoming/${NAME}-${VERSION}" "$RELEASE" "$DISTSECTION"
199 rm -rf "incoming/${NAME}-${VERSION}"
200}
201
202buildpackage() {
203 local BUILDDIR=$1
204 local RELEASE=$2
205 local SECTION=$3
206 msgninfo "Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… "
207 cd $BUILDDIR
208 if [ "$ARCH" = "all" ]; then
209 ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)"
210 fi
b7899b00
DK
211 local BUILT="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)"
212 local PKGS="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")"
213 local SRCS="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._-]*$')"
ce9864a8 214 cd - > /dev/null
b7899b00 215 for PKG in $PKGS; do
75954ae2 216 echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist
b7899b00
DK
217 done
218 for SRC in $SRCS; do
75954ae2 219 echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist
b7899b00 220 done
cffea9af 221 msgdone "info"
ce9864a8
DK
222}
223
224buildaptarchive() {
ce9864a8
DK
225 if [ -d incoming ]; then
226 buildaptarchivefromincoming $*
227 else
228 buildaptarchivefromfiles $*
229 fi
230}
231
232createaptftparchiveconfig() {
233 local ARCHS="$(find pool/ -name '*.deb' | grep -oE '_[a-z0-9-]+\.deb$' | sort | uniq | sed -e '/^_all.deb$/ d' -e 's#^_\([a-z0-9-]*\)\.deb$#\1#' | tr '\n' ' ')"
158fda31
DK
234 if [ -z "$ARCHS" ]; then
235 # the pool is empty, so we will operate on faked packages - let us use the configured archs
236 ARCHS="$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
237 fi
ce9864a8
DK
238 echo -n 'Dir {
239 ArchiveDir "' >> ftparchive.conf
240 echo -n $(readlink -f .) >> ftparchive.conf
241 echo -n '";
242 CacheDir "' >> ftparchive.conf
243 echo -n $(readlink -f ..) >> ftparchive.conf
244 echo -n '";
b7899b00
DK
245 FileListDir "' >> ftparchive.conf
246 echo -n $(readlink -f pool/) >> ftparchive.conf
247 echo -n '";
248};
249Default {
250 Packages::Compress ". gzip bzip2 lzma";
251 Sources::Compress ". gzip bzip2 lzma";
252 Contents::Compress ". gzip bzip2 lzma";
ce9864a8
DK
253};
254TreeDefault {
255 Directory "pool/";
256 SrcDirectory "pool/";
257};
258APT {
259 FTPArchive {
260 Release {
261 Origin "joesixpack";
262 Label "apttestcases";
263 Suite "unstable";
264 Description "repository with dummy packages";
265 Architectures "' >> ftparchive.conf
266 echo -n "$ARCHS" >> ftparchive.conf
267 echo 'source";
268 };
269 };
270};' >> ftparchive.conf
b7899b00
DK
271 for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
272 echo -n 'tree "dists/' >> ftparchive.conf
273 echo -n "$DIST" >> ftparchive.conf
274 echo -n '" {
ce9864a8
DK
275 Architectures "' >> ftparchive.conf
276 echo -n "$ARCHS" >> ftparchive.conf
b7899b00
DK
277 echo -n 'source";
278 FileList "' >> ftparchive.conf
279 echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf
280 echo -n '";
281 SourceFileList "' >> ftparchive.conf
282 echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf
283 echo -n '";
284 Sections "' >> ftparchive.conf
285 echo -n "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')" >> ftparchive.conf
286 echo '";
ce9864a8 287};' >> ftparchive.conf
b7899b00 288 done
ce9864a8
DK
289}
290
291buildaptftparchivedirectorystructure() {
b7899b00
DK
292 local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')"
293 for DIST in $DISTS; do
294 local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)"
295 for SECTION in $SECTIONS; do
296 local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')"
297 for ARCH in $ARCHS; do
298 mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH}
299 done
300 mkdir -p dists/${DIST}/${SECTION}/source
301 mkdir -p dists/${DIST}/${SECTION}/i18n
302 done
ce9864a8 303 done
ce9864a8
DK
304}
305
306buildaptarchivefromincoming() {
b7899b00 307 msginfo "Build APT archive for ${CCMD}$0${CINFO} based on incoming packages…"
ce9864a8
DK
308 cd aptarchive
309 [ -e pool ] || ln -s ../incoming pool
310 [ -e ftparchive.conf ] || createaptftparchiveconfig
311 [ -e dists ] || buildaptftparchivedirectorystructure
b7899b00 312 msgninfo "\tGenerate Packages, Sources and Contents files… "
ce9864a8 313 aptftparchive -qq generate ftparchive.conf
b7899b00
DK
314 msgdone "info"
315 msgninfo "\tGenerate Release files… "
ce9864a8 316 for dir in $(find ./dists -mindepth 1 -maxdepth 1 -type d); do
cd725954 317 aptftparchive -qq release $dir -o APT::FTPArchive::Release::Codename="$(echo "$dir" | cut -d'/' -f 3)" | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference
ce9864a8
DK
318 done
319 cd - > /dev/null
320 msgdone "info"
321}
322
323buildaptarchivefromfiles() {
b7899b00 324 msginfo "Build APT archive for ${CCMD}$0${CINFO} based on prebuild files…"
8d876415 325 cd aptarchive
8d876415
DK
326 if [ -f Packages ]; then
327 msgninfo "\tPackages file… "
328 cat Packages | gzip > Packages.gz
329 cat Packages | bzip2 > Packages.bz2
330 cat Packages | lzma > Packages.lzma
331 msgdone "info"
332 fi
333 if [ -f Sources ]; then
334 msgninfo "\tSources file… "
335 cat Sources | gzip > Sources.gz
336 cat Sources | bzip2 > Sources.bz2
337 cat Sources | lzma > Sources.lzma
338 msgdone "info"
339 fi
b7899b00
DK
340 msgninfo "\tRelease file… "
341 aptftparchive -qq release . | sed -e '/0 Release$/ d' > Release # remove the self reference
342 msgdone "info"
8d876415 343 cd ..
8d876415
DK
344}
345
b7899b00
DK
346setupdistsaptarchive() {
347 local APTARCHIVE=$(readlink -f ./aptarchive)
348 rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list
349 rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list
350 for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do
351 SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ')
352 msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… "
353 echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list
354 echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list
355 msgdone "info"
356 done
357}
358
359setupflataptarchive() {
ce9864a8 360 local APTARCHIVE=$(readlink -f ./aptarchive)
8d876415
DK
361 if [ -f ${APTARCHIVE}/Packages ]; then
362 msgninfo "\tadd deb sources.list line… "
363 echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
364 msgdone "info"
365 else
366 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
367 fi
368 if [ -f ${APTARCHIVE}/Sources ]; then
369 msgninfo "\tadd deb-src sources.list line… "
370 echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
371 msgdone "info"
372 else
373 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
374 fi
b7899b00
DK
375}
376
377setupaptarchive() {
378 buildaptarchive
379 if [ -e aptarchive/dists ]; then
380 setupdistsaptarchive
381 else
382 setupflataptarchive
383 fi
f213b6ea 384 signreleasefiles
cd725954 385 msgninfo "\tSync APT's cache with the archive… "
8d876415 386 aptget update -qq
cd725954 387 msgdone "info"
8d876415
DK
388}
389
f213b6ea
DK
390signreleasefiles() {
391 local SIGNER="${1:-Joe Sixpack}"
392 msgninfo "\tSign archive with $SIGNER key… "
393 local SECKEYS=""
394 for KEY in $(find keys/ -name '*.sec'); do
395 SECKEYS="$SECKEYS --secret-keyring $KEY"
396 done
397 local PUBKEYS=""
398 for KEY in $(find keys/ -name '*.pub'); do
399 PUBKEYS="$PUBKEYS --keyring $KEY"
400 done
401 for RELEASE in $(find aptarchive/ -name Release); do
402 gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" -abs -o ${RELEASE}.gpg ${RELEASE}
403 done
404 msgdone "info"
405}
406
407changetowebserver() {
408 if which weborf > /dev/null; then
409 weborf -xb aptarchive/ 2>&1 > /dev/null &
410 CURRENTTRAP="kill $(ps | grep weborf | sed -e 's#^[ ]*##' | cut -d' ' -f 1); $CURRENTTRAP"
411 trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
412 local APTARCHIVE="file://$(readlink -f ./aptarchive)"
413 for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
414 sed -i $LIST -e "s#$APTARCHIVE#http://localhost:8080/#"
415 done
416 return 0
417 fi
418 return 1
419}
420
421checkdiff() {
8d876415
DK
422 local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
423 if [ -n "$DIFFTEXT" ]; then
424 echo
425 echo "$DIFFTEXT"
426 return 1
427 else
428 return 0
429 fi
430}
431
75954ae2
DK
432testfileequal() {
433 local FILE="$1"
434 shift
435 msgtest "Test for correctness of file" "$FILE"
436 if [ -z "$*" ]; then
f213b6ea 437 echo -n "" | checkdiff $FILE - && msgpass || msgfail
75954ae2 438 else
f213b6ea 439 echo "$*" | checkdiff $FILE - && msgpass || msgfail
75954ae2
DK
440 fi
441}
442
8d876415
DK
443testequal() {
444 local COMPAREFILE=$(mktemp)
445 echo "$1" > $COMPAREFILE
446 shift
447 msgtest "Test for equality of" "$*"
f213b6ea 448 $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
8e86786b 449 rm $COMPAREFILE
8d876415
DK
450}
451
685625bd
DK
452testequalor2() {
453 local COMPAREFILE1=$(mktemp)
454 local COMPAREFILE2=$(mktemp)
455 local COMPAREAGAINST=$(mktemp)
456 echo "$1" > $COMPAREFILE1
457 echo "$2" > $COMPAREFILE2
458 shift 2
459 msgtest "Test for equality OR of" "$*"
460 $* 2>&1 1> $COMPAREAGAINST
f213b6ea
DK
461 (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
462 checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
463 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
464 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" &&
685625bd 465 msgfail )
8e86786b 466 rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST
685625bd
DK
467}
468
8d876415 469testshowvirtual() {
4bec02c2 470 local VIRTUAL="N: Can't select versions from package '$1' as it purely virtual"
8d876415
DK
471 local PACKAGE="$1"
472 shift
473 while [ -n "$1" ]; do
474 VIRTUAL="${VIRTUAL}
4bec02c2 475N: Can't select versions from package '$1' as it purely virtual"
8d876415
DK
476 PACKAGE="${PACKAGE} $1"
477 shift
478 done
479 msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
480 VIRTUAL="${VIRTUAL}
4bec02c2 481N: No packages found"
8d876415
DK
482 local COMPAREFILE=$(mktemp)
483 local ARCH=$(dpkg-architecture -qDEB_HOST_ARCH_CPU)
484 eval `apt-config shell ARCH APT::Architecture`
485 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
f213b6ea 486 aptcache show $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
8e86786b 487 rm $COMPAREFILE
8d876415
DK
488}
489
490testnopackage() {
491 msgtest "Test for non-existent packages" "apt-cache show $*"
492 local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
493 if [ -n "$SHOWPKG" ]; then
494 echo
495 echo "$SHOWPKG"
496 msgfail
497 return 1
498 fi
499 msgpass
500}