...
1#!/usr/bin/env bats
2
3load common
4
5truncated_diff() {
6 if ! diff "$@" > diff.patch; then
7 head diff.patch
8 false
9 fi
10}
11
12@test "prelude_go.mk: GOHOSTOS" {
13 [[ -n "$build_aux_expeced_GOHOSTOS" ]] || skip
14 check_expr_eq strict '$(GOHOSTOS)' "$build_aux_expeced_GOHOSTOS"
15}
16
17@test "prelude_go.mk: GOHOSTARCH" {
18 [[ -n "$build_aux_expeced_GOHOSTARCH" ]] || skip
19 check_expr_eq strict '$(GOHOSTARCH)' "$build_aux_expeced_GOHOSTARCH"
20}
21
22@test "prelude_go.mk: _prelude.go.lock" {
23 # TODO
24}
25
26@test "prelude_go.mk: _prelude.go.VERSION.parse" {
27 mkdir expected
28 testcase() {
29 [[ $# = 2 ]]
30 echo $2 > "expected/$1"
31 }
32 # Let's go ahead and test this on every version that's been
33 # released so far:
34 #
35 # Generate that list from go.git:
36 # git tag|sed -n '/^go[0-9.]*$/s/^go//p'|sort -V|while read -r rel; do git tag|sed -n "/^go${rel}[a-z]/s/^go//p"; echo $rel; done
37 # and manually put in the expected output.
38 testcase '1' '1 0 0'
39 testcase '1.0.1' '1 0 1'
40 testcase '1.0.2' '1 0 2'
41 testcase '1.0.3' '1 0 3'
42 testcase '1.1rc2' '1 1 0 rc2'
43 testcase '1.1rc3' '1 1 0 rc3'
44 testcase '1.1' '1 1 0'
45 testcase '1.1.1' '1 1 1'
46 testcase '1.1.2' '1 1 2'
47 testcase '1.2rc2' '1 2 0 rc2'
48 testcase '1.2rc3' '1 2 0 rc3'
49 testcase '1.2rc4' '1 2 0 rc4'
50 testcase '1.2rc5' '1 2 0 rc5'
51 testcase '1.2' '1 2 0'
52 testcase '1.2.1' '1 2 1'
53 testcase '1.2.2' '1 2 2'
54 testcase '1.3beta1' '1 3 0 beta1'
55 testcase '1.3beta2' '1 3 0 beta2'
56 testcase '1.3rc1' '1 3 0 rc1'
57 testcase '1.3rc2' '1 3 0 rc2'
58 testcase '1.3' '1 3 0'
59 testcase '1.3.1' '1 3 1'
60 testcase '1.3.2' '1 3 2'
61 testcase '1.3.3' '1 3 3'
62 testcase '1.4beta1' '1 4 0 beta1'
63 testcase '1.4rc1' '1 4 0 rc1'
64 testcase '1.4rc2' '1 4 0 rc2'
65 testcase '1.4' '1 4 0'
66 testcase '1.4.1' '1 4 1'
67 testcase '1.4.2' '1 4 2'
68 testcase '1.4.3' '1 4 3'
69 testcase '1.5beta1' '1 5 0 beta1'
70 testcase '1.5beta2' '1 5 0 beta2'
71 testcase '1.5beta3' '1 5 0 beta3'
72 testcase '1.5rc1' '1 5 0 rc1'
73 testcase '1.5' '1 5 0'
74 testcase '1.5.1' '1 5 1'
75 testcase '1.5.2' '1 5 2'
76 testcase '1.5.3' '1 5 3'
77 testcase '1.5.4' '1 5 4'
78 testcase '1.6beta1' '1 6 0 beta1'
79 testcase '1.6beta2' '1 6 0 beta2'
80 testcase '1.6rc1' '1 6 0 rc1'
81 testcase '1.6rc2' '1 6 0 rc2'
82 testcase '1.6' '1 6 0'
83 testcase '1.6.1' '1 6 1'
84 testcase '1.6.2' '1 6 2'
85 testcase '1.6.3' '1 6 3'
86 testcase '1.6.4' '1 6 4'
87 testcase '1.7beta1' '1 7 0 beta1'
88 testcase '1.7beta2' '1 7 0 beta2'
89 testcase '1.7rc1' '1 7 0 rc1'
90 testcase '1.7rc2' '1 7 0 rc2'
91 testcase '1.7rc3' '1 7 0 rc3'
92 testcase '1.7rc4' '1 7 0 rc4'
93 testcase '1.7rc5' '1 7 0 rc5'
94 testcase '1.7rc6' '1 7 0 rc6'
95 testcase '1.7' '1 7 0'
96 testcase '1.7.1' '1 7 1'
97 testcase '1.7.2' '1 7 2'
98 testcase '1.7.3' '1 7 3'
99 testcase '1.7.4' '1 7 4'
100 testcase '1.7.5' '1 7 5'
101 testcase '1.7.6' '1 7 6'
102 testcase '1.8beta1' '1 8 0 beta1'
103 testcase '1.8beta2' '1 8 0 beta2'
104 testcase '1.8rc1' '1 8 0 rc1'
105 testcase '1.8rc2' '1 8 0 rc2'
106 testcase '1.8rc3' '1 8 0 rc3'
107 testcase '1.8' '1 8 0'
108 testcase '1.8.1' '1 8 1'
109 testcase '1.8.2' '1 8 2'
110 testcase '1.8.3' '1 8 3'
111 testcase '1.8.4' '1 8 4'
112 testcase '1.8.5rc4' '1 8 5 rc4'
113 testcase '1.8.5rc5' '1 8 5 rc5'
114 testcase '1.8.5' '1 8 5'
115 testcase '1.8.6' '1 8 6'
116 testcase '1.8.7' '1 8 7'
117 testcase '1.9beta1' '1 9 0 beta1'
118 testcase '1.9beta2' '1 9 0 beta2'
119 testcase '1.9rc1' '1 9 0 rc1'
120 testcase '1.9rc2' '1 9 0 rc2'
121 testcase '1.9' '1 9 0'
122 testcase '1.9.1' '1 9 1'
123 testcase '1.9.2' '1 9 2'
124 testcase '1.9.3' '1 9 3'
125 testcase '1.9.4' '1 9 4'
126 testcase '1.9.5' '1 9 5'
127 testcase '1.9.6' '1 9 6'
128 testcase '1.9.7' '1 9 7'
129 testcase '1.10beta1' '1 10 0 beta1'
130 testcase '1.10beta2' '1 10 0 beta2'
131 testcase '1.10rc1' '1 10 0 rc1'
132 testcase '1.10rc2' '1 10 0 rc2'
133 testcase '1.10' '1 10 0'
134 testcase '1.10.1' '1 10 1'
135 testcase '1.10.2' '1 10 2'
136 testcase '1.10.3' '1 10 3'
137 testcase '1.10.4' '1 10 4'
138 testcase '1.10.5' '1 10 5'
139 testcase '1.10.6' '1 10 6'
140 testcase '1.10.7' '1 10 7'
141 testcase '1.10.8' '1 10 8'
142 testcase '1.11beta1' '1 11 0 beta1'
143 testcase '1.11beta2' '1 11 0 beta2'
144 testcase '1.11beta3' '1 11 0 beta3'
145 testcase '1.11rc1' '1 11 0 rc1'
146 testcase '1.11rc2' '1 11 0 rc2'
147 testcase '1.11' '1 11 0 '
148 testcase '1.11.1' '1 11 1'
149 testcase '1.11.2' '1 11 2'
150 testcase '1.11.3' '1 11 3'
151 testcase '1.11.4' '1 11 4'
152 testcase '1.11.5' '1 11 5'
153 testcase '1.11.6' '1 11 6'
154 testcase '1.11.7' '1 11 7'
155 testcase '1.11.8' '1 11 8'
156 testcase '1.11.9' '1 11 9'
157 testcase '1.11.10' '1 11 10'
158 testcase '1.11.11' '1 11 11'
159 testcase '1.11.12' '1 11 12'
160 testcase '1.11.13' '1 11 13'
161 testcase '1.12beta1' '1 12 0 beta1'
162 testcase '1.12beta2' '1 12 0 beta2'
163 testcase '1.12rc1' '1 12 0 rc1'
164 testcase '1.12' '1 12 0'
165 testcase '1.12.1' '1 12 1'
166 testcase '1.12.2' '1 12 2'
167 testcase '1.12.3' '1 12 3'
168 testcase '1.12.4' '1 12 4'
169 testcase '1.12.5' '1 12 5'
170 testcase '1.12.6' '1 12 6'
171 testcase '1.12.7' '1 12 7'
172 testcase '1.12.8' '1 12 8'
173 testcase '1.12.9' '1 12 9'
174
175 cat >>Makefile <<-'__EOT__'
176 include build-aux/prelude.mk
177 tst: $(patsubst expected/%,actual/%,$(wildcard expected/*))
178 actual/%: ; @echo $(call _prelude.go.VERSION.parse,$*) > $@
179 __EOT__
180
181 mkdir actual
182 make -j128
183 truncated_diff -ruN expected actual
184}
185
186@test "prelude_go.mk: _prelude.go.VERSION.prerelease.ge" {
187 local versions=(
188 # From go.git:
189 # git tag|sed -n 's/^go[0-9.]*//p'|sort -u
190 beta1
191 beta2
192 beta3
193 rc1
194 rc2
195 rc3
196 rc4
197 rc5
198 rc6
199 )
200 mkdir expected
201 local a b expect
202 for a in "${versions[@]}"; do
203 expect=true
204 for b in "${versions[@]}"; do
205 echo $expect > "expected/$a-ge-$b"
206 # early on, 'b' will be low, so a>=b is true;
207 # once 'b' catches 'a', that will flip to
208 # false.
209 if [[ "$a" == "$b" ]]; then
210 expect=false
211 fi
212 done
213 done
214
215 cat >>Makefile <<-'__EOT__'
216 include build-aux/prelude.mk
217 tst: $(patsubst expected/%,actual/%,$(wildcard expected/*))
218 A = $(word 1,$(subst -ge-, ,$*))
219 B = $(word 2,$(subst -ge-, ,$*))
220 actual/%: ; @echo $(if $(call _prelude.go.VERSION.prerelease.ge,$A,$B),true,false) > $@
221 __EOT__
222
223 mkdir actual
224 make -j128
225 truncated_diff -ruN expected actual
226}
227
228@test "prelude_go.mk: _prelude.go.VERSION.HAVE" {
229 local versions=(
230 # From go.git:
231 # git tag|sed -n '/^go[0-9.]*$/s/^go//p'|sort -V|while read -r rel; do git tag|sed -n "/^go${rel}[a-z]/s/^go//p"; echo $rel; done
232 #
233 # Comment out uninteresting parts in the middle,
234 # because (136 versions)^2 = 18_496 testcases, which
235 # can be kinda slow if we're writing expected and
236 # actual results to disk.
237 1
238 1.0.1
239 1.0.2
240 1.0.3
241 1.1rc2
242 1.1rc3
243 1.1
244 1.1.1
245 1.1.2
246 1.2rc2
247 1.2rc3
248 1.2rc4
249 1.2rc5
250 1.2
251 1.2.1
252 1.2.2
253 # 1.3beta1
254 # 1.3beta2
255 # 1.3rc1
256 # 1.3rc2
257 # 1.3
258 # 1.3.1
259 # 1.3.2
260 # 1.3.3
261 # 1.4beta1
262 # 1.4rc1
263 # 1.4rc2
264 # 1.4
265 # 1.4.1
266 # 1.4.2
267 # 1.4.3
268 # 1.5beta1
269 # 1.5beta2
270 # 1.5beta3
271 # 1.5rc1
272 # 1.5
273 # 1.5.1
274 # 1.5.2
275 # 1.5.3
276 # 1.5.4
277 # 1.6beta1
278 # 1.6beta2
279 # 1.6rc1
280 # 1.6rc2
281 # 1.6
282 # 1.6.1
283 # 1.6.2
284 # 1.6.3
285 # 1.6.4
286 # 1.7beta1
287 # 1.7beta2
288 # 1.7rc1
289 # 1.7rc2
290 # 1.7rc3
291 # 1.7rc4
292 # 1.7rc5
293 # 1.7rc6
294 # 1.7
295 # 1.7.1
296 # 1.7.2
297 # 1.7.3
298 # 1.7.4
299 # 1.7.5
300 # 1.7.6
301
302 # The 1.8 series is "interesting" because it had a
303 # patch release with RCs.
304 1.8beta1
305 1.8beta2
306 1.8rc1
307 1.8rc2
308 1.8rc3
309 1.8
310 1.8.1
311 1.8.2
312 1.8.3
313 1.8.4
314 1.8.5rc4
315 1.8.5rc5
316 1.8.5
317 1.8.6
318 1.8.7
319 # 1.9beta1
320 # 1.9beta2
321 # 1.9rc1
322 # 1.9rc2
323 # 1.9
324 # 1.9.1
325 # 1.9.2
326 # 1.9.3
327 # 1.9.4
328 # 1.9.5
329 # 1.9.6
330 # 1.9.7
331 # 1.10beta1
332 # 1.10beta2
333 # 1.10rc1
334 # 1.10rc2
335 # 1.10
336 # 1.10.1
337 # 1.10.2
338 # 1.10.3
339 # 1.10.4
340 # 1.10.5
341 # 1.10.6
342 # 1.10.7
343 # 1.10.8
344 1.11beta1
345 1.11beta2
346 1.11beta3
347 1.11rc1
348 1.11rc2
349 1.11
350 1.11.1
351 1.11.2
352 1.11.3
353 1.11.4
354 1.11.5
355 1.11.6
356 1.11.7
357 1.11.8
358 1.11.9
359 1.11.10
360 1.11.11
361 1.11.12
362 1.11.13
363 1.12beta1
364 1.12beta2
365 1.12rc1
366 1.12
367 1.12.1
368 1.12.2
369 1.12.3
370 1.12.4
371 1.12.5
372 1.12.6
373 1.12.7
374 1.12.8
375 1.12.9
376 )
377
378 cat >>Makefile <<-'__EOT__'
379 include build-aux/prelude.mk
380
381 expected/%/all: ; @mkdir $(@D) && $(MAKE) _prelude.go.VERSION=$* $(addprefix expected/$*/,$(expected_all))
382 expected/$(_prelude.go.VERSION)/%: ; @echo $(if $(filter $(expected_have),$*),true,false) > $@
383 .PHONY: expected/%/all
384
385 actual/all: $(addsuffix /all,$(patsubst expected/%,actual/%,$(wildcard expected/*)))
386 actual/%/all: ; @mkdir $(@D) && $(MAKE) _prelude.go.VERSION=$* $(patsubst expected/%,actual/%,$(wildcard expected/$*/*))
387 actual/$(_prelude.go.VERSION)/%: ; @echo $(if $(call _prelude.go.VERSION.HAVE,$*),true,false) > $@
388 .PHONY: actual/all actual/%/all
389 __EOT__
390
391 mkdir expected
392 local a b have=()
393 for a in "${versions[@]}"; do
394 have+=("$a")
395 make -j128 _prelude.go.HAVE=/phony/go _prelude.go.VERSION=unsed expected_all="${versions[*]}" expected_have="${have[*]}" "expected/$a/all"
396 done
397
398 mkdir actual
399 make -j128 _prelude.go.HAVE=/phony/go _prelude.go.VERSION=unset actual/all
400
401 truncated_diff -ruN expected actual
402}
View as plain text