]> git.saurik.com Git - apt.git/blob - test/integration/framework
merge from lp:~donkult/apt/sid
[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 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
40 }
41 aptconfig() { runapt apt-config $*; }
42 aptcache() { runapt apt-cache $*; }
43 aptget() { runapt apt-get $*; }
44 aptftparchive() { runapt apt-ftparchive $*; }
45
46 setupenvironment() {
47 local TMPWORKINGDIRECTORY=$(mktemp -d)
48 local TESTDIR=$(readlink -f $(dirname $0))
49 msgninfo "Preparing environment for ${CCMD}$0${CINFO} in ${TMPWORKINGDIRECTORY}… "
50 BUILDDIRECTORY="${TESTDIR}/../../build/bin"
51 test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
52 local OLDWORKINGDIRECTORY=$(pwd)
53 trap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
54 cd $TMPWORKINGDIRECTORY
55 mkdir rootdir aptarchive
56 cd rootdir
57 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
58 mkdir -p var/cache/apt/archives/partial var/lib/apt/lists/partial
59 local STATUSFILE=$(echo "$(basename $0)" | sed 's/^test-/status-/')
60 if [ -f "${TESTDIR}/${STATUSFILE}" ]; then
61 cp "${TESTDIR}/${STATUSFILE}" var/lib/dpkg/status
62 else
63 touch var/lib/dpkg/status
64 fi
65 mkdir -p usr/lib/apt
66 ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods
67 cd ..
68 local PACKAGESFILE=$(echo "$(basename $0)" | sed 's/^test-/Packages-/')
69 if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then
70 cp "${TESTDIR}/${PACKAGESFILE}" aptarchive/Packages
71 else
72 touch var/lib/dpkg/status
73 fi
74 echo "RootDir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
75 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
76 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
77 export LC_ALL=C
78 msgdone "info"
79 }
80
81 configarchitecture() {
82 local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf
83 echo "APT::Architecture \"$1\";" > $CONFFILE
84 shift
85 while [ -n "$1" ]; do
86 echo "APT::Architectures:: \"$1\";" >> $CONFFILE
87 shift
88 done
89 }
90
91 buildflataptarchive() {
92 msginfo "Build APT archive for ${CCMD}$0${CINFO}…"
93 cd aptarchive
94 APTARCHIVE=$(readlink -f .)
95 if [ -f Packages ]; then
96 msgninfo "\tPackages file… "
97 cat Packages | gzip > Packages.gz
98 cat Packages | bzip2 > Packages.bz2
99 cat Packages | lzma > Packages.lzma
100 msgdone "info"
101 fi
102 if [ -f Sources ]; then
103 msgninfo "\tSources file… "
104 cat Sources | gzip > Sources.gz
105 cat Sources | bzip2 > Sources.bz2
106 cat Sources | lzma > Sources.lzma
107 msgdone "info"
108 fi
109 cd ..
110 aptftparchive release . > Release
111 }
112
113 setupflataptarchive() {
114 buildflataptarchive
115 APTARCHIVE=$(readlink -f ./aptarchive)
116 if [ -f ${APTARCHIVE}/Packages ]; then
117 msgninfo "\tadd deb sources.list line… "
118 echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
119 msgdone "info"
120 else
121 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
122 fi
123 if [ -f ${APTARCHIVE}/Sources ]; then
124 msgninfo "\tadd deb-src sources.list line… "
125 echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
126 msgdone "info"
127 else
128 rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list
129 fi
130 aptget update -qq
131 }
132
133 diff() {
134 local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
135 if [ -n "$DIFFTEXT" ]; then
136 echo
137 echo "$DIFFTEXT"
138 return 1
139 else
140 return 0
141 fi
142 }
143
144 testequal() {
145 local COMPAREFILE=$(mktemp)
146 echo "$1" > $COMPAREFILE
147 shift
148 msgtest "Test for equality of" "$*"
149 $* 2>&1 | diff $COMPAREFILE - && msgpass || msgfail
150 rm $COMPAREFILE
151 }
152
153 testequalor2() {
154 local COMPAREFILE1=$(mktemp)
155 local COMPAREFILE2=$(mktemp)
156 local COMPAREAGAINST=$(mktemp)
157 echo "$1" > $COMPAREFILE1
158 echo "$2" > $COMPAREFILE2
159 shift 2
160 msgtest "Test for equality OR of" "$*"
161 $* 2>&1 1> $COMPAREAGAINST
162 (diff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
163 diff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
164 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(diff $COMPAREFILE1 $COMPAREAGAINST)" \
165 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(diff $COMPAREFILE2 $COMPAREAGAINST)" &&
166 msgfail )
167 rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST
168 }
169
170 testshowvirtual() {
171 local VIRTUAL="E: Can't select versions from package '$1' as it purely virtual"
172 local PACKAGE="$1"
173 shift
174 while [ -n "$1" ]; do
175 VIRTUAL="${VIRTUAL}
176 E: Can't select versions from package '$1' as it purely virtual"
177 PACKAGE="${PACKAGE} $1"
178 shift
179 done
180 msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
181 VIRTUAL="${VIRTUAL}
182 E: No packages found"
183 local COMPAREFILE=$(mktemp)
184 local ARCH=$(dpkg-architecture -qDEB_HOST_ARCH_CPU)
185 eval `apt-config shell ARCH APT::Architecture`
186 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
187 aptcache show $PACKAGE 2>&1 | diff $COMPAREFILE - && msgpass || msgfail
188 rm $COMPAREFILE
189 }
190
191 testnopackage() {
192 msgtest "Test for non-existent packages" "apt-cache show $*"
193 local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')"
194 if [ -n "$SHOWPKG" ]; then
195 echo
196 echo "$SHOWPKG"
197 msgfail
198 return 1
199 fi
200 msgpass
201 }