]> git.saurik.com Git - apt.git/blob - test/integration/framework
fix testcase framework to test correctly for virtual packages
[apt.git] / test / integration / framework
1 #!/bin/sh -- # no runable script, just for vi
2
3 # we all like colorful messages
4 CERROR="\e[1;31m" # red
5 CWARNING="\e[1;33m" # yellow
6 CMSG="\e[1;32m" # green
7 CINFO="\e[1;96m" # light blue
8 CDEBUG="\e[1;94m" # blue
9 CNORMAL="\e[0;39m" # default system console color
10 CDONE="\e[1;32m" # green
11 CPASS="\e[1;32m" # green
12 CFAIL="\e[1;31m" # red
13 CCMD="\e[1;35m" # pink
14
15 msgdie() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; }
16 msgwarn() { echo "${CWARNING}W: $1${CNORMAL}" >&2; }
17 msgmsg() { echo "${CMSG}$1${CNORMAL}" >&2; }
18 msginfo() { echo "${CINFO}I: $1${CNORMAL}" >&2; }
19 msgdebug() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; }
20 msgdone() { echo "${CDONE}DONE${CNORMAL}" >&2; }
21 msgnwarn() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; }
22 msgnmsg() { echo -n "${CMSG}$1${CNORMAL}" >&2; }
23 msgninfo() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; }
24 msgndebug() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; }
25 msgtest() { 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; }
26 msgpass() { echo "${CPASS}PASS${CNORMAL}" >&2; }
27 msgskip() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
28 msgfail() { echo "${CFAIL}FAIL${CNORMAL}" >&2; }
29
30 # enable / disable Debugging
31 msginfo() { true; }
32 msgdebug() { true; }
33 msgninfo() { true; }
34 msgndebug() { true; }
35 msgdone() { if [ "$1" = "debug" -o "$1" = "info" ]; then true; else echo "${CDONE}DONE${CNORMAL}" >&2; fi }
36
37 runapt() {
38 msgdebug "Executing: ${CCMD}$*${CDEBUG} "
39 if [ -f ./aptconfig.conf ]; then
40 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
41 else
42 LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
43 fi
44 }
45 aptconfig() { runapt apt-config $*; }
46 aptcache() { runapt apt-cache $*; }
47 aptget() { runapt apt-get $*; }
48 aptftparchive() { runapt apt-ftparchive $*; }
49
50 setupenvironment() {
51 local TMPWORKINGDIRECTORY=$(mktemp -d)
52 local TESTDIR=$(readlink -f $(dirname $0))
53 msgninfo "Preparing environment for ${CCMD}$0${CINFO} in ${TMPWORKINGDIRECTORY}… "
54 BUILDDIRECTORY="${TESTDIR}/../../build/bin"
55 test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
56 local OLDWORKINGDIRECTORY=$(pwd)
57 trap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
58 cd $TMPWORKINGDIRECTORY
59 mkdir rootdir aptarchive
60 cd rootdir
61 mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d var/cache var/lib/dpkg
62 mkdir -p var/cache/apt/archives/partial var/lib/apt/lists/partial
63 local STATUSFILE=$(echo "$(basename $0)" | sed 's/^test-/status-/')
64 if [ -f "${TESTDIR}/${STATUSFILE}" ]; then
65 cp "${TESTDIR}/${STATUSFILE}" var/lib/dpkg/status
66 else
67 touch var/lib/dpkg/status
68 fi
69 mkdir -p usr/lib/apt
70 ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods
71 cd ..
72 local PACKAGESFILE=$(echo "$(basename $0)" | sed 's/^test-/Packages-/')
73 if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then
74 cp "${TESTDIR}/${PACKAGESFILE}" aptarchive/Packages
75 else
76 touch aptarchive/Packages
77 fi
78 echo "RootDir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
79 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
80 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
81 export LC_ALL=C
82 msgdone "info"
83 }
84
85 configarchitecture() {
86 local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf
87 echo "APT::Architecture \"$1\";" > $CONFFILE
88 shift
89 while [ -n "$1" ]; do
90 echo "APT::Architectures:: \"$1\";" >> $CONFFILE
91 shift
92 done
93 }
94
95 buildflataptarchive() {
96 msginfo "Build APT archive for ${CCMD}$0${CINFO}…"
97 cd aptarchive
98 APTARCHIVE=$(readlink -f .)
99 if [ -f Packages ]; then
100 msgninfo "\tPackages file… "
101 cat Packages | gzip > Packages.gz
102 cat Packages | bzip2 > Packages.bz2
103 cat Packages | lzma > Packages.lzma
104 msgdone "info"
105 fi
106 if [ -f Sources ]; then
107 msgninfo "\tSources file… "
108 cat Sources | gzip > Sources.gz
109 cat Sources | bzip2 > Sources.bz2
110 cat Sources | lzma > Sources.lzma
111 msgdone "info"
112 fi
113 cd ..
114 aptftparchive release . > Release
115 }
116
117 setupflataptarchive() {
118 buildflataptarchive
119 APTARCHIVE=$(readlink -f ./aptarchive)
120 if [ -f ${APTARCHIVE}/Packages ]; then
121 msgninfo "\tadd deb sources.list line… "
122 echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
123 msgdone "info"
124 else
125 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
126 fi
127 if [ -f ${APTARCHIVE}/Sources ]; then
128 msgninfo "\tadd deb-src sources.list line… "
129 echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
130 msgdone "info"
131 else
132 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
133 fi
134 aptget update -qq
135 }
136
137 diff() {
138 local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
139 if [ -n "$DIFFTEXT" ]; then
140 echo
141 echo "$DIFFTEXT"
142 return 1
143 else
144 return 0
145 fi
146 }
147
148 testequal() {
149 local COMPAREFILE=$(mktemp)
150 echo "$1" > $COMPAREFILE
151 shift
152 msgtest "Test for equality of" "$*"
153 $* 2>&1 | diff $COMPAREFILE - && msgpass || msgfail
154 rm $COMPAREFILE
155 }
156
157 testequalor2() {
158 local COMPAREFILE1=$(mktemp)
159 local COMPAREFILE2=$(mktemp)
160 local COMPAREAGAINST=$(mktemp)
161 echo "$1" > $COMPAREFILE1
162 echo "$2" > $COMPAREFILE2
163 shift 2
164 msgtest "Test for equality OR of" "$*"
165 $* 2>&1 1> $COMPAREAGAINST
166 (diff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
167 diff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
168 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(diff $COMPAREFILE1 $COMPAREAGAINST)" \
169 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(diff $COMPAREFILE2 $COMPAREAGAINST)" &&
170 msgfail )
171 rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST
172 }
173
174 testshowvirtual() {
175 local VIRTUAL="N: Can't select versions from package '$1' as it purely virtual"
176 local PACKAGE="$1"
177 shift
178 while [ -n "$1" ]; do
179 VIRTUAL="${VIRTUAL}
180 N: Can't select versions from package '$1' as it purely virtual"
181 PACKAGE="${PACKAGE} $1"
182 shift
183 done
184 msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
185 VIRTUAL="${VIRTUAL}
186 N: No packages found"
187 local COMPAREFILE=$(mktemp)
188 local ARCH=$(dpkg-architecture -qDEB_HOST_ARCH_CPU)
189 eval `apt-config shell ARCH APT::Architecture`
190 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
191 aptcache show $PACKAGE 2>&1 | diff $COMPAREFILE - && msgpass || msgfail
192 rm $COMPAREFILE
193 }
194
195 testnopackage() {
196 msgtest "Test for non-existent packages" "apt-cache show $*"
197 local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
198 if [ -n "$SHOWPKG" ]; then
199 echo
200 echo "$SHOWPKG"
201 msgfail
202 return 1
203 fi
204 msgpass
205 }