1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
3 ;;; Copyright © 2019 Robert Vollmert <rob@vllmrt.net>
5 ;;; This file is part of GNU Guix.
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.
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.
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/>.
20 (define-module (test-hackage)
21 #:use-module (guix import cabal)
22 #:use-module (guix import hackage)
23 #:use-module (guix tests)
24 #:use-module (srfi srfi-64)
25 #:use-module (ice-9 match))
30 homepage: http://test.org
32 description: description
36 HTTP >= 4000.2.5 && < 4000.3,
43 homepage: http://test.org
45 description: description
49 HTTP >= 4000.2.5 && < 4000.3,
54 ;; Check compiler implementation test with and without spaces.
58 homepage: http://test.org
60 description: description
63 if impl(ghc >= 7.2 && < 7.6)
65 if impl(ghc>=7.2&&<7.6)
69 HTTP >= 4000.2.5 && < 4000.3,
73 ;; Check "-any", "-none" when name is different.
77 homepage: http://test.org
79 description: description
84 if impl(ghc>=7.2&&<7.6)
88 HTTP >= 4000.2.5 && < 4000.3,
92 ;; Check "-any", "-none".
96 homepage: http://test.org
98 description: description
103 HTTP >= 4000.2.5 && < 4000.3,
105 Build-depends: mtl >= 2.0 && < 3
106 if impl(ghc>=7.2&&<7.6)
110 ;; Check "custom-setup".
115 homepage: http://test.org
117 description: description
120 setup-depends: base >= 4.7 && < 5,
124 if impl(ghc>=7.2&&<7.6)
128 HTTP >= 4000.2.5 && < 4000.3,
132 ;; A fragment of a real Cabal file with minor modification to check precedence
133 ;; of 'and' over 'or', missing final newline, spaces between keywords and
134 ;; parentheses and between key and column.
135 (define test-read-cabal-1
138 -- Choose which library versions to use.
140 Build-depends: base >= 4.8 && < 5
143 Build-depends: base >= 4 && < 4.8
146 Build-depends: base >= 3 && < 4
148 Build-depends: base < 3
149 if flag(base4point8) || flag (base4) && flag(base3)
150 Build-depends: random
151 Build-depends : containers
153 -- Modules that are always built.
155 Test.QuickCheck.Exception")
157 (test-begin "hackage")
159 (define-syntax-rule (define-package-matcher name pattern)
163 (x (pk 'fail x #f)))))
165 (define-package-matcher match-ghc-foo
172 ('uri ('string-append
173 "https://hackage.haskell.org/package/foo/foo-"
179 ('build-system 'haskell-build-system)
182 (("ghc-http" ('unquote 'ghc-http)))))
183 ('home-page "http://test.org")
184 ('synopsis (? string?))
185 ('description (? string?))
188 (define* (eval-test-with-cabal test-cabal matcher #:key (cabal-environment '()))
189 (define port (open-input-string test-cabal))
190 (matcher (hackage->guix-package "foo" #:port port #:cabal-environment cabal-environment)))
192 (test-assert "hackage->guix-package test 1"
193 (eval-test-with-cabal test-cabal-1 match-ghc-foo))
195 (test-assert "hackage->guix-package test 2"
196 (eval-test-with-cabal test-cabal-2 match-ghc-foo))
198 (test-assert "hackage->guix-package test 3"
199 (eval-test-with-cabal test-cabal-3 match-ghc-foo
200 #:cabal-environment '(("impl" . "ghc-7.8"))))
202 (test-assert "hackage->guix-package test 4"
203 (eval-test-with-cabal test-cabal-4 match-ghc-foo
204 #:cabal-environment '(("impl" . "ghc-7.8"))))
206 (test-assert "hackage->guix-package test 5"
207 (eval-test-with-cabal test-cabal-5 match-ghc-foo
208 #:cabal-environment '(("impl" . "ghc-7.8"))))
210 (define-package-matcher match-ghc-foo-6
217 ('uri ('string-append
218 "https://hackage.haskell.org/package/foo/foo-"
224 ('build-system 'haskell-build-system)
227 (("ghc-b" ('unquote 'ghc-b))
228 ("ghc-http" ('unquote 'ghc-http)))))
231 (("ghc-haskell-gi" ('unquote 'ghc-haskell-gi)))))
232 ('home-page "http://test.org")
233 ('synopsis (? string?))
234 ('description (? string?))
237 (test-assert "hackage->guix-package test 6"
238 (eval-test-with-cabal test-cabal-6 match-ghc-foo-6))
240 ;; Check multi-line layouted description.
241 (define test-cabal-multiline-layout
244 homepage: http://test.org
246 description: first line
251 HTTP >= 4000.2.5 && < 4000.3,
255 (test-assert "hackage->guix-package test multiline desc (layout)"
256 (eval-test-with-cabal test-cabal-multiline-layout match-ghc-foo))
258 ;; Check multi-line braced description.
259 (define test-cabal-multiline-braced
262 homepage: http://test.org
271 HTTP >= 4000.2.5 && < 4000.3,
275 (test-assert "hackage->guix-package test multiline desc (braced)"
276 (eval-test-with-cabal test-cabal-multiline-braced match-ghc-foo))
278 ;; Check mixed layout. Compare e.g. warp.
279 (define test-cabal-mixed-layout
282 homepage: http://test.org
284 description: description
288 HTTP >= 4000.2.5 && < 4000.3,
293 ;; Fails: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=35743
295 (test-assert "hackage->guix-package test mixed layout"
296 (eval-test-with-cabal test-cabal-mixed-layout match-ghc-foo))
298 ;; Check flag executable. Compare e.g. darcs.
299 (define test-cabal-flag-executable
302 homepage: http://test.org
304 description: description
307 description: Build executable
316 HTTP >= 4000.2.5 && < 4000.3,
320 ;; Fails: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25138
322 (test-assert "hackage->guix-package test flag executable"
323 (eval-test-with-cabal test-cabal-flag-executable match-ghc-foo))
325 ;; Check Hackage Cabal revisions.
326 (define test-cabal-revision
330 homepage: http://test.org
332 description: description
336 HTTP >= 4000.2.5 && < 4000.3,
340 (define-package-matcher match-ghc-foo-revision
347 ('uri ('string-append
348 "https://hackage.haskell.org/package/foo/foo-"
354 ('build-system 'haskell-build-system)
357 (("ghc-http" ('unquote 'ghc-http)))))
361 ("2" "0xxd88fb659f0krljidbvvmkh9ppjnx83j0nqzx8whcg4n5qbyng"))))
362 ('home-page "http://test.org")
363 ('synopsis (? string?))
364 ('description (? string?))
367 (test-assert "hackage->guix-package test cabal revision"
368 (eval-test-with-cabal test-cabal-revision match-ghc-foo-revision))
370 (test-assert "read-cabal test 1"
371 (match (call-with-input-string test-read-cabal-1 read-cabal)
372 ((("name" ("test-me"))
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")))
385 ("build-depends" ("containers"))
386 ("exposed-modules" ("Test.QuickCheck.Exception")))))
388 (x (pk 'fail x #f))))