lzlib: 'make-lzip-input-port' better handles end of decompression.
[jackhill/guix/guix.git] / tests / hackage.scm
CommitLineData
b29455cf
FB
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/>.
18
19(define-module (test-hackage)
a4154748 20 #:use-module (guix import cabal)
b29455cf
FB
21 #:use-module (guix import hackage)
22 #:use-module (guix tests)
23 #:use-module (srfi srfi-64)
24 #:use-module (ice-9 match))
25
26(define test-cabal-1
27 "name: foo
28version: 1.0.0
29homepage: http://test.org
30synopsis: synopsis
31description: description
32license: BSD3
33executable cabal
34 build-depends:
35 HTTP >= 4000.2.5 && < 4000.3,
36 mtl >= 2.0 && < 3
37")
38
b29455cf 39(define test-cabal-2
b29455cf
FB
40 "name: foo
41version: 1.0.0
42homepage: http://test.org
43synopsis: synopsis
44description: description
45license: BSD3
a4154748
FB
46executable cabal {
47build-depends:
48 HTTP >= 4000.2.5 && < 4000.3,
49 mtl >= 2.0 && < 3
50}
b29455cf
FB
51")
52
d3c827e4
FB
53;; Check compiler implementation test with and without spaces.
54(define test-cabal-3
55 "name: foo
56version: 1.0.0
57homepage: http://test.org
58synopsis: synopsis
59description: description
60license: BSD3
61library
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
70")
71
e39a44f3
DM
72;; Check "-any", "-none" when name is different.
73(define test-cabal-4
74 "name: foo
75version: 1.0.0
76homepage: http://test.org
77synopsis: synopsis
78description: description
79license: BSD3
80library
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
89")
90
91;; Check "-any", "-none".
92(define test-cabal-5
93 "name: foo
94version: 1.0.0
95homepage: http://test.org
96synopsis: synopsis
97description: description
98license: BSD3
99library
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
107")
108
109;; Check "custom-setup".
110(define test-cabal-6
111 "name: foo
112build-type: Custom
113version: 1.0.0
114homepage: http://test.org
115synopsis: synopsis
116description: description
117license: BSD3
118custom-setup
119 setup-depends: base >= 4.7 && < 5,
120 Cabal >= 1.24,
121 haskell-gi == 0.21.*
122library
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
129")
130
a4154748 131;; A fragment of a real Cabal file with minor modification to check precedence
d3c827e4
FB
132;; of 'and' over 'or', missing final newline, spaces between keywords and
133;; parentheses and between key and column.
a4154748
FB
134(define test-read-cabal-1
135 "name: test-me
136library
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
d3c827e4 148 if flag(base4point8) || flag (base4) && flag(base3)
a4154748 149 Build-depends: random
d3c827e4 150 Build-depends : containers
a4154748
FB
151
152 -- Modules that are always built.
153 Exposed-Modules:
d3c827e4 154 Test.QuickCheck.Exception")
b29455cf
FB
155
156(test-begin "hackage")
157
d3c827e4 158(define* (eval-test-with-cabal test-cabal #:key (cabal-environment '()))
b29455cf
FB
159 (mock
160 ((guix import hackage) hackage-fetch
161 (lambda (name-version)
162 (call-with-input-string test-cabal
163 read-cabal)))
d3c827e4 164 (match (hackage->guix-package "foo" #:cabal-environment cabal-environment)
b29455cf
FB
165 (('package
166 ('name "ghc-foo")
167 ('version "1.0.0")
168 ('source
169 ('origin
170 ('method 'url-fetch)
171 ('uri ('string-append
7060b281 172 "https://hackage.haskell.org/package/foo/foo-"
b29455cf
FB
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)))))
190
191(test-assert "hackage->guix-package test 1"
192 (eval-test-with-cabal test-cabal-1))
193
194(test-assert "hackage->guix-package test 2"
195 (eval-test-with-cabal test-cabal-2))
196
d3c827e4
FB
197(test-assert "hackage->guix-package test 3"
198 (eval-test-with-cabal test-cabal-3
199 #:cabal-environment '(("impl" . "ghc-7.8"))))
200
e39a44f3
DM
201(test-assert "hackage->guix-package test 4"
202 (eval-test-with-cabal test-cabal-4
203 #:cabal-environment '(("impl" . "ghc-7.8"))))
204
205(test-assert "hackage->guix-package test 5"
206 (eval-test-with-cabal test-cabal-5
207 #:cabal-environment '(("impl" . "ghc-7.8"))))
208
209(test-assert "hackage->guix-package test 6"
ad7466aa
LC
210 (mock
211 ((guix import hackage) hackage-fetch
212 (lambda (name-version)
213 (call-with-input-string test-cabal-6
214 read-cabal)))
215 (match (hackage->guix-package "foo")
216 (('package
217 ('name "ghc-foo")
218 ('version "1.0.0")
219 ('source
220 ('origin
221 ('method 'url-fetch)
222 ('uri ('string-append
223 "https://hackage.haskell.org/package/foo/foo-"
224 'version
225 ".tar.gz"))
226 ('sha256
227 ('base32
228 (? string? hash)))))
229 ('build-system 'haskell-build-system)
230 ('inputs
231 ('quasiquote
232 (("ghc-b" ('unquote 'ghc-b))
233 ("ghc-http" ('unquote 'ghc-http))
234 ("ghc-mtl" ('unquote 'ghc-mtl)))))
235 ('native-inputs
236 ('quasiquote
237 (("ghc-haskell-gi" ('unquote 'ghc-haskell-gi)))))
238 ('home-page "http://test.org")
239 ('synopsis (? string?))
240 ('description (? string?))
241 ('license 'bsd-3))
242 #t)
243 (x
244 (pk 'fail x #f)))))
e39a44f3 245
a4154748
FB
246(test-assert "read-cabal test 1"
247 (match (call-with-input-string test-read-cabal-1 read-cabal)
248 ((("name" ("test-me"))
249 ('section 'library
250 (('if ('flag "base4point8")
251 (("build-depends" ("base >= 4.8 && < 5")))
252 (('if ('flag "base4")
253 (("build-depends" ("base >= 4 && < 4.8")))
254 (('if ('flag "base3")
255 (("build-depends" ("base >= 3 && < 4")))
256 (("build-depends" ("base < 3"))))))))
257 ('if ('or ('flag "base4point8")
258 ('and ('flag "base4") ('flag "base3")))
259 (("build-depends" ("random")))
260 ())
261 ("build-depends" ("containers"))
262 ("exposed-modules" ("Test.QuickCheck.Exception")))))
b29455cf 263 #t)
a4154748 264 (x (pk 'fail x #f))))
b29455cf
FB
265
266(test-end "hackage")