]> git.donarmstrong.com Git - wannabuild.git/blob - tests/tests.sh
[tests] Make tests less chatty
[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 cd "$(dirname $0)"/..
40
41 assert "[ -e bin/wanna-build ]"
42
43 testdir=./tests/tmp
44 rm -rf $testdir
45 mkdir -p $testdir
46
47 # This is a fake configuration file to make sure we do not interfere with a
48 # possibly installed wanna-build instance
49 cat > $testdir/wanna-build.conf <<__END__
50 \$basedir = "$testdir/db";
51 \$ignore_epochs = 0;
52 \$db_maint = "wb-team\@dontsend.buildd.debian.org";
53 \$notforus_maint = "notforus\@dontsend.buildd.debian.org";
54 \$stat_mail = "wb-team\@dontsend.buildd.debian.org";
55 \$buildd_domain = "buildd.debian.org";
56 \$web_stats = "/var/www/buildd/stats.txt";
57 @sections = qw(main contrib non-US/main non-US/contrib);
58 \$pkgs_source = "$testdir/ftp";
59 \$quinn_source = "$testdir/quinn-diff-output";
60 \$quinn_source_multi_section = 0;
61 @admin_users = qw(wbadm $USER);
62 \$mailprog = "/bin/true";
63 %distributions = (
64         "unstable" => { },
65 );
66 # don't remove this, Perl needs it:
67 1;
68 __END__
69
70 mkdir $testdir/db;
71 mkdir $testdir/db/amd64;
72
73 function wanna-build {
74         # Here we make sure that the "require /etc/wanan-build.conf" does not
75         # have effect, and load our own file instead.
76         #echo "Executing wanna-build" "$@" >&2
77         export PERL5LIB=/home/jojo/debian/wanna-build/testsetup/bin
78         perl -e '
79           package conf;
80           do "./tests/tmp/wanna-build.conf";
81           $INC{"/etc/wanna-build.conf"}=1;
82           package main;
83           my $ret;
84           eval {
85                 require "./bin/wanna-build";
86           };
87           if ($@) { die $@; }
88         ' -- "$@"
89 }
90
91 # Create database
92 wanna-build -A amd64 -b amd64/build-db --create-db --info no-package-1.2.3
93
94 echo Load some sources
95
96 cat > $testdir/Packages <<__END__ 
97 Package: bin-a-indep
98 Version: 1
99 Architecture: all
100 Source: src-a
101 __END__
102 cat > $testdir/quinn-diff <<__END__
103 misc/src-a_1.dsc [optional:uncompiled]
104 __END__
105 cat > $testdir/Sources <<__END__
106 Package: src-a
107 Version: 1
108 Architecture: any
109 Section: misc
110 Priority: standard
111 Binary: bin-a-indep,bin-a-1
112 __END__
113 wanna-build -A amd64 -b amd64/build-db --merge-all $testdir/Packages $testdir/quinn-diff $testdir/Sources
114
115 # Test that they exist are in state Needs-Build
116 wanna-build -A amd64 -b amd64/build-db --info src-a | assert_grep ' State.*: Needs-Build'
117
118 echo Take for building
119 wanna-build -A amd64 -b amd64/build-db --take src-a_1
120 wanna-build -A amd64 -b amd64/build-db --info src-a | assert_grep ' State.*: Building'
121
122 echo Upload binaries
123 wanna-build -A amd64 -b amd64/build-db --uploaded src-a_1
124 wanna-build -A amd64 -b amd64/build-db --info src-a | assert_grep ' State.*: Uploaded'
125
126 echo Load the binaries for the sources
127 cat > $testdir/Packages <<__END__ 
128 Package: bin-a-indep
129 Version: 1
130 Architecture: all
131 Source: src-a
132
133 Package: bin-a-1
134 Version: 1
135 Architecture: amd64
136 Source: src-a
137 __END__
138 cat > $testdir/quinn-diff <<__END__
139 __END__
140 cat > $testdir/Sources <<__END__
141 Package: src-a
142 Version: 1
143 Architecture: any
144 Section: misc
145 Priority: standard
146 Binary: bin-a-indep,bin-a-1
147 __END__
148 wanna-build -A amd64 -b amd64/build-db --merge-all $testdir/Packages $testdir/quinn-diff $testdir/Sources
149
150 # Test that they exist are in state Needs-Build
151 wanna-build -A amd64 -b amd64/build-db --info src-a | assert_grep ' State .*: Installed'
152
153 echo Upload another source that needs bin-a-1 in Version 2
154 cat > $testdir/Packages <<__END__ 
155 Package: bin-a-indep
156 Version: 1
157 Architecture: all
158 Source: src-a
159
160 Package: bin-a-1
161 Version: 1
162 Architecture: amd64
163 Source: src-a
164 __END__
165 cat > $testdir/quinn-diff <<__END__
166 misc/src-b_1.dsc [optional:uncompiled]
167 __END__
168 cat > $testdir/Sources <<__END__
169 Package: src-a
170 Version: 1
171 Architecture: any
172 Section: misc
173 Priority: standard
174 Binary: bin-a-indep,bin-a-1
175
176 Package: src-b
177 Version: 1
178 Architecture: any
179 Section: misc
180 Priority: standard
181 Build-Depends: bin-a-1 (>= 2)
182 Binary: bin-b
183 __END__
184 wanna-build -A amd64 -b amd64/build-db --merge-all $testdir/Packages $testdir/quinn-diff $testdir/Sources
185
186 wanna-build -A amd64 -b amd64/build-db --info src-b | assert_grep "bin-a-1 (>= 2)"
187
188 echo Uploading the new source with an updated binary package
189 cat > $testdir/Packages <<__END__ 
190 Package: bin-a-indep
191 Version: 2
192 Architecture: all
193 Source: src-a
194
195 Package: bin-a-1
196 Version: 2
197 Architecture: amd64
198 Source: src-a
199 __END__
200 cat > $testdir/quinn-diff <<__END__
201 misc/src-a_1.dsc [optional:uncompiled]
202 misc/src-b_1.dsc [optional:uncompiled]
203 __END__
204 cat > $testdir/Sources <<__END__
205 Package: src-a
206 Version: 2
207 Architecture: any
208 Section: misc
209 Priority: standard
210 Binary: bin-a-indep,bin-a-1
211
212 Package: src-b
213 Version: 1
214 Architecture: any
215 Section: misc
216 Priority: standard
217 Build-Depends: bin-a-1 (>= 2)
218 Binary: bin-b
219 __END__
220 wanna-build -A amd64 -b amd64/build-db --merge-all $testdir/Packages $testdir/quinn-diff $testdir/Sources
221
222 wanna-build -A amd64 -b amd64/build-db --info src-b | assert_grep "State.*:.*Needs-Build"
223
224 echo "Finished sucessfully"