1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (test-hackage)
20 #:use-module (guix import cabal)
21 #:use-module (guix import hackage)
22 #:use-module (guix tests)
23 #:use-module (srfi srfi-64)
24 #:use-module (ice-9 match))
29 homepage: http://test.org
31 description: description
35 HTTP >= 4000.2.5 && < 4000.3,
42 homepage: http://test.org
44 description: description
48 HTTP >= 4000.2.5 && < 4000.3,
53 ;; Check compiler implementation test with and without spaces.
57 homepage: http://test.org
59 description: description
62 if impl(ghc >= 7.2 && < 7.6)
64 if impl(ghc>=7.2&&<7.6)
68 HTTP >= 4000.2.5 && < 4000.3,
72 ;; Check "-any", "-none" when name is different.
76 homepage: http://test.org
78 description: description
83 if impl(ghc>=7.2&&<7.6)
87 HTTP >= 4000.2.5 && < 4000.3,
91 ;; Check "-any", "-none".
95 homepage: http://test.org
97 description: description
102 HTTP >= 4000.2.5 && < 4000.3,
104 Build-depends: mtl >= 2.0 && < 3
105 if impl(ghc>=7.2&&<7.6)
109 ;; Check "custom-setup".
114 homepage: http://test.org
116 description: description
119 setup-depends: base >= 4.7 && < 5,
123 if impl(ghc>=7.2&&<7.6)
127 HTTP >= 4000.2.5 && < 4000.3,
131 ;; A fragment of a real Cabal file with minor modification to check precedence
132 ;; of 'and' over 'or', missing final newline, spaces between keywords and
133 ;; parentheses and between key and column.
134 (define test-read-cabal-1
137 -- Choose which library versions to use.
139 Build-depends: base >= 4.8 && < 5
142 Build-depends: base >= 4 && < 4.8
145 Build-depends: base >= 3 && < 4
147 Build-depends: base < 3
148 if flag(base4point8) || flag (base4) && flag(base3)
149 Build-depends: random
150 Build-depends : containers
152 -- Modules that are always built.
154 Test.QuickCheck.Exception")
156 (test-begin "hackage")
158 (define-syntax-rule (define-package-matcher name pattern)
162 (x (pk 'fail x #f)))))
164 (define-package-matcher match-ghc-foo
171 ('uri ('string-append
172 "https://hackage.haskell.org/package/foo/foo-"
178 ('build-system 'haskell-build-system)
181 (("ghc-http" ('unquote 'ghc-http))
182 ("ghc-mtl" ('unquote 'ghc-mtl)))))
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))
229 ("ghc-mtl" ('unquote 'ghc-mtl)))))
232 (("ghc-haskell-gi" ('unquote 'ghc-haskell-gi)))))
233 ('home-page "http://test.org")
234 ('synopsis (? string?))
235 ('description (? string?))
238 (test-assert "hackage->guix-package test 6"
239 (eval-test-with-cabal test-cabal-6 match-ghc-foo-6))
241 (test-assert "read-cabal test 1"
242 (match (call-with-input-string test-read-cabal-1 read-cabal)
243 ((("name" ("test-me"))
245 (('if ('flag "base4point8")
246 (("build-depends" ("base >= 4.8 && < 5")))
247 (('if ('flag "base4")
248 (("build-depends" ("base >= 4 && < 4.8")))
249 (('if ('flag "base3")
250 (("build-depends" ("base >= 3 && < 4")))
251 (("build-depends" ("base < 3"))))))))
252 ('if ('or ('flag "base4point8")
253 ('and ('flag "base4") ('flag "base3")))
254 (("build-depends" ("random")))
256 ("build-depends" ("containers"))
257 ("exposed-modules" ("Test.QuickCheck.Exception")))))
259 (x (pk 'fail x #f))))