Commit | Line | Data |
---|---|---|
233e7676 | 1 | ;;; GNU Guix --- Functional package management for GNU |
c1bc358f | 2 | ;;; Copyright © 2012, 2013, 2014 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 | 18 | |
e3ce5d70 | 19 | (define-module (test-packages) |
c1bc358f | 20 | #:use-module (guix tests) |
e3ce5d70 LC |
21 | #:use-module (guix store) |
22 | #:use-module (guix utils) | |
f9cc8971 | 23 | #:use-module (guix hash) |
e3ce5d70 LC |
24 | #:use-module (guix derivations) |
25 | #:use-module (guix packages) | |
a18eda27 | 26 | #:use-module (guix build-system) |
be13fbfa | 27 | #:use-module (guix build-system trivial) |
a3d73f59 | 28 | #:use-module (guix build-system gnu) |
59a43334 | 29 | #:use-module (gnu packages) |
1ffa7090 LC |
30 | #:use-module (gnu packages base) |
31 | #:use-module (gnu packages bootstrap) | |
e509d152 | 32 | #:use-module (srfi srfi-11) |
6b1891b0 | 33 | #:use-module (srfi srfi-26) |
9b222abe | 34 | #:use-module (srfi srfi-34) |
6b1891b0 | 35 | #:use-module (srfi srfi-64) |
860a6f1a | 36 | #:use-module (rnrs io ports) |
6b1891b0 | 37 | #:use-module (ice-9 match)) |
e3ce5d70 LC |
38 | |
39 | ;; Test the high-level packaging layer. | |
40 | ||
41 | (define %store | |
c1bc358f | 42 | (open-connection-for-tests)) |
e3ce5d70 | 43 | |
81dbd783 | 44 | |
14da91e2 | 45 | \f |
e3ce5d70 LC |
46 | (test-begin "packages") |
47 | ||
a3d73f59 LC |
48 | (define-syntax-rule (dummy-package name* extra-fields ...) |
49 | (package (name name*) (version "0") (source #f) | |
50 | (build-system gnu-build-system) | |
d45122f5 | 51 | (synopsis #f) (description #f) |
1fb78cb2 | 52 | (home-page #f) (license #f) |
a3d73f59 LC |
53 | extra-fields ...)) |
54 | ||
d66c7096 LC |
55 | (test-assert "package-field-location" |
56 | (let () | |
57 | (define (goto port line column) | |
58 | (unless (and (= (port-column port) (- column 1)) | |
59 | (= (port-line port) (- line 1))) | |
60 | (unless (eof-object? (get-char port)) | |
61 | (goto port line column)))) | |
62 | ||
63 | (define read-at | |
64 | (match-lambda | |
65 | (($ <location> file line column) | |
66 | (call-with-input-file (search-path %load-path file) | |
67 | (lambda (port) | |
68 | (goto port line column) | |
69 | (read port)))))) | |
70 | ||
ee48b283 LC |
71 | ;; Until Guile 2.0.6 included, source properties were added only to pairs. |
72 | ;; Thus, check against both VALUE and (FIELD VALUE). | |
73 | (and (member (read-at (package-field-location %bootstrap-guile 'name)) | |
74 | (let ((name (package-name %bootstrap-guile))) | |
75 | (list name `(name ,name)))) | |
76 | (member (read-at (package-field-location %bootstrap-guile 'version)) | |
77 | (let ((version (package-version %bootstrap-guile))) | |
78 | (list version `(version ,version)))) | |
f903dc05 | 79 | (not (package-field-location %bootstrap-guile 'does-not-exist))))) |
d66c7096 | 80 | |
0b8749b7 LC |
81 | ;; Make sure we don't change the file name to an absolute file name. |
82 | (test-equal "package-field-location, relative file name" | |
83 | (location-file (package-location %bootstrap-guile)) | |
84 | (with-fluids ((%file-port-name-canonicalization 'absolute)) | |
85 | (location-file (package-field-location %bootstrap-guile 'version)))) | |
86 | ||
a3d73f59 LC |
87 | (test-assert "package-transitive-inputs" |
88 | (let* ((a (dummy-package "a")) | |
89 | (b (dummy-package "b" | |
90 | (propagated-inputs `(("a" ,a))))) | |
91 | (c (dummy-package "c" | |
92 | (inputs `(("a" ,a))))) | |
93 | (d (dummy-package "d" | |
94 | (propagated-inputs `(("x" "something.drv"))))) | |
95 | (e (dummy-package "e" | |
96 | (inputs `(("b" ,b) ("c" ,c) ("d" ,d)))))) | |
97 | (and (null? (package-transitive-inputs a)) | |
98 | (equal? `(("a" ,a)) (package-transitive-inputs b)) | |
99 | (equal? `(("a" ,a)) (package-transitive-inputs c)) | |
100 | (equal? (package-propagated-inputs d) | |
101 | (package-transitive-inputs d)) | |
102 | (equal? `(("b" ,b) ("b/a" ,a) ("c" ,c) | |
103 | ("d" ,d) ("d/x" "something.drv")) | |
104 | (pk 'x (package-transitive-inputs e)))))) | |
105 | ||
7357138b LC |
106 | (test-skip (if (not %store) 8 0)) |
107 | ||
108 | (test-assert "package-source-derivation, file" | |
109 | (let* ((file (search-path %load-path "guix.scm")) | |
110 | (package (package (inherit (dummy-package "p")) | |
111 | (source file))) | |
112 | (source (package-source-derivation %store | |
113 | (package-source package)))) | |
114 | (and (store-path? source) | |
115 | (valid-path? %store source) | |
116 | (equal? (call-with-input-file source get-bytevector-all) | |
117 | (call-with-input-file file get-bytevector-all))))) | |
118 | ||
119 | (test-assert "package-source-derivation, store path" | |
120 | (let* ((file (add-to-store %store "guix.scm" #t "sha256" | |
121 | (search-path %load-path "guix.scm"))) | |
122 | (package (package (inherit (dummy-package "p")) | |
123 | (source file))) | |
124 | (source (package-source-derivation %store | |
125 | (package-source package)))) | |
126 | (string=? file source))) | |
e509d152 | 127 | |
f80594cc LC |
128 | (test-assert "package-source-derivation, indirect store path" |
129 | (let* ((dir (add-to-store %store "guix-build" #t "sha256" | |
130 | (dirname (search-path %load-path | |
131 | "guix/build/utils.scm")))) | |
132 | (package (package (inherit (dummy-package "p")) | |
133 | (source (string-append dir "/utils.scm")))) | |
134 | (source (package-source-derivation %store | |
135 | (package-source package)))) | |
136 | (and (direct-store-path? source) | |
137 | (string-suffix? "utils.scm" source)))) | |
138 | ||
b29f947d LC |
139 | (unless (false-if-exception (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)) |
140 | (test-skip 1)) | |
f9cc8971 LC |
141 | (test-equal "package-source-derivation, snippet" |
142 | "OK" | |
127ed6a9 | 143 | (let* ((file (search-bootstrap-binary "guile-2.0.9.tar.xz" |
f9cc8971 LC |
144 | (%current-system))) |
145 | (sha256 (call-with-input-file file port-sha256)) | |
146 | (fetch (lambda* (store url hash-algo hash | |
147 | #:optional name #:key system) | |
148 | (pk 'fetch url hash-algo hash name system) | |
149 | (add-to-store store (basename url) #f "sha256" url))) | |
150 | (source (bootstrap-origin | |
151 | (origin | |
152 | (method fetch) | |
153 | (uri file) | |
154 | (sha256 sha256) | |
155 | (patch-inputs | |
156 | `(("tar" ,%bootstrap-coreutils&co) | |
157 | ("xz" ,%bootstrap-coreutils&co) | |
158 | ("patch" ,%bootstrap-coreutils&co))) | |
7db9608d | 159 | (patch-guile %bootstrap-guile) |
f9cc8971 LC |
160 | (modules '((guix build utils))) |
161 | (imported-modules modules) | |
162 | (snippet '(begin | |
163 | ;; We end up in 'bin', because it's the first | |
164 | ;; directory, alphabetically. Not a very good | |
165 | ;; example but hey. | |
166 | (chmod "." #o777) | |
167 | (symlink "guile" "guile-rocks") | |
168 | (copy-recursively "../share/guile/2.0/scripts" | |
169 | "scripts") | |
170 | ||
171 | ;; These variables must exist. | |
172 | (pk %build-inputs %outputs)))))) | |
173 | (package (package (inherit (dummy-package "with-snippet")) | |
174 | (source source) | |
175 | (build-system trivial-build-system) | |
176 | (inputs | |
177 | `(("tar" ,(search-bootstrap-binary "tar" | |
178 | (%current-system))) | |
179 | ("xz" ,(search-bootstrap-binary "xz" | |
180 | (%current-system))))) | |
181 | (arguments | |
182 | `(#:guile ,%bootstrap-guile | |
183 | #:builder | |
184 | (let ((tar (assoc-ref %build-inputs "tar")) | |
185 | (xz (assoc-ref %build-inputs "xz")) | |
186 | (source (assoc-ref %build-inputs "source"))) | |
187 | (and (zero? (system* tar "xvf" source | |
188 | "--use-compress-program" xz)) | |
189 | (string=? "guile" (readlink "bin/guile-rocks")) | |
190 | (file-exists? "bin/scripts/compile.scm") | |
191 | (let ((out (assoc-ref %outputs "out"))) | |
192 | (call-with-output-file out | |
193 | (lambda (p) | |
194 | (display "OK" p)))))))))) | |
195 | (drv (package-derivation %store package)) | |
196 | (out (derivation->output-path drv))) | |
197 | (and (build-derivations %store (list (pk 'snippet-drv drv))) | |
198 | (call-with-input-file out get-string-all)))) | |
199 | ||
59688fc4 LC |
200 | (test-assert "return value" |
201 | (let ((drv (package-derivation %store (dummy-package "p")))) | |
202 | (and (derivation? drv) | |
203 | (file-exists? (derivation-file-name drv))))) | |
be13fbfa | 204 | |
d510ab46 LC |
205 | (test-assert "package-output" |
206 | (let* ((package (dummy-package "p")) | |
59688fc4 LC |
207 | (drv (package-derivation %store package))) |
208 | (and (derivation? drv) | |
209 | (string=? (derivation->output-path drv) | |
d510ab46 LC |
210 | (package-output %store package "out"))))) |
211 | ||
be13fbfa LC |
212 | (test-assert "trivial" |
213 | (let* ((p (package (inherit (dummy-package "trivial")) | |
214 | (build-system trivial-build-system) | |
215 | (source #f) | |
216 | (arguments | |
14da91e2 LC |
217 | `(#:guile ,%bootstrap-guile |
218 | #:builder | |
be13fbfa LC |
219 | (begin |
220 | (mkdir %output) | |
221 | (call-with-output-file (string-append %output "/test") | |
222 | (lambda (p) | |
223 | (display '(hello guix) p)))))))) | |
224 | (d (package-derivation %store p))) | |
225 | (and (build-derivations %store (list d)) | |
59688fc4 | 226 | (let ((p (pk 'drv d (derivation->output-path d)))) |
be13fbfa LC |
227 | (equal? '(hello guix) |
228 | (call-with-input-file (string-append p "/test") read)))))) | |
e3ce5d70 | 229 | |
860a6f1a LC |
230 | (test-assert "trivial with local file as input" |
231 | (let* ((i (search-path %load-path "ice-9/boot-9.scm")) | |
232 | (p (package (inherit (dummy-package "trivial-with-input-file")) | |
233 | (build-system trivial-build-system) | |
234 | (source #f) | |
235 | (arguments | |
236 | `(#:guile ,%bootstrap-guile | |
237 | #:builder (copy-file (assoc-ref %build-inputs "input") | |
238 | %output))) | |
239 | (inputs `(("input" ,i))))) | |
240 | (d (package-derivation %store p))) | |
241 | (and (build-derivations %store (list d)) | |
59688fc4 | 242 | (let ((p (pk 'drv d (derivation->output-path d)))) |
860a6f1a LC |
243 | (equal? (call-with-input-file p get-bytevector-all) |
244 | (call-with-input-file i get-bytevector-all)))))) | |
245 | ||
03761a44 LC |
246 | (test-assert "trivial with source" |
247 | (let* ((i (search-path %load-path "ice-9/boot-9.scm")) | |
248 | (p (package (inherit (dummy-package "trivial-with-source")) | |
249 | (build-system trivial-build-system) | |
250 | (source i) | |
251 | (arguments | |
252 | `(#:guile ,%bootstrap-guile | |
253 | #:builder (copy-file (assoc-ref %build-inputs "source") | |
254 | %output))))) | |
255 | (d (package-derivation %store p))) | |
256 | (and (build-derivations %store (list d)) | |
257 | (let ((p (derivation->output-path d))) | |
258 | (equal? (call-with-input-file p get-bytevector-all) | |
259 | (call-with-input-file i get-bytevector-all)))))) | |
260 | ||
592ef6c8 LC |
261 | (test-assert "trivial with system-dependent input" |
262 | (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input")) | |
263 | (build-system trivial-build-system) | |
264 | (source #f) | |
265 | (arguments | |
266 | `(#:guile ,%bootstrap-guile | |
267 | #:builder | |
268 | (let ((out (assoc-ref %outputs "out")) | |
269 | (bash (assoc-ref %build-inputs "bash"))) | |
270 | (zero? (system* bash "-c" | |
271 | (format #f "echo hello > ~a" out)))))) | |
dd6b9a37 LC |
272 | (inputs `(("bash" ,(search-bootstrap-binary "bash" |
273 | (%current-system))))))) | |
592ef6c8 LC |
274 | (d (package-derivation %store p))) |
275 | (and (build-derivations %store (list d)) | |
59688fc4 | 276 | (let ((p (pk 'drv d (derivation->output-path d)))) |
592ef6c8 LC |
277 | (eq? 'hello (call-with-input-file p read)))))) |
278 | ||
a18eda27 LC |
279 | (test-assert "search paths" |
280 | (let* ((p (make-prompt-tag "return-search-paths")) | |
281 | (s (build-system | |
0d5a559f | 282 | (name 'raw) |
a18eda27 | 283 | (description "Raw build system with direct store access") |
d3d337d2 LC |
284 | (lower (lambda* (name #:key source inputs system target |
285 | #:allow-other-keys) | |
0d5a559f LC |
286 | (bag |
287 | (name name) | |
d3d337d2 | 288 | (system system) (target target) |
0d5a559f LC |
289 | (build-inputs inputs) |
290 | (build | |
291 | (lambda* (store name inputs | |
292 | #:key outputs system search-paths) | |
293 | search-paths))))))) | |
a18eda27 LC |
294 | (x (list (search-path-specification |
295 | (variable "GUILE_LOAD_PATH") | |
296 | (directories '("share/guile/site/2.0"))) | |
297 | (search-path-specification | |
298 | (variable "GUILE_LOAD_COMPILED_PATH") | |
299 | (directories '("share/guile/site/2.0"))))) | |
300 | (a (package (inherit (dummy-package "guile")) | |
301 | (build-system s) | |
302 | (native-search-paths x))) | |
303 | (b (package (inherit (dummy-package "guile-foo")) | |
304 | (build-system s) | |
305 | (inputs `(("guile" ,a))))) | |
306 | (c (package (inherit (dummy-package "guile-bar")) | |
307 | (build-system s) | |
308 | (inputs `(("guile" ,a) | |
309 | ("guile-foo" ,b)))))) | |
310 | (let-syntax ((collect (syntax-rules () | |
311 | ((_ body ...) | |
312 | (call-with-prompt p | |
313 | (lambda () | |
314 | body ...) | |
315 | (lambda (k search-paths) | |
316 | search-paths)))))) | |
317 | (and (null? (collect (package-derivation %store a))) | |
318 | (equal? x (collect (package-derivation %store b))) | |
319 | (equal? x (collect (package-derivation %store c))))))) | |
320 | ||
9c1edabd | 321 | (test-assert "package-cross-derivation" |
59688fc4 LC |
322 | (let ((drv (package-cross-derivation %store (dummy-package "p") |
323 | "mips64el-linux-gnu"))) | |
324 | (and (derivation? drv) | |
325 | (file-exists? (derivation-file-name drv))))) | |
9c1edabd | 326 | |
5dce8218 LC |
327 | (test-assert "package-cross-derivation, trivial-build-system" |
328 | (let ((p (package (inherit (dummy-package "p")) | |
329 | (build-system trivial-build-system) | |
330 | (arguments '(#:builder (exit 1)))))) | |
59688fc4 LC |
331 | (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu"))) |
332 | (derivation? drv)))) | |
5dce8218 | 333 | |
9b222abe LC |
334 | (test-assert "package-cross-derivation, no cross builder" |
335 | (let* ((b (build-system (inherit trivial-build-system) | |
0d5a559f | 336 | (lower (const #f)))) |
9b222abe LC |
337 | (p (package (inherit (dummy-package "p")) |
338 | (build-system b)))) | |
339 | (guard (c ((package-cross-build-system-error? c) | |
340 | (eq? (package-error-package c) p))) | |
341 | (package-cross-derivation %store p "mips64el-linux-gnu") | |
342 | #f))) | |
343 | ||
d3d337d2 LC |
344 | (test-equal "package->bag" |
345 | `("foo86-hurd" #f (,(package-source gnu-make)) | |
346 | (,(canonical-package glibc)) (,(canonical-package coreutils))) | |
347 | (let ((bag (package->bag gnu-make "foo86-hurd"))) | |
348 | (list (bag-system bag) (bag-target bag) | |
349 | (assoc-ref (bag-build-inputs bag) "source") | |
350 | (assoc-ref (bag-build-inputs bag) "libc") | |
351 | (assoc-ref (bag-build-inputs bag) "coreutils")))) | |
352 | ||
353 | (test-equal "package->bag, cross-compilation" | |
354 | `(,(%current-system) "foo86-hurd" | |
355 | (,(package-source gnu-make)) | |
356 | (,(canonical-package glibc)) (,(canonical-package coreutils))) | |
357 | (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd"))) | |
358 | (list (bag-system bag) (bag-target bag) | |
359 | (assoc-ref (bag-build-inputs bag) "source") | |
360 | (assoc-ref (bag-build-inputs bag) "libc") | |
361 | (assoc-ref (bag-build-inputs bag) "coreutils")))) | |
362 | ||
363 | (test-assert "bag->derivation" | |
364 | (let ((bag (package->bag gnu-make)) | |
365 | (drv (package-derivation %store gnu-make))) | |
366 | (parameterize ((%current-system "foox86-hurd")) ;should have no effect | |
367 | (equal? drv (bag->derivation %store bag))))) | |
368 | ||
369 | (test-assert "bag->derivation, cross-compilation" | |
370 | (let ((bag (package->bag gnu-make (%current-system) "mips64el-linux-gnu")) | |
371 | (drv (package-cross-derivation %store gnu-make "mips64el-linux-gnu"))) | |
372 | (parameterize ((%current-system "foox86-hurd") ;should have no effect | |
373 | (%current-target-system "foo64-linux-gnu")) | |
374 | (equal? drv (bag->derivation %store bag))))) | |
375 | ||
ad1ebab3 LC |
376 | (unless (false-if-exception (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)) |
377 | (test-skip 1)) | |
9e782349 LC |
378 | (test-assert "GNU Make, bootstrap" |
379 | ;; GNU Make is the first program built during bootstrap; we choose it | |
380 | ;; here so that the test doesn't last for too long. | |
bdb36958 | 381 | (let ((gnu-make (@@ (gnu packages commencement) gnu-make-boot0))) |
9e782349 LC |
382 | (and (package? gnu-make) |
383 | (or (location? (package-location gnu-make)) | |
384 | (not (package-location gnu-make))) | |
385 | (let* ((drv (package-derivation %store gnu-make)) | |
59688fc4 | 386 | (out (derivation->output-path drv))) |
14da91e2 | 387 | (and (build-derivations %store (list drv)) |
9e782349 | 388 | (file-exists? (string-append out "/bin/make"))))))) |
e3ce5d70 | 389 | |
ba326ce4 LC |
390 | (test-eq "fold-packages" hello |
391 | (fold-packages (lambda (p r) | |
392 | (if (string=? (package-name p) "hello") | |
393 | p | |
394 | r)) | |
395 | #f)) | |
396 | ||
6b1891b0 LC |
397 | (test-assert "find-packages-by-name" |
398 | (match (find-packages-by-name "hello") | |
399 | (((? (cut eq? hello <>))) #t) | |
400 | (wrong (pk 'find-packages-by-name wrong #f)))) | |
401 | ||
402 | (test-assert "find-packages-by-name with version" | |
403 | (match (find-packages-by-name "hello" (package-version hello)) | |
404 | (((? (cut eq? hello <>))) #t) | |
405 | (wrong (pk 'find-packages-by-name wrong #f)))) | |
406 | ||
e3ce5d70 LC |
407 | (test-end "packages") |
408 | ||
409 | \f | |
410 | (exit (= (test-runner-fail-count (test-runner-current)) 0)) | |
411 | ||
412 | ;;; Local Variables: | |
a3d73f59 | 413 | ;;; eval: (put 'dummy-package 'scheme-indent-function 1) |
e3ce5d70 | 414 | ;;; End: |