Commit | Line | Data |
---|---|---|
b29455cf FB |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch> | |
b46a9b9a | 3 | ;;; Copyright © 2019 Robert Vollmert <rob@vllmrt.net> |
cfec09a9 | 4 | ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz> |
b29455cf FB |
5 | ;;; |
6 | ;;; This file is part of GNU Guix. | |
7 | ;;; | |
8 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
9 | ;;; under the terms of the GNU General Public License as published by | |
10 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
11 | ;;; your option) any later version. | |
12 | ;;; | |
13 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
14 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | ;;; GNU General Public License for more details. | |
17 | ;;; | |
18 | ;;; You should have received a copy of the GNU General Public License | |
19 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
20 | ||
21 | (define-module (test-hackage) | |
a4154748 | 22 | #:use-module (guix import cabal) |
b29455cf FB |
23 | #:use-module (guix import hackage) |
24 | #:use-module (guix tests) | |
25 | #:use-module (srfi srfi-64) | |
26 | #:use-module (ice-9 match)) | |
27 | ||
28 | (define test-cabal-1 | |
29 | "name: foo | |
30 | version: 1.0.0 | |
31 | homepage: http://test.org | |
32 | synopsis: synopsis | |
33 | description: description | |
34 | license: BSD3 | |
35 | executable cabal | |
36 | build-depends: | |
37 | HTTP >= 4000.2.5 && < 4000.3, | |
38 | mtl >= 2.0 && < 3 | |
39 | ") | |
40 | ||
b29455cf | 41 | (define test-cabal-2 |
b29455cf FB |
42 | "name: foo |
43 | version: 1.0.0 | |
44 | homepage: http://test.org | |
45 | synopsis: synopsis | |
46 | description: description | |
47 | license: BSD3 | |
a4154748 FB |
48 | executable cabal { |
49 | build-depends: | |
50 | HTTP >= 4000.2.5 && < 4000.3, | |
51 | mtl >= 2.0 && < 3 | |
52 | } | |
b29455cf FB |
53 | ") |
54 | ||
d3c827e4 FB |
55 | ;; Check compiler implementation test with and without spaces. |
56 | (define test-cabal-3 | |
57 | "name: foo | |
58 | version: 1.0.0 | |
59 | homepage: http://test.org | |
60 | synopsis: synopsis | |
61 | description: description | |
62 | license: BSD3 | |
63 | library | |
64 | if impl(ghc >= 7.2 && < 7.6) | |
65 | Build-depends: ghc-a | |
66 | if impl(ghc>=7.2&&<7.6) | |
67 | Build-depends: ghc-b | |
68 | if impl(ghc == 7.8) | |
69 | Build-depends: | |
70 | HTTP >= 4000.2.5 && < 4000.3, | |
71 | mtl >= 2.0 && < 3 | |
72 | ") | |
73 | ||
e39a44f3 DM |
74 | ;; Check "-any", "-none" when name is different. |
75 | (define test-cabal-4 | |
76 | "name: foo | |
77 | version: 1.0.0 | |
78 | homepage: http://test.org | |
79 | synopsis: synopsis | |
80 | description: description | |
81 | license: BSD3 | |
82 | library | |
83 | if impl(ghcjs -any) | |
84 | Build-depends: ghc-a | |
85 | if impl(ghc>=7.2&&<7.6) | |
86 | Build-depends: ghc-b | |
87 | if impl(ghc == 7.8) | |
88 | Build-depends: | |
89 | HTTP >= 4000.2.5 && < 4000.3, | |
90 | mtl >= 2.0 && < 3 | |
91 | ") | |
92 | ||
93 | ;; Check "-any", "-none". | |
94 | (define test-cabal-5 | |
95 | "name: foo | |
96 | version: 1.0.0 | |
97 | homepage: http://test.org | |
98 | synopsis: synopsis | |
99 | description: description | |
100 | license: BSD3 | |
101 | library | |
102 | if impl(ghc == 7.8) | |
103 | Build-depends: | |
104 | HTTP >= 4000.2.5 && < 4000.3, | |
105 | if impl(ghc -any) | |
106 | Build-depends: mtl >= 2.0 && < 3 | |
107 | if impl(ghc>=7.2&&<7.6) | |
108 | Build-depends: ghc-b | |
109 | ") | |
110 | ||
111 | ;; Check "custom-setup". | |
112 | (define test-cabal-6 | |
113 | "name: foo | |
114 | build-type: Custom | |
115 | version: 1.0.0 | |
116 | homepage: http://test.org | |
117 | synopsis: synopsis | |
118 | description: description | |
119 | license: BSD3 | |
120 | custom-setup | |
121 | setup-depends: base >= 4.7 && < 5, | |
122 | Cabal >= 1.24, | |
123 | haskell-gi == 0.21.* | |
124 | library | |
125 | if impl(ghc>=7.2&&<7.6) | |
126 | Build-depends: ghc-b | |
127 | if impl(ghc == 7.8) | |
128 | Build-depends: | |
129 | HTTP >= 4000.2.5 && < 4000.3, | |
130 | mtl >= 2.0 && < 3 | |
131 | ") | |
132 | ||
a4154748 | 133 | ;; A fragment of a real Cabal file with minor modification to check precedence |
d3c827e4 FB |
134 | ;; of 'and' over 'or', missing final newline, spaces between keywords and |
135 | ;; parentheses and between key and column. | |
a4154748 FB |
136 | (define test-read-cabal-1 |
137 | "name: test-me | |
138 | library | |
139 | -- Choose which library versions to use. | |
140 | if flag(base4point8) | |
141 | Build-depends: base >= 4.8 && < 5 | |
142 | else | |
143 | if flag(base4) | |
144 | Build-depends: base >= 4 && < 4.8 | |
145 | else | |
146 | if flag(base3) | |
147 | Build-depends: base >= 3 && < 4 | |
148 | else | |
149 | Build-depends: base < 3 | |
d3c827e4 | 150 | if flag(base4point8) || flag (base4) && flag(base3) |
a4154748 | 151 | Build-depends: random |
d3c827e4 | 152 | Build-depends : containers |
a4154748 FB |
153 | |
154 | -- Modules that are always built. | |
155 | Exposed-Modules: | |
d3c827e4 | 156 | Test.QuickCheck.Exception") |
b29455cf FB |
157 | |
158 | (test-begin "hackage") | |
159 | ||
55c98f32 RV |
160 | (define-syntax-rule (define-package-matcher name pattern) |
161 | (define* (name obj) | |
162 | (match obj | |
163 | (pattern #t) | |
164 | (x (pk 'fail x #f))))) | |
165 | ||
166 | (define-package-matcher match-ghc-foo | |
167 | ('package | |
168 | ('name "ghc-foo") | |
169 | ('version "1.0.0") | |
170 | ('source | |
171 | ('origin | |
172 | ('method 'url-fetch) | |
173 | ('uri ('string-append | |
174 | "https://hackage.haskell.org/package/foo/foo-" | |
175 | 'version | |
176 | ".tar.gz")) | |
177 | ('sha256 | |
178 | ('base32 | |
179 | (? string? hash))))) | |
180 | ('build-system 'haskell-build-system) | |
181 | ('inputs | |
182 | ('quasiquote | |
ea35f5c5 | 183 | (("ghc-http" ('unquote 'ghc-http))))) |
55c98f32 RV |
184 | ('home-page "http://test.org") |
185 | ('synopsis (? string?)) | |
186 | ('description (? string?)) | |
cfec09a9 | 187 | ('license 'license:bsd-3))) |
55c98f32 RV |
188 | |
189 | (define* (eval-test-with-cabal test-cabal matcher #:key (cabal-environment '())) | |
4110cde0 RV |
190 | (define port (open-input-string test-cabal)) |
191 | (matcher (hackage->guix-package "foo" #:port port #:cabal-environment cabal-environment))) | |
b29455cf FB |
192 | |
193 | (test-assert "hackage->guix-package test 1" | |
55c98f32 | 194 | (eval-test-with-cabal test-cabal-1 match-ghc-foo)) |
b29455cf FB |
195 | |
196 | (test-assert "hackage->guix-package test 2" | |
55c98f32 | 197 | (eval-test-with-cabal test-cabal-2 match-ghc-foo)) |
b29455cf | 198 | |
d3c827e4 | 199 | (test-assert "hackage->guix-package test 3" |
55c98f32 | 200 | (eval-test-with-cabal test-cabal-3 match-ghc-foo |
d3c827e4 FB |
201 | #:cabal-environment '(("impl" . "ghc-7.8")))) |
202 | ||
e39a44f3 | 203 | (test-assert "hackage->guix-package test 4" |
55c98f32 | 204 | (eval-test-with-cabal test-cabal-4 match-ghc-foo |
e39a44f3 DM |
205 | #:cabal-environment '(("impl" . "ghc-7.8")))) |
206 | ||
207 | (test-assert "hackage->guix-package test 5" | |
55c98f32 | 208 | (eval-test-with-cabal test-cabal-5 match-ghc-foo |
e39a44f3 DM |
209 | #:cabal-environment '(("impl" . "ghc-7.8")))) |
210 | ||
55c98f32 RV |
211 | (define-package-matcher match-ghc-foo-6 |
212 | ('package | |
213 | ('name "ghc-foo") | |
214 | ('version "1.0.0") | |
215 | ('source | |
216 | ('origin | |
217 | ('method 'url-fetch) | |
218 | ('uri ('string-append | |
219 | "https://hackage.haskell.org/package/foo/foo-" | |
220 | 'version | |
221 | ".tar.gz")) | |
222 | ('sha256 | |
223 | ('base32 | |
224 | (? string? hash))))) | |
225 | ('build-system 'haskell-build-system) | |
226 | ('inputs | |
227 | ('quasiquote | |
228 | (("ghc-b" ('unquote 'ghc-b)) | |
ea35f5c5 | 229 | ("ghc-http" ('unquote 'ghc-http))))) |
55c98f32 RV |
230 | ('native-inputs |
231 | ('quasiquote | |
232 | (("ghc-haskell-gi" ('unquote 'ghc-haskell-gi))))) | |
233 | ('home-page "http://test.org") | |
234 | ('synopsis (? string?)) | |
235 | ('description (? string?)) | |
cfec09a9 | 236 | ('license 'license:bsd-3))) |
55c98f32 | 237 | |
e39a44f3 | 238 | (test-assert "hackage->guix-package test 6" |
55c98f32 | 239 | (eval-test-with-cabal test-cabal-6 match-ghc-foo-6)) |
e39a44f3 | 240 | |
b46a9b9a | 241 | ;; Check multi-line layouted description. |
959c9d15 | 242 | (define test-cabal-multiline-layout |
64d31813 RV |
243 | "name: foo |
244 | version: 1.0.0 | |
245 | homepage: http://test.org | |
246 | synopsis: synopsis | |
247 | description: first line | |
248 | second line | |
249 | license: BSD3 | |
250 | executable cabal | |
251 | build-depends: | |
252 | HTTP >= 4000.2.5 && < 4000.3, | |
253 | mtl >= 2.0 && < 3 | |
254 | ") | |
255 | ||
959c9d15 RV |
256 | (test-assert "hackage->guix-package test multiline desc (layout)" |
257 | (eval-test-with-cabal test-cabal-multiline-layout match-ghc-foo)) | |
64d31813 | 258 | |
b46a9b9a | 259 | ;; Check multi-line braced description. |
959c9d15 RV |
260 | (define test-cabal-multiline-braced |
261 | "name: foo | |
262 | version: 1.0.0 | |
263 | homepage: http://test.org | |
264 | synopsis: synopsis | |
265 | description: { | |
266 | first line | |
267 | second line | |
268 | } | |
269 | license: BSD3 | |
270 | executable cabal | |
271 | build-depends: | |
272 | HTTP >= 4000.2.5 && < 4000.3, | |
273 | mtl >= 2.0 && < 3 | |
274 | ") | |
275 | ||
276 | (test-assert "hackage->guix-package test multiline desc (braced)" | |
277 | (eval-test-with-cabal test-cabal-multiline-braced match-ghc-foo)) | |
64d31813 | 278 | |
b46a9b9a RV |
279 | ;; Check mixed layout. Compare e.g. warp. |
280 | (define test-cabal-mixed-layout | |
281 | "name: foo | |
282 | version: 1.0.0 | |
283 | homepage: http://test.org | |
284 | synopsis: synopsis | |
285 | description: description | |
286 | license: BSD3 | |
287 | executable cabal | |
288 | build-depends: | |
289 | HTTP >= 4000.2.5 && < 4000.3, | |
290 | mtl >= 2.0 && < 3 | |
291 | ghc-options: -Wall | |
292 | ") | |
293 | ||
294 | ;; Fails: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=35743 | |
295 | (test-expect-fail 1) | |
296 | (test-assert "hackage->guix-package test mixed layout" | |
297 | (eval-test-with-cabal test-cabal-mixed-layout match-ghc-foo)) | |
298 | ||
299 | ;; Check flag executable. Compare e.g. darcs. | |
300 | (define test-cabal-flag-executable | |
301 | "name: foo | |
302 | version: 1.0.0 | |
303 | homepage: http://test.org | |
304 | synopsis: synopsis | |
305 | description: description | |
306 | license: BSD3 | |
307 | flag executable | |
308 | description: Build executable | |
309 | default: True | |
310 | executable cabal | |
311 | if !flag(executable) | |
312 | buildable: False | |
313 | else | |
314 | buildable: True | |
315 | ||
316 | build-depends: | |
317 | HTTP >= 4000.2.5 && < 4000.3, | |
318 | mtl >= 2.0 && < 3 | |
319 | ") | |
320 | ||
321 | ;; Fails: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25138 | |
322 | (test-expect-fail 1) | |
323 | (test-assert "hackage->guix-package test flag executable" | |
324 | (eval-test-with-cabal test-cabal-flag-executable match-ghc-foo)) | |
325 | ||
ca45da9f RV |
326 | ;; Check Hackage Cabal revisions. |
327 | (define test-cabal-revision | |
328 | "name: foo | |
329 | version: 1.0.0 | |
330 | x-revision: 2 | |
331 | homepage: http://test.org | |
332 | synopsis: synopsis | |
333 | description: description | |
334 | license: BSD3 | |
335 | executable cabal | |
336 | build-depends: | |
337 | HTTP >= 4000.2.5 && < 4000.3, | |
338 | mtl >= 2.0 && < 3 | |
339 | ") | |
340 | ||
341 | (define-package-matcher match-ghc-foo-revision | |
342 | ('package | |
343 | ('name "ghc-foo") | |
344 | ('version "1.0.0") | |
345 | ('source | |
346 | ('origin | |
347 | ('method 'url-fetch) | |
348 | ('uri ('string-append | |
349 | "https://hackage.haskell.org/package/foo/foo-" | |
350 | 'version | |
351 | ".tar.gz")) | |
352 | ('sha256 | |
353 | ('base32 | |
354 | (? string? hash))))) | |
355 | ('build-system 'haskell-build-system) | |
356 | ('inputs | |
357 | ('quasiquote | |
358 | (("ghc-http" ('unquote 'ghc-http))))) | |
359 | ('arguments | |
360 | ('quasiquote | |
361 | ('#:cabal-revision | |
362 | ("2" "0xxd88fb659f0krljidbvvmkh9ppjnx83j0nqzx8whcg4n5qbyng")))) | |
363 | ('home-page "http://test.org") | |
364 | ('synopsis (? string?)) | |
365 | ('description (? string?)) | |
cfec09a9 | 366 | ('license 'license:bsd-3))) |
ca45da9f RV |
367 | |
368 | (test-assert "hackage->guix-package test cabal revision" | |
369 | (eval-test-with-cabal test-cabal-revision match-ghc-foo-revision)) | |
370 | ||
a4154748 FB |
371 | (test-assert "read-cabal test 1" |
372 | (match (call-with-input-string test-read-cabal-1 read-cabal) | |
373 | ((("name" ("test-me")) | |
374 | ('section 'library | |
0be46592 RV |
375 | (('if ('flag "base4point8") |
376 | (("build-depends" ("base >= 4.8 && < 5"))) | |
377 | (('if ('flag "base4") | |
378 | (("build-depends" ("base >= 4 && < 4.8"))) | |
379 | (('if ('flag "base3") | |
380 | (("build-depends" ("base >= 3 && < 4"))) | |
381 | (("build-depends" ("base < 3")))))))) | |
382 | ('if ('or ('flag "base4point8") | |
383 | ('and ('flag "base4") ('flag "base3"))) | |
384 | (("build-depends" ("random"))) | |
385 | ()) | |
386 | ("build-depends" ("containers")) | |
387 | ("exposed-modules" ("Test.QuickCheck.Exception"))))) | |
b29455cf | 388 | #t) |
a4154748 | 389 | (x (pk 'fail x #f)))) |
b29455cf | 390 | |
dfac3e64 PM |
391 | (define test-cabal-import |
392 | "name: foo | |
393 | version: 1.0.0 | |
394 | homepage: http://test.org | |
395 | synopsis: synopsis | |
396 | description: description | |
397 | license: BSD3 | |
398 | common commons | |
399 | build-depends: | |
400 | HTTP >= 4000.2.5 && < 4000.3, | |
401 | mtl >= 2.0 && < 3 | |
402 | ||
403 | executable cabal | |
404 | import: commons | |
405 | ") | |
406 | ||
407 | (define-package-matcher match-ghc-foo-import | |
408 | ('package | |
409 | ('name "ghc-foo") | |
410 | ('version "1.0.0") | |
411 | ('source | |
412 | ('origin | |
413 | ('method 'url-fetch) | |
414 | ('uri ('string-append | |
415 | "https://hackage.haskell.org/package/foo/foo-" | |
416 | 'version | |
417 | ".tar.gz")) | |
418 | ('sha256 | |
419 | ('base32 | |
420 | (? string? hash))))) | |
421 | ('build-system 'haskell-build-system) | |
422 | ('inputs | |
423 | ('quasiquote | |
424 | (("ghc-http" ('unquote 'ghc-http))))) | |
425 | ('home-page "http://test.org") | |
426 | ('synopsis (? string?)) | |
427 | ('description (? string?)) | |
428 | ('license 'license:bsd-3))) | |
429 | ||
430 | (test-assert "hackage->guix-package test cabal import" | |
431 | (eval-test-with-cabal test-cabal-import match-ghc-foo-import)) | |
432 | ||
b29455cf | 433 | (test-end "hackage") |