gnu: ubridge: Update to 0.9.15.
[guix.git] / tests / hackage.scm
blobe17851a213bc69be408f1633367069474263c28e
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
3 ;;;
4 ;;; This file is part of GNU Guix.
5 ;;;
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.
10 ;;;
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.
15 ;;;
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))
26 (define test-cabal-1
27   "name: foo
28 version: 1.0.0
29 homepage: http://test.org
30 synopsis: synopsis
31 description: description
32 license: BSD3
33 executable cabal
34   build-depends:
35     HTTP       >= 4000.2.5 && < 4000.3,
36     mtl        >= 2.0      && < 3
39 (define test-cabal-2
40   "name: foo
41 version: 1.0.0
42 homepage: http://test.org
43 synopsis: synopsis
44 description: description
45 license: BSD3
46 executable cabal {
47 build-depends:
48   HTTP       >= 4000.2.5 && < 4000.3,
49   mtl        >= 2.0      && < 3
53 ;; Check compiler implementation test with and without spaces.
54 (define test-cabal-3
55   "name: foo
56 version: 1.0.0
57 homepage: http://test.org
58 synopsis: synopsis
59 description: description
60 license: BSD3
61 library
62   if impl(ghc >= 7.2 && < 7.6)
63     Build-depends: ghc-a
64   if impl(ghc>=7.2&&<7.6)
65     Build-depends: ghc-b
66   if impl(ghc == 7.8)
67     Build-depends: 
68       HTTP       >= 4000.2.5 && < 4000.3,
69       mtl        >= 2.0      && < 3
72 ;; Check "-any", "-none" when name is different.
73 (define test-cabal-4
74   "name: foo
75 version: 1.0.0
76 homepage: http://test.org
77 synopsis: synopsis
78 description: description
79 license: BSD3
80 library
81   if impl(ghcjs -any)
82     Build-depends: ghc-a
83   if impl(ghc>=7.2&&<7.6)
84     Build-depends: ghc-b
85   if impl(ghc == 7.8)
86     Build-depends: 
87       HTTP       >= 4000.2.5 && < 4000.3,
88       mtl        >= 2.0      && < 3
91 ;; Check "-any", "-none".
92 (define test-cabal-5
93   "name: foo
94 version: 1.0.0
95 homepage: http://test.org
96 synopsis: synopsis
97 description: description
98 license: BSD3
99 library
100   if impl(ghc == 7.8)
101     Build-depends: 
102       HTTP       >= 4000.2.5 && < 4000.3,
103   if impl(ghc -any)
104     Build-depends: mtl        >= 2.0      && < 3
105   if impl(ghc>=7.2&&<7.6)
106     Build-depends: ghc-b
109 ;; Check "custom-setup".
110 (define test-cabal-6
111   "name: foo
112 build-type: Custom
113 version: 1.0.0
114 homepage: http://test.org
115 synopsis: synopsis
116 description: description
117 license: BSD3
118 custom-setup
119   setup-depends: base >= 4.7 && < 5,
120                  Cabal >= 1.24,
121                  haskell-gi == 0.21.*
122 library
123   if impl(ghc>=7.2&&<7.6)
124     Build-depends: ghc-b
125   if impl(ghc == 7.8)
126     Build-depends: 
127       HTTP       >= 4000.2.5 && < 4000.3,
128       mtl        >= 2.0      && < 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
135   "name: test-me
136 library
137   -- Choose which library versions to use.
138   if flag(base4point8)
139     Build-depends: base >= 4.8 && < 5
140   else
141     if flag(base4)
142       Build-depends: base >= 4 && < 4.8
143     else
144       if flag(base3)
145         Build-depends: base >= 3 && < 4
146       else
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.
153   Exposed-Modules:
154     Test.QuickCheck.Exception")
156 (test-begin "hackage")
158 (define* (eval-test-with-cabal test-cabal #:key (cabal-environment '()))
159   (mock
160    ((guix import hackage) hackage-fetch
161     (lambda (name-version)
162       (call-with-input-string test-cabal
163         read-cabal)))
164    (match (hackage->guix-package "foo" #:cabal-environment cabal-environment)
165      (('package
166         ('name "ghc-foo")
167         ('version "1.0.0")
168         ('source
169          ('origin
170            ('method 'url-fetch)
171            ('uri ('string-append
172                   "https://hackage.haskell.org/package/foo/foo-"
173                   'version
174                   ".tar.gz"))
175            ('sha256
176             ('base32
177              (? string? hash)))))
178         ('build-system 'haskell-build-system)
179         ('inputs
180          ('quasiquote
181           (("ghc-http" ('unquote 'ghc-http))
182            ("ghc-mtl" ('unquote 'ghc-mtl)))))
183         ('home-page "http://test.org")
184         ('synopsis (? string?))
185         ('description (? string?))
186         ('license 'bsd-3))
187       #t)
188      (x
189       (pk 'fail x #f)))))
191 (test-assert "hackage->guix-package test 1"
192   (eval-test-with-cabal test-cabal-1))
194 (test-assert "hackage->guix-package test 2"
195   (eval-test-with-cabal test-cabal-2))
197 (test-assert "hackage->guix-package test 3"
198   (eval-test-with-cabal test-cabal-3
199                         #:cabal-environment '(("impl" . "ghc-7.8"))))
201 (test-assert "hackage->guix-package test 4"
202   (eval-test-with-cabal test-cabal-4
203                         #:cabal-environment '(("impl" . "ghc-7.8"))))
205 (test-assert "hackage->guix-package test 5"
206   (eval-test-with-cabal test-cabal-5
207                         #:cabal-environment '(("impl" . "ghc-7.8"))))
209 (test-assert "hackage->guix-package test 6"
210   (eval-test-with-cabal test-cabal-6
211                         #:cabal-environment '(("impl" . "ghc-7.8"))))
213 (test-assert "read-cabal test 1"
214   (match (call-with-input-string test-read-cabal-1 read-cabal)
215     ((("name" ("test-me"))
216       ('section 'library
217                (('if ('flag "base4point8")
218                     (("build-depends" ("base >= 4.8 && < 5")))
219                     (('if ('flag "base4")
220                          (("build-depends" ("base >= 4 && < 4.8")))
221                          (('if ('flag "base3")
222                               (("build-depends" ("base >= 3 && < 4")))
223                               (("build-depends" ("base < 3"))))))))
224                 ('if ('or ('flag "base4point8")
225                           ('and ('flag "base4") ('flag "base3")))
226                     (("build-depends" ("random")))
227                     ())
228                 ("build-depends" ("containers"))
229                 ("exposed-modules" ("Test.QuickCheck.Exception")))))
230      #t)
231     (x (pk 'fail x #f))))
233 (test-end "hackage")