1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
3 ;;; Copyright © 2019 Robert Vollmert <rob@vllmrt.net>
4 ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
5 ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
7 ;;; This file is part of GNU Guix.
9 ;;; GNU Guix is free software; you can redistribute it and/or modify it
10 ;;; under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 3 of the License, or (at
12 ;;; your option) any later version.
14 ;;; GNU Guix is distributed in the hope that it will be useful, but
15 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22 (define-module (test-hackage)
23 #:use-module (guix import cabal)
24 #:use-module (guix import hackage)
25 #:use-module (guix tests)
26 #:use-module (srfi srfi-64)
27 #:use-module (ice-9 match))
32 homepage: http://test.org
34 description: description
38 HTTP >= 4000.2.5 && < 4000.3,
45 homepage: http://test.org
47 description: description
51 HTTP >= 4000.2.5 && < 4000.3,
56 ;; Check compiler implementation test with and without spaces.
60 homepage: http://test.org
62 description: description
65 if impl(ghc >= 7.2 && < 7.6)
67 if impl(ghc>=7.2&&<7.6)
71 HTTP >= 4000.2.5 && < 4000.3,
75 ;; Check "-any", "-none" when name is different.
79 homepage: http://test.org
81 description: description
86 if impl(ghc>=7.2&&<7.6)
90 HTTP >= 4000.2.5 && < 4000.3,
94 ;; Check "-any", "-none".
98 homepage: http://test.org
100 description: description
105 HTTP >= 4000.2.5 && < 4000.3,
107 Build-depends: mtl >= 2.0 && < 3
108 if impl(ghc>=7.2&&<7.6)
112 ;; Check "custom-setup".
117 homepage: http://test.org
119 description: description
122 setup-depends: base >= 4.7 && < 5,
126 if impl(ghc>=7.2&&<7.6)
130 HTTP >= 4000.2.5 && < 4000.3,
134 ;; A fragment of a real Cabal file with minor modification to check precedence
135 ;; of 'and' over 'or', missing final newline, spaces between keywords and
136 ;; parentheses and between key and column.
137 (define test-read-cabal-1
140 -- Choose which library versions to use.
142 Build-depends: base >= 4.8 && < 5
145 Build-depends: base >= 4 && < 4.8
148 Build-depends: base >= 3 && < 4
150 Build-depends: base < 3
151 if flag(base4point8) || flag (base4) && flag(base3)
152 Build-depends: random
153 Build-depends : containers
155 -- Modules that are always built.
157 Test.QuickCheck.Exception")
159 (test-begin "hackage")
161 (define-syntax-rule (define-package-matcher name pattern)
165 (x (pk 'fail x #f)))))
167 (define-package-matcher match-ghc-foo
174 ('uri ('string-append
175 "https://hackage.haskell.org/package/foo/foo-"
181 ('build-system 'haskell-build-system)
182 ('inputs ('list 'ghc-http))
183 ('home-page "http://test.org")
184 ('synopsis (? string?))
185 ('description (? string?))
186 ('license 'license:bsd-3)))
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)
225 ('inputs ('list 'ghc-b 'ghc-http))
226 ('native-inputs ('list 'ghc-haskell-gi))
227 ('home-page "http://test.org")
228 ('synopsis (? string?))
229 ('description (? string?))
230 ('license 'license:bsd-3)))
232 (test-assert "hackage->guix-package test 6"
233 (eval-test-with-cabal test-cabal-6 match-ghc-foo-6))
235 ;; Check multi-line layouted description.
236 (define test-cabal-multiline-layout
239 homepage: http://test.org
241 description: first line
246 HTTP >= 4000.2.5 && < 4000.3,
250 (test-assert "hackage->guix-package test multiline desc (layout)"
251 (eval-test-with-cabal test-cabal-multiline-layout match-ghc-foo))
253 ;; Check multi-line braced description.
254 (define test-cabal-multiline-braced
257 homepage: http://test.org
266 HTTP >= 4000.2.5 && < 4000.3,
270 (test-assert "hackage->guix-package test multiline desc (braced)"
271 (eval-test-with-cabal test-cabal-multiline-braced match-ghc-foo))
273 ;; Check mixed layout. Compare e.g. warp.
274 (define test-cabal-mixed-layout
277 homepage: http://test.org
279 description: description
283 HTTP >= 4000.2.5 && < 4000.3,
288 ;; Fails: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=35743
290 (test-assert "hackage->guix-package test mixed layout"
291 (eval-test-with-cabal test-cabal-mixed-layout match-ghc-foo))
293 ;; Check flag executable. Compare e.g. darcs.
294 (define test-cabal-flag-executable
297 homepage: http://test.org
299 description: description
302 description: Build executable
311 HTTP >= 4000.2.5 && < 4000.3,
315 (test-assert "hackage->guix-package test flag executable"
316 (eval-test-with-cabal test-cabal-flag-executable match-ghc-foo))
318 ;; Check Hackage Cabal revisions.
319 (define test-cabal-revision
323 homepage: http://test.org
325 description: description
329 HTTP >= 4000.2.5 && < 4000.3,
333 (define-package-matcher match-ghc-foo-revision
340 ('uri ('string-append
341 "https://hackage.haskell.org/package/foo/foo-"
347 ('build-system 'haskell-build-system)
348 ('inputs ('list 'ghc-http))
352 ("2" "0xxd88fb659f0krljidbvvmkh9ppjnx83j0nqzx8whcg4n5qbyng"))))
353 ('home-page "http://test.org")
354 ('synopsis (? string?))
355 ('description (? string?))
356 ('license 'license:bsd-3)))
358 (test-assert "hackage->guix-package test cabal revision"
359 (eval-test-with-cabal test-cabal-revision match-ghc-foo-revision))
361 (test-assert "read-cabal test 1"
362 (match (call-with-input-string test-read-cabal-1 read-cabal)
363 ((("name" ("test-me"))
365 (('if ('flag "base4point8")
366 (("build-depends" ("base >= 4.8 && < 5")))
367 (('if ('flag "base4")
368 (("build-depends" ("base >= 4 && < 4.8")))
369 (('if ('flag "base3")
370 (("build-depends" ("base >= 3 && < 4")))
371 (("build-depends" ("base < 3"))))))))
372 ('if ('or ('flag "base4point8")
373 ('and ('flag "base4") ('flag "base3")))
374 (("build-depends" ("random")))
376 ("build-depends" ("containers"))
377 ("exposed-modules" ("Test.QuickCheck.Exception")))))
379 (x (pk 'fail x #f))))
381 (define test-cabal-import
384 homepage: http://test.org
386 description: description
390 HTTP >= 4000.2.5 && < 4000.3,
397 (define-package-matcher match-ghc-foo-import
404 ('uri ('string-append
405 "https://hackage.haskell.org/package/foo/foo-"
411 ('build-system 'haskell-build-system)
412 ('inputs ('list 'ghc-http))
413 ('home-page "http://test.org")
414 ('synopsis (? string?))
415 ('description (? string?))
416 ('license 'license:bsd-3)))
418 (test-assert "hackage->guix-package test cabal import"
419 (eval-test-with-cabal test-cabal-import match-ghc-foo-import))