]> git.donarmstrong.com Git - wannabuild.git/blob - tests/tests.sh
[tests] assert_grep_not function
[wannabuild.git] / tests / tests.sh
1 #!/bin/bash
2
3 #
4 # This file runs wanna-build in a clean environment to make sure, certain
5 # features work as expected.
6 #
7 # At the moment it
8 #  * Uploads a source
9 #  * Take the build
10 #  * Marks it as uploaded
11 #  * Uploads a source with build-depends
12 #  - Makes sure the package is marked Dep-Wait
13 #  * Uploads a new version of the dependency
14 #  - Makes sure the Dep-Wait is cleared
15 #
16
17 parent_pid=$$
18
19 function assert {
20         if ! eval $1
21         then
22                 echo "Assertion failed: $1"
23                 exit 1;
24         fi
25 }
26
27 function assert_grep {
28         cat > $testdir/assert_grep
29         if ! grep -q "$1" $testdir/assert_grep 
30         then
31           echo "Could not find expected \"$1\" in:"
32           cat $testdir/assert_grep
33           # We are in a pipe, i.e. a subshell, so kill the parent 
34           kill -TERM $parent_pid
35           exit 1
36         fi
37 }
38
39 function assert_grep_not {
40         cat > $testdir/assert_grep
41         if grep -q "$1" $testdir/assert_grep 
42         then
43           echo "Could find unexpected \"$1\" in:"
44           cat $testdir/assert_grep
45           # We are in a pipe, i.e. a subshell, so kill the parent 
46           kill -TERM $parent_pid
47           exit 1
48         fi
49 }
50
51 cd "$(dirname $0)"/..
52
53 assert "[ -e bin/wanna-build ]"
54
55 testdir=./tests/tmp
56 rm -rf $testdir
57 mkdir -p $testdir
58
59 # This is a fake configuration file to make sure we do not interfere with a
60 # possibly installed wanna-build instance
61 cat > $testdir/wanna-build.conf <<__END__
62 \$basedir = "$testdir/db";
63 \$ignore_epochs = 0;
64 \$db_maint = "wb-team\@dontsend.buildd.debian.org";
65 \$notforus_maint = "notforus\@dontsend.buildd.debian.org";
66 \$stat_mail = "wb-team\@dontsend.buildd.debian.org";
67 \$buildd_domain = "buildd.debian.org";
68 \$web_stats = "/var/www/buildd/stats.txt";
69 @sections = qw(main contrib non-US/main non-US/contrib);
70 \$pkgs_source = "$testdir/ftp";
71 \$quinn_source = "$testdir/quinn-diff-output";
72 \$quinn_source_multi_section = 0;
73 @admin_users = qw(wbadm $USER);
74 \$mailprog = "/bin/true";
75 %distributions = (
76         "unstable" => { },
77 );
78 # don't remove this, Perl needs it:
79 1;
80 __END__
81
82 mkdir $testdir/db;
83 mkdir $testdir/db/amd64;
84
85 function wanna-build {
86         # Here we make sure that the "require /etc/wanan-build.conf" does not
87         # have effect, and load our own file instead.
88         #echo "Executing wanna-build" "$@" >&2
89         export PERL5LIB=/home/jojo/debian/wanna-build/testsetup/bin
90         perl -e '
91           package conf;
92           do "./tests/tmp/wanna-build.conf";
93           $INC{"/etc/wanna-build.conf"}=1;
94           package main;
95           my $ret;
96           eval {
97                 require "./bin/wanna-build";
98           };
99           if ($@) { die $@; }
100         ' -- "$@"
101 }
102
103 # Create database
104 wanna-build -A amd64 -b amd64/build-db --create-db --info no-package-1.2.3
105
106 echo Load some sources
107
108 cat > $testdir/Packages <<__END__ 
109 Package: bin-a-indep
110 Version: 1
111 Architecture: all
112 Source: src-a
113 __END__
114 cat > $testdir/quinn-diff <<__END__
115 misc/src-a_1.dsc [optional:uncompiled]
116 __END__
117 cat > $testdir/Sources <<__END__
118 Package: src-a
119 Version: 1
120 Architecture: any
121 Section: misc
122 Priority: standard
123 Binary: bin-a-indep,bin-a-1
124 __END__
125 wanna-build -A amd64 -b amd64/build-db --merge-all $testdir/Packages $testdir/quinn-diff $testdir/Sources
126
127 # Test that they exist are in state Needs-Build
128 wanna-build -A amd64 -b amd64/build-db --info src-a | assert_grep ' State.*: Needs-Build'
129
130 echo Take for building
131 wanna-build -A amd64 -b amd64/build-db --take src-a_1
132 wanna-build -A amd64 -b amd64/build-db --info src-a | assert_grep ' State.*: Building'
133
134 echo Upload binaries
135 wanna-build -A amd64 -b amd64/build-db --uploaded src-a_1
136 wanna-build -A amd64 -b amd64/build-db --info src-a | assert_grep ' State.*: Uploaded'
137
138 echo Load the binaries for the sources
139 cat > $testdir/Packages <<__END__ 
140 Package: bin-a-indep
141 Version: 1
142 Architecture: all
143 Source: src-a
144
145 Package: bin-a-1
146 Version: 1
147 Architecture: amd64
148 Source: src-a
149 __END__
150 cat > $testdir/quinn-diff <<__END__
151 __END__
152 cat > $testdir/Sources <<__END__
153 Package: src-a
154 Version: 1
155 Architecture: any
156 Section: misc
157 Priority: standard
158 Binary: bin-a-indep,bin-a-1
159 __END__
160 wanna-build -A amd64 -b amd64/build-db --merge-all $testdir/Packages $testdir/quinn-diff $testdir/Sources
161
162 # Test that they exist are in state Needs-Build
163 wanna-build -A amd64 -b amd64/build-db --info src-a | assert_grep ' State .*: Installed'
164
165 echo Upload another source that needs bin-a-1 in Version 2
166 cat > $testdir/Packages <<__END__ 
167 Package: bin-a-indep
168 Version: 1
169 Architecture: all
170 Source: src-a
171
172 Package: bin-a-1
173 Version: 1
174 Architecture: amd64
175 Source: src-a
176 __END__
177 cat > $testdir/quinn-diff <<__END__
178 misc/src-b_1.dsc [optional:uncompiled]
179 __END__
180 cat > $testdir/Sources <<__END__
181 Package: src-a
182 Version: 1
183 Architecture: any
184 Section: misc
185 Priority: standard
186 Binary: bin-a-indep,bin-a-1
187
188 Package: src-b
189 Version: 1
190 Architecture: any
191 Section: misc
192 Priority: standard
193 Build-Depends: bin-a-1 (>= 2)
194 Binary: bin-b
195 __END__
196 wanna-build -A amd64 -b amd64/build-db --merge-all $testdir/Packages $testdir/quinn-diff $testdir/Sources
197
198 wanna-build -A amd64 -b amd64/build-db --info src-b | assert_grep "bin-a-1 (>= 2)"
199
200 echo Uploading the new source with an updated binary package
201 cat > $testdir/Packages <<__END__ 
202 Package: bin-a-indep
203 Version: 2
204 Architecture: all
205 Source: src-a
206
207 Package: bin-a-1
208 Version: 2
209 Architecture: amd64
210 Source: src-a
211 __END__
212 cat > $testdir/quinn-diff <<__END__
213 misc/src-a_1.dsc [optional:uncompiled]
214 misc/src-b_1.dsc [optional:uncompiled]
215 __END__
216 cat > $testdir/Sources <<__END__
217 Package: src-a
218 Version: 2
219 Architecture: any
220 Section: misc
221 Priority: standard
222 Binary: bin-a-indep,bin-a-1
223
224 Package: src-b
225 Version: 1
226 Architecture: any
227 Section: misc
228 Priority: standard
229 Build-Depends: bin-a-1 (>= 2)
230 Binary: bin-b
231 __END__
232 wanna-build -A amd64 -b amd64/build-db --merge-all $testdir/Packages $testdir/quinn-diff $testdir/Sources
233
234 wanna-build -A amd64 -b amd64/build-db --info src-b | assert_grep "State.*:.*Needs-Build"
235
236 echo "Exporting database"
237 wanna-build -A amd64 -b amd64/build-db --export $testdir/export1
238
239 echo "Importing database"
240 wanna-build -A amd64 -b amd64/build-db --import $testdir/export1
241
242 echo "Exporting database again"
243 wanna-build -A amd64 -b amd64/build-db --export $testdir/export2
244
245 if ! diff -q $testdir/export1 $testdir/export2
246 then
247         echo "Exporting and importing is not idempotent!"
248         exit 1
249 fi
250 echo "Finished sucessfully"