Commit | Line | Data |
---|---|---|
233e7676 | 1 | ;;; GNU Guix --- Functional package management for GNU |
e509d152 | 2 | ;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org> |
e3ce5d70 | 3 | ;;; |
233e7676 | 4 | ;;; This file is part of GNU Guix. |
e3ce5d70 | 5 | ;;; |
233e7676 | 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it |
e3ce5d70 LC |
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 | ;;; | |
233e7676 | 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but |
e3ce5d70 LC |
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 | |
233e7676 | 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
e3ce5d70 LC |
18 | |
19 | ||
20 | (define-module (test-packages) | |
21 | #:use-module (guix store) | |
22 | #:use-module (guix utils) | |
23 | #:use-module (guix derivations) | |
24 | #:use-module (guix packages) | |
a18eda27 | 25 | #:use-module (guix build-system) |
be13fbfa | 26 | #:use-module (guix build-system trivial) |
a3d73f59 | 27 | #:use-module (guix build-system gnu) |
59a43334 | 28 | #:use-module (gnu packages) |
1ffa7090 LC |
29 | #:use-module (gnu packages base) |
30 | #:use-module (gnu packages bootstrap) | |
e509d152 | 31 | #:use-module (srfi srfi-11) |
6b1891b0 | 32 | #:use-module (srfi srfi-26) |
9b222abe | 33 | #:use-module (srfi srfi-34) |
6b1891b0 | 34 | #:use-module (srfi srfi-64) |
860a6f1a | 35 | #:use-module (rnrs io ports) |
6b1891b0 | 36 | #:use-module (ice-9 match)) |
e3ce5d70 LC |
37 | |
38 | ;; Test the high-level packaging layer. | |
39 | ||
40 | (define %store | |
41 | (false-if-exception (open-connection))) | |
42 | ||
81dbd783 LC |
43 | (when %store |
44 | ;; Make sure we build everything by ourselves. | |
45 | (set-build-options %store #:use-substitutes? #f)) | |
46 | ||
14da91e2 | 47 | \f |
e3ce5d70 LC |
48 | (test-begin "packages") |
49 | ||
a3d73f59 LC |
50 | (define-syntax-rule (dummy-package name* extra-fields ...) |
51 | (package (name name*) (version "0") (source #f) | |
52 | (build-system gnu-build-system) | |
d45122f5 | 53 | (synopsis #f) (description #f) |
1fb78cb2 | 54 | (home-page #f) (license #f) |
a3d73f59 LC |
55 | extra-fields ...)) |
56 | ||
d66c7096 LC |
57 | (test-assert "package-field-location" |
58 | (let () | |
59 | (define (goto port line column) | |
60 | (unless (and (= (port-column port) (- column 1)) | |
61 | (= (port-line port) (- line 1))) | |
62 | (unless (eof-object? (get-char port)) | |
63 | (goto port line column)))) | |
64 | ||
65 | (define read-at | |
66 | (match-lambda | |
67 | (($ <location> file line column) | |
68 | (call-with-input-file (search-path %load-path file) | |
69 | (lambda (port) | |
70 | (goto port line column) | |
71 | (read port)))))) | |
72 | ||
ee48b283 LC |
73 | ;; Until Guile 2.0.6 included, source properties were added only to pairs. |
74 | ;; Thus, check against both VALUE and (FIELD VALUE). | |
75 | (and (member (read-at (package-field-location %bootstrap-guile 'name)) | |
76 | (let ((name (package-name %bootstrap-guile))) | |
77 | (list name `(name ,name)))) | |
78 | (member (read-at (package-field-location %bootstrap-guile 'version)) | |
79 | (let ((version (package-version %bootstrap-guile))) | |
80 | (list version `(version ,version)))) | |
f903dc05 | 81 | (not (package-field-location %bootstrap-guile 'does-not-exist))))) |
d66c7096 | 82 | |
a3d73f59 LC |
83 | (test-assert "package-transitive-inputs" |
84 | (let* ((a (dummy-package "a")) | |
85 | (b (dummy-package "b" | |
86 | (propagated-inputs `(("a" ,a))))) | |
87 | (c (dummy-package "c" | |
88 | (inputs `(("a" ,a))))) | |
89 | (d (dummy-package "d" | |
90 | (propagated-inputs `(("x" "something.drv"))))) | |
91 | (e (dummy-package "e" | |
92 | (inputs `(("b" ,b) ("c" ,c) ("d" ,d)))))) | |
93 | (and (null? (package-transitive-inputs a)) | |
94 | (equal? `(("a" ,a)) (package-transitive-inputs b)) | |
95 | (equal? `(("a" ,a)) (package-transitive-inputs c)) | |
96 | (equal? (package-propagated-inputs d) | |
97 | (package-transitive-inputs d)) | |
98 | (equal? `(("b" ,b) ("b/a" ,a) ("c" ,c) | |
99 | ("d" ,d) ("d/x" "something.drv")) | |
100 | (pk 'x (package-transitive-inputs e)))))) | |
101 | ||
7357138b LC |
102 | (test-skip (if (not %store) 8 0)) |
103 | ||
104 | (test-assert "package-source-derivation, file" | |
105 | (let* ((file (search-path %load-path "guix.scm")) | |
106 | (package (package (inherit (dummy-package "p")) | |
107 | (source file))) | |
108 | (source (package-source-derivation %store | |
109 | (package-source package)))) | |
110 | (and (store-path? source) | |
111 | (valid-path? %store source) | |
112 | (equal? (call-with-input-file source get-bytevector-all) | |
113 | (call-with-input-file file get-bytevector-all))))) | |
114 | ||
115 | (test-assert "package-source-derivation, store path" | |
116 | (let* ((file (add-to-store %store "guix.scm" #t "sha256" | |
117 | (search-path %load-path "guix.scm"))) | |
118 | (package (package (inherit (dummy-package "p")) | |
119 | (source file))) | |
120 | (source (package-source-derivation %store | |
121 | (package-source package)))) | |
122 | (string=? file source))) | |
e509d152 | 123 | |
59688fc4 LC |
124 | (test-assert "return value" |
125 | (let ((drv (package-derivation %store (dummy-package "p")))) | |
126 | (and (derivation? drv) | |
127 | (file-exists? (derivation-file-name drv))))) | |
be13fbfa | 128 | |
d510ab46 LC |
129 | (test-assert "package-output" |
130 | (let* ((package (dummy-package "p")) | |
59688fc4 LC |
131 | (drv (package-derivation %store package))) |
132 | (and (derivation? drv) | |
133 | (string=? (derivation->output-path drv) | |
d510ab46 LC |
134 | (package-output %store package "out"))))) |
135 | ||
be13fbfa LC |
136 | (test-assert "trivial" |
137 | (let* ((p (package (inherit (dummy-package "trivial")) | |
138 | (build-system trivial-build-system) | |
139 | (source #f) | |
140 | (arguments | |
14da91e2 LC |
141 | `(#:guile ,%bootstrap-guile |
142 | #:builder | |
be13fbfa LC |
143 | (begin |
144 | (mkdir %output) | |
145 | (call-with-output-file (string-append %output "/test") | |
146 | (lambda (p) | |
147 | (display '(hello guix) p)))))))) | |
148 | (d (package-derivation %store p))) | |
149 | (and (build-derivations %store (list d)) | |
59688fc4 | 150 | (let ((p (pk 'drv d (derivation->output-path d)))) |
be13fbfa LC |
151 | (equal? '(hello guix) |
152 | (call-with-input-file (string-append p "/test") read)))))) | |
e3ce5d70 | 153 | |
860a6f1a LC |
154 | (test-assert "trivial with local file as input" |
155 | (let* ((i (search-path %load-path "ice-9/boot-9.scm")) | |
156 | (p (package (inherit (dummy-package "trivial-with-input-file")) | |
157 | (build-system trivial-build-system) | |
158 | (source #f) | |
159 | (arguments | |
160 | `(#:guile ,%bootstrap-guile | |
161 | #:builder (copy-file (assoc-ref %build-inputs "input") | |
162 | %output))) | |
163 | (inputs `(("input" ,i))))) | |
164 | (d (package-derivation %store p))) | |
165 | (and (build-derivations %store (list d)) | |
59688fc4 | 166 | (let ((p (pk 'drv d (derivation->output-path d)))) |
860a6f1a LC |
167 | (equal? (call-with-input-file p get-bytevector-all) |
168 | (call-with-input-file i get-bytevector-all)))))) | |
169 | ||
03761a44 LC |
170 | (test-assert "trivial with source" |
171 | (let* ((i (search-path %load-path "ice-9/boot-9.scm")) | |
172 | (p (package (inherit (dummy-package "trivial-with-source")) | |
173 | (build-system trivial-build-system) | |
174 | (source i) | |
175 | (arguments | |
176 | `(#:guile ,%bootstrap-guile | |
177 | #:builder (copy-file (assoc-ref %build-inputs "source") | |
178 | %output))))) | |
179 | (d (package-derivation %store p))) | |
180 | (and (build-derivations %store (list d)) | |
181 | (let ((p (derivation->output-path d))) | |
182 | (equal? (call-with-input-file p get-bytevector-all) | |
183 | (call-with-input-file i get-bytevector-all)))))) | |
184 | ||
592ef6c8 LC |
185 | (test-assert "trivial with system-dependent input" |
186 | (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input")) | |
187 | (build-system trivial-build-system) | |
188 | (source #f) | |
189 | (arguments | |
190 | `(#:guile ,%bootstrap-guile | |
191 | #:builder | |
192 | (let ((out (assoc-ref %outputs "out")) | |
193 | (bash (assoc-ref %build-inputs "bash"))) | |
194 | (zero? (system* bash "-c" | |
195 | (format #f "echo hello > ~a" out)))))) | |
dd6b9a37 LC |
196 | (inputs `(("bash" ,(search-bootstrap-binary "bash" |
197 | (%current-system))))))) | |
592ef6c8 LC |
198 | (d (package-derivation %store p))) |
199 | (and (build-derivations %store (list d)) | |
59688fc4 | 200 | (let ((p (pk 'drv d (derivation->output-path d)))) |
592ef6c8 LC |
201 | (eq? 'hello (call-with-input-file p read)))))) |
202 | ||
a18eda27 LC |
203 | (test-assert "search paths" |
204 | (let* ((p (make-prompt-tag "return-search-paths")) | |
205 | (s (build-system | |
206 | (name "raw") | |
207 | (description "Raw build system with direct store access") | |
208 | (build (lambda* (store name source inputs | |
209 | #:key outputs system search-paths) | |
210 | search-paths)))) | |
211 | (x (list (search-path-specification | |
212 | (variable "GUILE_LOAD_PATH") | |
213 | (directories '("share/guile/site/2.0"))) | |
214 | (search-path-specification | |
215 | (variable "GUILE_LOAD_COMPILED_PATH") | |
216 | (directories '("share/guile/site/2.0"))))) | |
217 | (a (package (inherit (dummy-package "guile")) | |
218 | (build-system s) | |
219 | (native-search-paths x))) | |
220 | (b (package (inherit (dummy-package "guile-foo")) | |
221 | (build-system s) | |
222 | (inputs `(("guile" ,a))))) | |
223 | (c (package (inherit (dummy-package "guile-bar")) | |
224 | (build-system s) | |
225 | (inputs `(("guile" ,a) | |
226 | ("guile-foo" ,b)))))) | |
227 | (let-syntax ((collect (syntax-rules () | |
228 | ((_ body ...) | |
229 | (call-with-prompt p | |
230 | (lambda () | |
231 | body ...) | |
232 | (lambda (k search-paths) | |
233 | search-paths)))))) | |
234 | (and (null? (collect (package-derivation %store a))) | |
235 | (equal? x (collect (package-derivation %store b))) | |
236 | (equal? x (collect (package-derivation %store c))))))) | |
237 | ||
9c1edabd | 238 | (test-assert "package-cross-derivation" |
59688fc4 LC |
239 | (let ((drv (package-cross-derivation %store (dummy-package "p") |
240 | "mips64el-linux-gnu"))) | |
241 | (and (derivation? drv) | |
242 | (file-exists? (derivation-file-name drv))))) | |
9c1edabd | 243 | |
5dce8218 LC |
244 | (test-assert "package-cross-derivation, trivial-build-system" |
245 | (let ((p (package (inherit (dummy-package "p")) | |
246 | (build-system trivial-build-system) | |
247 | (arguments '(#:builder (exit 1)))))) | |
59688fc4 LC |
248 | (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu"))) |
249 | (derivation? drv)))) | |
5dce8218 | 250 | |
9b222abe LC |
251 | (test-assert "package-cross-derivation, no cross builder" |
252 | (let* ((b (build-system (inherit trivial-build-system) | |
253 | (cross-build #f))) | |
254 | (p (package (inherit (dummy-package "p")) | |
255 | (build-system b)))) | |
256 | (guard (c ((package-cross-build-system-error? c) | |
257 | (eq? (package-error-package c) p))) | |
258 | (package-cross-derivation %store p "mips64el-linux-gnu") | |
259 | #f))) | |
260 | ||
ad1ebab3 LC |
261 | (unless (false-if-exception (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)) |
262 | (test-skip 1)) | |
9e782349 LC |
263 | (test-assert "GNU Make, bootstrap" |
264 | ;; GNU Make is the first program built during bootstrap; we choose it | |
265 | ;; here so that the test doesn't last for too long. | |
1ffa7090 | 266 | (let ((gnu-make (@@ (gnu packages base) gnu-make-boot0))) |
9e782349 LC |
267 | (and (package? gnu-make) |
268 | (or (location? (package-location gnu-make)) | |
269 | (not (package-location gnu-make))) | |
270 | (let* ((drv (package-derivation %store gnu-make)) | |
59688fc4 | 271 | (out (derivation->output-path drv))) |
14da91e2 | 272 | (and (build-derivations %store (list drv)) |
9e782349 | 273 | (file-exists? (string-append out "/bin/make"))))))) |
e3ce5d70 | 274 | |
ba326ce4 LC |
275 | (test-eq "fold-packages" hello |
276 | (fold-packages (lambda (p r) | |
277 | (if (string=? (package-name p) "hello") | |
278 | p | |
279 | r)) | |
280 | #f)) | |
281 | ||
6b1891b0 LC |
282 | (test-assert "find-packages-by-name" |
283 | (match (find-packages-by-name "hello") | |
284 | (((? (cut eq? hello <>))) #t) | |
285 | (wrong (pk 'find-packages-by-name wrong #f)))) | |
286 | ||
287 | (test-assert "find-packages-by-name with version" | |
288 | (match (find-packages-by-name "hello" (package-version hello)) | |
289 | (((? (cut eq? hello <>))) #t) | |
290 | (wrong (pk 'find-packages-by-name wrong #f)))) | |
291 | ||
e3ce5d70 LC |
292 | (test-end "packages") |
293 | ||
294 | \f | |
295 | (exit (= (test-runner-fail-count (test-runner-current)) 0)) | |
296 | ||
297 | ;;; Local Variables: | |
a3d73f59 | 298 | ;;; eval: (put 'dummy-package 'scheme-indent-function 1) |
e3ce5d70 | 299 | ;;; End: |