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 ('home-page "http://test.org")
183 ('synopsis (? string?))
184 ('description (? string?))
187 (define* (eval-test-with-cabal test-cabal matcher #:key (cabal-environment '()))
188 (define port (open-input-string test-cabal))
189 (matcher (hackage->guix-package "foo" #:port port #:cabal-environment cabal-environment)))
191 (test-assert "hackage->guix-package test 1"
192 (eval-test-with-cabal test-cabal-1 match-ghc-foo))
194 (test-assert "hackage->guix-package test 2"
195 (eval-test-with-cabal test-cabal-2 match-ghc-foo))
197 (test-assert "hackage->guix-package test 3"
198 (eval-test-with-cabal test-cabal-3 match-ghc-foo
199 #:cabal-environment '(("impl" . "ghc-7.8"))))
201 (test-assert "hackage->guix-package test 4"
202 (eval-test-with-cabal test-cabal-4 match-ghc-foo
203 #:cabal-environment '(("impl" . "ghc-7.8"))))
205 (test-assert "hackage->guix-package test 5"
206 (eval-test-with-cabal test-cabal-5 match-ghc-foo
207 #:cabal-environment '(("impl" . "ghc-7.8"))))
209 (define-package-matcher match-ghc-foo-6
216 ('uri ('string-append
217 "https://hackage.haskell.org/package/foo/foo-"
223 ('build-system 'haskell-build-system)
226 (("ghc-b" ('unquote 'ghc-b))
227 ("ghc-http" ('unquote 'ghc-http)))))
230 (("ghc-haskell-gi" ('unquote 'ghc-haskell-gi)))))
231 ('home-page "http://test.org")
232 ('synopsis (? string?))
233 ('description (? string?))
236 (test-assert "hackage->guix-package test 6"
237 (eval-test-with-cabal test-cabal-6 match-ghc-foo-6))
239 (test-assert "read-cabal test 1"
240 (match (call-with-input-string test-read-cabal-1 read-cabal)
241 ((("name" ("test-me"))
243 (('if ('flag "base4point8")
244 (("build-depends" ("base >= 4.8 && < 5")))
245 (('if ('flag "base4")
246 (("build-depends" ("base >= 4 && < 4.8")))
247 (('if ('flag "base3")
248 (("build-depends" ("base >= 3 && < 4")))
249 (("build-depends" ("base < 3"))))))))
250 ('if ('or ('flag "base4point8")
251 ('and ('flag "base4") ('flag "base3")))
252 (("build-depends" ("random")))
254 ("build-depends" ("containers"))
255 ("exposed-modules" ("Test.QuickCheck.Exception")))))
257 (x (pk 'fail x #f))))