Commit | Line | Data |
---|---|---|
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 | |
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 | |
37 | ") | |
38 | ||
b29455cf | 39 | (define test-cabal-2 |
b29455cf FB |
40 | "name: foo |
41 | version: 1.0.0 | |
42 | homepage: http://test.org | |
43 | synopsis: synopsis | |
44 | description: description | |
45 | license: BSD3 | |
a4154748 FB |
46 | executable cabal { |
47 | build-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 | |
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 | |
70 | ") | |
71 | ||
a4154748 | 72 | ;; A fragment of a real Cabal file with minor modification to check precedence |
d3c827e4 FB |
73 | ;; of 'and' over 'or', missing final newline, spaces between keywords and |
74 | ;; parentheses and between key and column. | |
a4154748 FB |
75 | (define test-read-cabal-1 |
76 | "name: test-me | |
77 | library | |
78 | -- Choose which library versions to use. | |
79 | if flag(base4point8) | |
80 | Build-depends: base >= 4.8 && < 5 | |
81 | else | |
82 | if flag(base4) | |
83 | Build-depends: base >= 4 && < 4.8 | |
84 | else | |
85 | if flag(base3) | |
86 | Build-depends: base >= 3 && < 4 | |
87 | else | |
88 | Build-depends: base < 3 | |
d3c827e4 | 89 | if flag(base4point8) || flag (base4) && flag(base3) |
a4154748 | 90 | Build-depends: random |
d3c827e4 | 91 | Build-depends : containers |
a4154748 FB |
92 | |
93 | -- Modules that are always built. | |
94 | Exposed-Modules: | |
d3c827e4 | 95 | Test.QuickCheck.Exception") |
b29455cf FB |
96 | |
97 | (test-begin "hackage") | |
98 | ||
d3c827e4 | 99 | (define* (eval-test-with-cabal test-cabal #:key (cabal-environment '())) |
b29455cf FB |
100 | (mock |
101 | ((guix import hackage) hackage-fetch | |
102 | (lambda (name-version) | |
103 | (call-with-input-string test-cabal | |
104 | read-cabal))) | |
d3c827e4 | 105 | (match (hackage->guix-package "foo" #:cabal-environment cabal-environment) |
b29455cf FB |
106 | (('package |
107 | ('name "ghc-foo") | |
108 | ('version "1.0.0") | |
109 | ('source | |
110 | ('origin | |
111 | ('method 'url-fetch) | |
112 | ('uri ('string-append | |
7060b281 | 113 | "https://hackage.haskell.org/package/foo/foo-" |
b29455cf FB |
114 | 'version |
115 | ".tar.gz")) | |
116 | ('sha256 | |
117 | ('base32 | |
118 | (? string? hash))))) | |
119 | ('build-system 'haskell-build-system) | |
120 | ('inputs | |
121 | ('quasiquote | |
122 | (("ghc-http" ('unquote 'ghc-http)) | |
123 | ("ghc-mtl" ('unquote 'ghc-mtl))))) | |
124 | ('home-page "http://test.org") | |
125 | ('synopsis (? string?)) | |
126 | ('description (? string?)) | |
127 | ('license 'bsd-3)) | |
128 | #t) | |
129 | (x | |
130 | (pk 'fail x #f))))) | |
131 | ||
132 | (test-assert "hackage->guix-package test 1" | |
133 | (eval-test-with-cabal test-cabal-1)) | |
134 | ||
135 | (test-assert "hackage->guix-package test 2" | |
136 | (eval-test-with-cabal test-cabal-2)) | |
137 | ||
d3c827e4 FB |
138 | (test-assert "hackage->guix-package test 3" |
139 | (eval-test-with-cabal test-cabal-3 | |
140 | #:cabal-environment '(("impl" . "ghc-7.8")))) | |
141 | ||
a4154748 FB |
142 | (test-assert "read-cabal test 1" |
143 | (match (call-with-input-string test-read-cabal-1 read-cabal) | |
144 | ((("name" ("test-me")) | |
145 | ('section 'library | |
146 | (('if ('flag "base4point8") | |
147 | (("build-depends" ("base >= 4.8 && < 5"))) | |
148 | (('if ('flag "base4") | |
149 | (("build-depends" ("base >= 4 && < 4.8"))) | |
150 | (('if ('flag "base3") | |
151 | (("build-depends" ("base >= 3 && < 4"))) | |
152 | (("build-depends" ("base < 3")))))))) | |
153 | ('if ('or ('flag "base4point8") | |
154 | ('and ('flag "base4") ('flag "base3"))) | |
155 | (("build-depends" ("random"))) | |
156 | ()) | |
157 | ("build-depends" ("containers")) | |
158 | ("exposed-modules" ("Test.QuickCheck.Exception"))))) | |
b29455cf | 159 | #t) |
a4154748 | 160 | (x (pk 'fail x #f)))) |
b29455cf FB |
161 | |
162 | (test-end "hackage") |