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