]> git.donarmstrong.com Git - wannabuild.git/blob - tests/tests.sh
Do not use BASHs redirection feature
[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 Build-Depends: compiler
112 Binary: bin-a-indep,bin-a-1
113 __END__
114 wanna-build -A amd64 -b amd64/build-db --merge-all $testdir/Packages $testdir/quinn-diff $testdir/Sources
115
116 # Test that they exist are in state Needs-Build
117 wanna-build -A amd64 -b amd64/build-db --info src-a | assert_grep ' State.*: Needs-Build'
118
119 echo Take for building
120 wanna-build -A amd64 -b amd64/build-db --take src-a_1
121 wanna-build -A amd64 -b amd64/build-db --info src-a | assert_grep ' State.*: Building'
122
123 echo Upload binaries
124 wanna-build -A amd64 -b amd64/build-db --uploaded src-a_1
125 wanna-build -A amd64 -b amd64/build-db --info src-a | assert_grep ' State.*: Uploaded'
126
127 echo Load the binaries for the sources
128 cat > $testdir/Packages <<__END__ 
129 Package: bin-a-indep
130 Version: 1
131 Architecture: all
132 Source: src-a
133
134 Package: bin-a-1
135 Version: 1
136 Architecture: amd64
137 Source: src-a
138 __END__
139 cat > $testdir/quinn-diff <<__END__
140 __END__
141 cat > $testdir/Sources <<__END__
142 Package: src-a
143 Version: 1
144 Architecture: any
145 Section: misc
146 Priority: standard
147 Build-Depends: compiler
148 Binary: bin-a-indep,bin-a-1
149 __END__
150 wanna-build -A amd64 -b amd64/build-db --merge-all $testdir/Packages $testdir/quinn-diff $testdir/Sources
151
152 # Test that they exist are in state Needs-Build
153 wanna-build -A amd64 -b amd64/build-db --info src-a | assert_grep ' State .*: Installed'
154
155 echo Upload another source that needs bin-a-1 in Version 2
156 cat > $testdir/Packages <<__END__ 
157 Package: bin-a-indep
158 Version: 1
159 Architecture: all
160 Source: src-a
161
162 Package: bin-a-1
163 Version: 1
164 Architecture: amd64
165 Source: src-a
166 __END__
167 cat > $testdir/quinn-diff <<__END__
168 misc/src-b_1.dsc [optional:uncompiled]
169 __END__
170 cat > $testdir/Sources <<__END__
171 Package: src-a
172 Version: 1
173 Architecture: any
174 Section: misc
175 Priority: standard
176 Build-Depends: compiler
177 Binary: bin-a-indep,bin-a-1
178
179 Package: src-b
180 Version: 1
181 Architecture: any
182 Section: misc
183 Priority: standard
184 Build-Depends: bin-a-1 (>= 2)
185 Binary: bin-b
186 __END__
187 wanna-build -A amd64 -b amd64/build-db --merge-all $testdir/Packages $testdir/quinn-diff $testdir/Sources
188
189 wanna-build -A amd64 -b amd64/build-db --info src-b | assert_grep "bin-a-1 (>= 2)"
190
191 echo Uploading the new source with an updated binary package
192 cat > $testdir/Packages <<__END__ 
193 Package: bin-a-indep
194 Version: 2
195 Architecture: all
196 Source: src-a
197
198 Package: bin-a-1
199 Version: 2
200 Architecture: amd64
201 Source: src-a
202 __END__
203 cat > $testdir/quinn-diff <<__END__
204 misc/src-a_1.dsc [optional:uncompiled]
205 misc/src-b_1.dsc [optional:uncompiled]
206 __END__
207 cat > $testdir/Sources <<__END__
208 Package: src-a
209 Version: 2
210 Architecture: any
211 Section: misc
212 Priority: standard
213 Build-Depends: compiler
214 Binary: bin-a-indep,bin-a-1
215
216 Package: src-b
217 Version: 1
218 Architecture: any
219 Section: misc
220 Priority: standard
221 Build-Depends: bin-a-1 (>= 2)
222 Binary: bin-b
223 __END__
224 wanna-build -A amd64 -b amd64/build-db --merge-all $testdir/Packages $testdir/quinn-diff $testdir/Sources
225
226 wanna-build -A amd64 -b amd64/build-db --info src-b | assert_grep "State.*:.*Needs-Build"
227
228 echo "Finished sucessfully"