install: Add bash-completion to the packages.
[jackhill/guix/guix.git] / tests / packages.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
f220a838 2;;; Copyright © 2012, 2013, 2014, 2015 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 21 #:use-module (guix store)
cf81a236 22 #:use-module (guix monads)
2e1bafb0
LC
23 #:use-module ((guix utils)
24 ;; Rename the 'location' binding to allow proper syntax
25 ;; matching when setting the 'location' field of a package.
26 #:renamer (lambda (name)
27 (cond ((eq? name 'location) 'make-location)
28 (else name))))
f9cc8971 29 #:use-module (guix hash)
e3ce5d70
LC
30 #:use-module (guix derivations)
31 #:use-module (guix packages)
a18eda27 32 #:use-module (guix build-system)
be13fbfa 33 #:use-module (guix build-system trivial)
a3d73f59 34 #:use-module (guix build-system gnu)
cf81a236
LC
35 #:use-module (guix profiles)
36 #:use-module (guix scripts package)
59a43334 37 #:use-module (gnu packages)
1ffa7090 38 #:use-module (gnu packages base)
05962f29 39 #:use-module (gnu packages guile)
1ffa7090 40 #:use-module (gnu packages bootstrap)
cf81a236 41 #:use-module (gnu packages xml)
05962f29 42 #:use-module (srfi srfi-1)
6b1891b0 43 #:use-module (srfi srfi-26)
9b222abe 44 #:use-module (srfi srfi-34)
dbab5150 45 #:use-module (srfi srfi-35)
6b1891b0 46 #:use-module (srfi srfi-64)
860a6f1a 47 #:use-module (rnrs io ports)
2e1bafb0 48 #:use-module (ice-9 regex)
6b1891b0 49 #:use-module (ice-9 match))
e3ce5d70
LC
50
51;; Test the high-level packaging layer.
52
53(define %store
c1bc358f 54 (open-connection-for-tests))
e3ce5d70 55
05962f29
LC
56\f
57(test-begin "packages")
58
2e1bafb0
LC
59(test-assert "printer with location"
60 (string-match "^#<package foo-0 foo.scm:42 [[:xdigit:]]+>$"
61 (with-output-to-string
62 (lambda ()
63 (write
64 (dummy-package "foo"
65 (location (make-location "foo.scm" 42 7))))))))
66
67(test-assert "printer without location"
68 (string-match "^#<package foo-0 [[:xdigit:]]+>$"
69 (with-output-to-string
70 (lambda ()
71 (write
72 (dummy-package "foo" (location #f)))))))
73
d66c7096
LC
74(test-assert "package-field-location"
75 (let ()
76 (define (goto port line column)
77 (unless (and (= (port-column port) (- column 1))
78 (= (port-line port) (- line 1)))
79 (unless (eof-object? (get-char port))
80 (goto port line column))))
81
82 (define read-at
83 (match-lambda
84 (($ <location> file line column)
85 (call-with-input-file (search-path %load-path file)
86 (lambda (port)
87 (goto port line column)
88 (read port))))))
89
ee48b283
LC
90 ;; Until Guile 2.0.6 included, source properties were added only to pairs.
91 ;; Thus, check against both VALUE and (FIELD VALUE).
92 (and (member (read-at (package-field-location %bootstrap-guile 'name))
93 (let ((name (package-name %bootstrap-guile)))
94 (list name `(name ,name))))
95 (member (read-at (package-field-location %bootstrap-guile 'version))
96 (let ((version (package-version %bootstrap-guile)))
97 (list version `(version ,version))))
f903dc05 98 (not (package-field-location %bootstrap-guile 'does-not-exist)))))
d66c7096 99
0b8749b7
LC
100;; Make sure we don't change the file name to an absolute file name.
101(test-equal "package-field-location, relative file name"
102 (location-file (package-location %bootstrap-guile))
103 (with-fluids ((%file-port-name-canonicalization 'absolute))
104 (location-file (package-field-location %bootstrap-guile 'version))))
105
a3d73f59
LC
106(test-assert "package-transitive-inputs"
107 (let* ((a (dummy-package "a"))
108 (b (dummy-package "b"
109 (propagated-inputs `(("a" ,a)))))
110 (c (dummy-package "c"
111 (inputs `(("a" ,a)))))
112 (d (dummy-package "d"
113 (propagated-inputs `(("x" "something.drv")))))
114 (e (dummy-package "e"
115 (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
116 (and (null? (package-transitive-inputs a))
117 (equal? `(("a" ,a)) (package-transitive-inputs b))
118 (equal? `(("a" ,a)) (package-transitive-inputs c))
119 (equal? (package-propagated-inputs d)
120 (package-transitive-inputs d))
121 (equal? `(("b" ,b) ("b/a" ,a) ("c" ,c)
122 ("d" ,d) ("d/x" "something.drv"))
123 (pk 'x (package-transitive-inputs e))))))
124
7c3c0374 125(test-equal "package-transitive-supported-systems"
c37a74bd
LC
126 '(("x" "y" "z") ;a
127 ("x" "y") ;b
128 ("y") ;c
129 ("y") ;d
130 ("y")) ;e
9bf3ced0
LC
131 ;; Use TRIVIAL-BUILD-SYSTEM because it doesn't add implicit inputs and thus
132 ;; doesn't restrict the set of supported systems.
133 (let* ((a (dummy-package "a"
134 (build-system trivial-build-system)
135 (supported-systems '("x" "y" "z"))))
136 (b (dummy-package "b"
137 (build-system trivial-build-system)
138 (supported-systems '("x" "y"))
139 (inputs `(("a" ,a)))))
140 (c (dummy-package "c"
141 (build-system trivial-build-system)
142 (supported-systems '("y" "z"))
143 (inputs `(("b" ,b)))))
144 (d (dummy-package "d"
145 (build-system trivial-build-system)
146 (supported-systems '("x" "y" "z"))
147 (inputs `(("b" ,b) ("c" ,c)))))
148 (e (dummy-package "e"
149 (build-system trivial-build-system)
150 (supported-systems '("x" "y" "z"))
151 (inputs `(("d" ,d))))))
7c3c0374
LC
152 (list (package-transitive-supported-systems a)
153 (package-transitive-supported-systems b)
c37a74bd
LC
154 (package-transitive-supported-systems c)
155 (package-transitive-supported-systems d)
156 (package-transitive-supported-systems e))))
7c3c0374 157
9bf3ced0
LC
158(test-equal "package-transitive-supported-systems, implicit inputs"
159 %supported-systems
160
161 ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on
162 ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored.
163 (let ((p (dummy-package "foo"
164 (build-system gnu-build-system)
165 (supported-systems
166 `("does-not-exist" "foobar" ,@%supported-systems)))))
167 (package-transitive-supported-systems p)))
168
bbceb0ef
LC
169(test-assert "supported-package?"
170 (let ((p (dummy-package "foo"
171 (build-system gnu-build-system)
172 (supported-systems '("x86_64-linux" "does-not-exist")))))
173 (and (supported-package? p "x86_64-linux")
174 (not (supported-package? p "does-not-exist"))
175 (not (supported-package? p "i686-linux")))))
176
7357138b
LC
177(test-skip (if (not %store) 8 0))
178
179(test-assert "package-source-derivation, file"
180 (let* ((file (search-path %load-path "guix.scm"))
181 (package (package (inherit (dummy-package "p"))
182 (source file)))
183 (source (package-source-derivation %store
184 (package-source package))))
185 (and (store-path? source)
186 (valid-path? %store source)
187 (equal? (call-with-input-file source get-bytevector-all)
188 (call-with-input-file file get-bytevector-all)))))
189
190(test-assert "package-source-derivation, store path"
191 (let* ((file (add-to-store %store "guix.scm" #t "sha256"
192 (search-path %load-path "guix.scm")))
193 (package (package (inherit (dummy-package "p"))
194 (source file)))
195 (source (package-source-derivation %store
196 (package-source package))))
197 (string=? file source)))
e509d152 198
f80594cc
LC
199(test-assert "package-source-derivation, indirect store path"
200 (let* ((dir (add-to-store %store "guix-build" #t "sha256"
201 (dirname (search-path %load-path
202 "guix/build/utils.scm"))))
203 (package (package (inherit (dummy-package "p"))
204 (source (string-append dir "/utils.scm"))))
205 (source (package-source-derivation %store
206 (package-source package))))
207 (and (direct-store-path? source)
208 (string-suffix? "utils.scm" source))))
209
12d720fd 210(unless (network-reachable?) (test-skip 1))
f9cc8971
LC
211(test-equal "package-source-derivation, snippet"
212 "OK"
5cfc17cb
MW
213 (let* ((file (search-bootstrap-binary (match (%current-system)
214 ("armhf-linux"
215 "guile-2.0.11.tar.xz")
216 (_
217 "guile-2.0.9.tar.xz"))
f9cc8971
LC
218 (%current-system)))
219 (sha256 (call-with-input-file file port-sha256))
f220a838 220 (fetch (lambda* (url hash-algo hash
f9cc8971
LC
221 #:optional name #:key system)
222 (pk 'fetch url hash-algo hash name system)
f220a838 223 (interned-file url)))
f9cc8971
LC
224 (source (bootstrap-origin
225 (origin
226 (method fetch)
227 (uri file)
228 (sha256 sha256)
229 (patch-inputs
230 `(("tar" ,%bootstrap-coreutils&co)
231 ("xz" ,%bootstrap-coreutils&co)
232 ("patch" ,%bootstrap-coreutils&co)))
7db9608d 233 (patch-guile %bootstrap-guile)
f9cc8971
LC
234 (modules '((guix build utils)))
235 (imported-modules modules)
236 (snippet '(begin
237 ;; We end up in 'bin', because it's the first
238 ;; directory, alphabetically. Not a very good
239 ;; example but hey.
240 (chmod "." #o777)
241 (symlink "guile" "guile-rocks")
242 (copy-recursively "../share/guile/2.0/scripts"
cf87cc89 243 "scripts"))))))
f9cc8971
LC
244 (package (package (inherit (dummy-package "with-snippet"))
245 (source source)
246 (build-system trivial-build-system)
247 (inputs
248 `(("tar" ,(search-bootstrap-binary "tar"
249 (%current-system)))
250 ("xz" ,(search-bootstrap-binary "xz"
251 (%current-system)))))
252 (arguments
253 `(#:guile ,%bootstrap-guile
254 #:builder
255 (let ((tar (assoc-ref %build-inputs "tar"))
256 (xz (assoc-ref %build-inputs "xz"))
257 (source (assoc-ref %build-inputs "source")))
258 (and (zero? (system* tar "xvf" source
259 "--use-compress-program" xz))
260 (string=? "guile" (readlink "bin/guile-rocks"))
261 (file-exists? "bin/scripts/compile.scm")
262 (let ((out (assoc-ref %outputs "out")))
263 (call-with-output-file out
264 (lambda (p)
265 (display "OK" p))))))))))
266 (drv (package-derivation %store package))
267 (out (derivation->output-path drv)))
268 (and (build-derivations %store (list (pk 'snippet-drv drv)))
269 (call-with-input-file out get-string-all))))
270
59688fc4
LC
271(test-assert "return value"
272 (let ((drv (package-derivation %store (dummy-package "p"))))
273 (and (derivation? drv)
274 (file-exists? (derivation-file-name drv)))))
be13fbfa 275
d510ab46
LC
276(test-assert "package-output"
277 (let* ((package (dummy-package "p"))
59688fc4
LC
278 (drv (package-derivation %store package)))
279 (and (derivation? drv)
280 (string=? (derivation->output-path drv)
d510ab46
LC
281 (package-output %store package "out")))))
282
dbab5150
LC
283(test-assert "patch not found yields a run-time error"
284 (guard (c ((condition-has-type? c &message)
285 (and (string-contains (condition-message c)
286 "does-not-exist.patch")
287 (string-contains (condition-message c)
288 "not found"))))
289 (let ((p (package
290 (inherit (dummy-package "p"))
291 (source (origin
292 (method (const #f))
293 (uri "http://whatever")
294 (patches
295 (list (search-patch "does-not-exist.patch")))
296 (sha256
297 (base32
298 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks4")))))))
299 (package-derivation %store p)
300 #f)))
301
f304c9c2
LC
302(test-assert "reference to non-existent output"
303 ;; See <http://bugs.gnu.org/19630>.
862abf8f
LC
304 (parameterize ((%graft? #f))
305 (let* ((dep (dummy-package "dep"))
306 (p (dummy-package "p"
307 (inputs `(("dep" ,dep "non-existent"))))))
308 (guard (c ((derivation-missing-output-error? c)
309 (and (string=? (derivation-missing-output c) "non-existent")
310 (equal? (package-derivation %store dep)
311 (derivation-error-derivation c)))))
312 (package-derivation %store p)))))
f304c9c2 313
be13fbfa
LC
314(test-assert "trivial"
315 (let* ((p (package (inherit (dummy-package "trivial"))
316 (build-system trivial-build-system)
317 (source #f)
318 (arguments
14da91e2
LC
319 `(#:guile ,%bootstrap-guile
320 #:builder
be13fbfa
LC
321 (begin
322 (mkdir %output)
323 (call-with-output-file (string-append %output "/test")
324 (lambda (p)
325 (display '(hello guix) p))))))))
326 (d (package-derivation %store p)))
327 (and (build-derivations %store (list d))
59688fc4 328 (let ((p (pk 'drv d (derivation->output-path d))))
be13fbfa
LC
329 (equal? '(hello guix)
330 (call-with-input-file (string-append p "/test") read))))))
e3ce5d70 331
860a6f1a
LC
332(test-assert "trivial with local file as input"
333 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
334 (p (package (inherit (dummy-package "trivial-with-input-file"))
335 (build-system trivial-build-system)
336 (source #f)
337 (arguments
338 `(#:guile ,%bootstrap-guile
339 #:builder (copy-file (assoc-ref %build-inputs "input")
340 %output)))
341 (inputs `(("input" ,i)))))
342 (d (package-derivation %store p)))
343 (and (build-derivations %store (list d))
59688fc4 344 (let ((p (pk 'drv d (derivation->output-path d))))
860a6f1a
LC
345 (equal? (call-with-input-file p get-bytevector-all)
346 (call-with-input-file i get-bytevector-all))))))
347
03761a44
LC
348(test-assert "trivial with source"
349 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
350 (p (package (inherit (dummy-package "trivial-with-source"))
351 (build-system trivial-build-system)
352 (source i)
353 (arguments
354 `(#:guile ,%bootstrap-guile
355 #:builder (copy-file (assoc-ref %build-inputs "source")
356 %output)))))
357 (d (package-derivation %store p)))
358 (and (build-derivations %store (list d))
359 (let ((p (derivation->output-path d)))
360 (equal? (call-with-input-file p get-bytevector-all)
361 (call-with-input-file i get-bytevector-all))))))
362
592ef6c8
LC
363(test-assert "trivial with system-dependent input"
364 (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
365 (build-system trivial-build-system)
366 (source #f)
367 (arguments
368 `(#:guile ,%bootstrap-guile
369 #:builder
370 (let ((out (assoc-ref %outputs "out"))
371 (bash (assoc-ref %build-inputs "bash")))
372 (zero? (system* bash "-c"
373 (format #f "echo hello > ~a" out))))))
dd6b9a37
LC
374 (inputs `(("bash" ,(search-bootstrap-binary "bash"
375 (%current-system)))))))
592ef6c8
LC
376 (d (package-derivation %store p)))
377 (and (build-derivations %store (list d))
59688fc4 378 (let ((p (pk 'drv d (derivation->output-path d))))
592ef6c8
LC
379 (eq? 'hello (call-with-input-file p read))))))
380
a18eda27
LC
381(test-assert "search paths"
382 (let* ((p (make-prompt-tag "return-search-paths"))
383 (s (build-system
0d5a559f 384 (name 'raw)
a18eda27 385 (description "Raw build system with direct store access")
d3d337d2
LC
386 (lower (lambda* (name #:key source inputs system target
387 #:allow-other-keys)
0d5a559f
LC
388 (bag
389 (name name)
d3d337d2 390 (system system) (target target)
0d5a559f
LC
391 (build-inputs inputs)
392 (build
393 (lambda* (store name inputs
394 #:key outputs system search-paths)
395 search-paths)))))))
a18eda27
LC
396 (x (list (search-path-specification
397 (variable "GUILE_LOAD_PATH")
af070955 398 (files '("share/guile/site/2.0")))
a18eda27
LC
399 (search-path-specification
400 (variable "GUILE_LOAD_COMPILED_PATH")
af070955 401 (files '("share/guile/site/2.0")))))
a18eda27
LC
402 (a (package (inherit (dummy-package "guile"))
403 (build-system s)
404 (native-search-paths x)))
405 (b (package (inherit (dummy-package "guile-foo"))
406 (build-system s)
407 (inputs `(("guile" ,a)))))
408 (c (package (inherit (dummy-package "guile-bar"))
409 (build-system s)
410 (inputs `(("guile" ,a)
411 ("guile-foo" ,b))))))
412 (let-syntax ((collect (syntax-rules ()
413 ((_ body ...)
414 (call-with-prompt p
415 (lambda ()
416 body ...)
417 (lambda (k search-paths)
418 search-paths))))))
419 (and (null? (collect (package-derivation %store a)))
420 (equal? x (collect (package-derivation %store b)))
421 (equal? x (collect (package-derivation %store c)))))))
422
9c1edabd 423(test-assert "package-cross-derivation"
59688fc4
LC
424 (let ((drv (package-cross-derivation %store (dummy-package "p")
425 "mips64el-linux-gnu")))
426 (and (derivation? drv)
427 (file-exists? (derivation-file-name drv)))))
9c1edabd 428
5dce8218
LC
429(test-assert "package-cross-derivation, trivial-build-system"
430 (let ((p (package (inherit (dummy-package "p"))
431 (build-system trivial-build-system)
432 (arguments '(#:builder (exit 1))))))
59688fc4
LC
433 (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu")))
434 (derivation? drv))))
5dce8218 435
9b222abe
LC
436(test-assert "package-cross-derivation, no cross builder"
437 (let* ((b (build-system (inherit trivial-build-system)
0d5a559f 438 (lower (const #f))))
9b222abe
LC
439 (p (package (inherit (dummy-package "p"))
440 (build-system b))))
441 (guard (c ((package-cross-build-system-error? c)
442 (eq? (package-error-package c) p)))
443 (package-cross-derivation %store p "mips64el-linux-gnu")
444 #f)))
445
05962f29
LC
446(test-equal "package-derivation, direct graft"
447 (package-derivation %store gnu-make)
448 (let ((p (package (inherit coreutils)
449 (replacement gnu-make))))
450 (package-derivation %store p)))
451
452(test-equal "package-cross-derivation, direct graft"
453 (package-cross-derivation %store gnu-make "mips64el-linux-gnu")
454 (let ((p (package (inherit coreutils)
455 (replacement gnu-make))))
456 (package-cross-derivation %store p "mips64el-linux-gnu")))
457
458(test-assert "package-grafts, indirect grafts"
459 (let* ((new (dummy-package "dep"
460 (arguments '(#:implicit-inputs? #f))))
461 (dep (package (inherit new) (version "0.0")))
462 (dep* (package (inherit dep) (replacement new)))
463 (dummy (dummy-package "dummy"
464 (arguments '(#:implicit-inputs? #f))
465 (inputs `(("dep" ,dep*))))))
466 (equal? (package-grafts %store dummy)
467 (list (graft
468 (origin (package-derivation %store dep))
469 (replacement (package-derivation %store new)))))))
470
471(test-assert "package-grafts, indirect grafts, cross"
472 (let* ((new (dummy-package "dep"
473 (arguments '(#:implicit-inputs? #f))))
474 (dep (package (inherit new) (version "0.0")))
475 (dep* (package (inherit dep) (replacement new)))
476 (dummy (dummy-package "dummy"
477 (arguments '(#:implicit-inputs? #f))
478 (inputs `(("dep" ,dep*)))))
479 (target "mips64el-linux-gnu"))
480 (equal? (package-grafts %store dummy #:target target)
481 (list (graft
482 (origin (package-cross-derivation %store dep target))
483 (replacement
484 (package-cross-derivation %store new target)))))))
485
486(test-assert "package-grafts, indirect grafts, propagated inputs"
487 (let* ((new (dummy-package "dep"
488 (arguments '(#:implicit-inputs? #f))))
489 (dep (package (inherit new) (version "0.0")))
490 (dep* (package (inherit dep) (replacement new)))
491 (prop (dummy-package "propagated"
492 (propagated-inputs `(("dep" ,dep*)))
493 (arguments '(#:implicit-inputs? #f))))
494 (dummy (dummy-package "dummy"
495 (arguments '(#:implicit-inputs? #f))
496 (inputs `(("prop" ,prop))))))
497 (equal? (package-grafts %store dummy)
498 (list (graft
499 (origin (package-derivation %store dep))
500 (replacement (package-derivation %store new)))))))
501
502(test-assert "package-derivation, indirect grafts"
503 (let* ((new (dummy-package "dep"
504 (arguments '(#:implicit-inputs? #f))))
505 (dep (package (inherit new) (version "0.0")))
506 (dep* (package (inherit dep) (replacement new)))
507 (dummy (dummy-package "dummy"
508 (arguments '(#:implicit-inputs? #f))
509 (inputs `(("dep" ,dep*)))))
510 (guile (package-derivation %store (canonical-package guile-2.0)
511 #:graft? #f)))
512 (equal? (package-derivation %store dummy)
513 (graft-derivation %store "dummy-0"
514 (package-derivation %store dummy #:graft? #f)
515 (package-grafts %store dummy)
516
517 ;; Use the same Guile as 'package-derivation'.
518 #:guile guile))))
519
d3d337d2
LC
520(test-equal "package->bag"
521 `("foo86-hurd" #f (,(package-source gnu-make))
522 (,(canonical-package glibc)) (,(canonical-package coreutils)))
523 (let ((bag (package->bag gnu-make "foo86-hurd")))
524 (list (bag-system bag) (bag-target bag)
525 (assoc-ref (bag-build-inputs bag) "source")
526 (assoc-ref (bag-build-inputs bag) "libc")
527 (assoc-ref (bag-build-inputs bag) "coreutils"))))
528
529(test-equal "package->bag, cross-compilation"
530 `(,(%current-system) "foo86-hurd"
531 (,(package-source gnu-make))
532 (,(canonical-package glibc)) (,(canonical-package coreutils)))
533 (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd")))
534 (list (bag-system bag) (bag-target bag)
535 (assoc-ref (bag-build-inputs bag) "source")
536 (assoc-ref (bag-build-inputs bag) "libc")
537 (assoc-ref (bag-build-inputs bag) "coreutils"))))
538
50373bab
LC
539(test-assert "package->bag, propagated inputs"
540 (let* ((dep (dummy-package "dep"))
541 (prop (dummy-package "prop"
542 (propagated-inputs `(("dep" ,dep)))))
543 (dummy (dummy-package "dummy"
544 (inputs `(("prop" ,prop)))))
545 (inputs (bag-transitive-inputs (package->bag dummy #:graft? #f))))
546 (match (assoc "prop/dep" inputs)
547 (("prop/dep" package)
548 (eq? package dep)))))
549
d3d337d2 550(test-assert "bag->derivation"
05962f29
LC
551 (parameterize ((%graft? #f))
552 (let ((bag (package->bag gnu-make))
553 (drv (package-derivation %store gnu-make)))
554 (parameterize ((%current-system "foox86-hurd")) ;should have no effect
555 (equal? drv (bag->derivation %store bag))))))
d3d337d2
LC
556
557(test-assert "bag->derivation, cross-compilation"
05962f29
LC
558 (parameterize ((%graft? #f))
559 (let* ((target "mips64el-linux-gnu")
560 (bag (package->bag gnu-make (%current-system) target))
561 (drv (package-cross-derivation %store gnu-make target)))
562 (parameterize ((%current-system "foox86-hurd") ;should have no effect
563 (%current-target-system "foo64-linux-gnu"))
564 (equal? drv (bag->derivation %store bag))))))
d3d337d2 565
b69c5c2c
LC
566(when (or (not (network-reachable?)) (shebang-too-long?))
567 (test-skip 1))
9e782349
LC
568(test-assert "GNU Make, bootstrap"
569 ;; GNU Make is the first program built during bootstrap; we choose it
570 ;; here so that the test doesn't last for too long.
bdb36958 571 (let ((gnu-make (@@ (gnu packages commencement) gnu-make-boot0)))
9e782349
LC
572 (and (package? gnu-make)
573 (or (location? (package-location gnu-make))
574 (not (package-location gnu-make)))
575 (let* ((drv (package-derivation %store gnu-make))
59688fc4 576 (out (derivation->output-path drv)))
14da91e2 577 (and (build-derivations %store (list drv))
9e782349 578 (file-exists? (string-append out "/bin/make")))))))
e3ce5d70 579
ba326ce4
LC
580(test-eq "fold-packages" hello
581 (fold-packages (lambda (p r)
582 (if (string=? (package-name p) "hello")
583 p
584 r))
585 #f))
586
6b1891b0
LC
587(test-assert "find-packages-by-name"
588 (match (find-packages-by-name "hello")
589 (((? (cut eq? hello <>))) #t)
590 (wrong (pk 'find-packages-by-name wrong #f))))
591
592(test-assert "find-packages-by-name with version"
593 (match (find-packages-by-name "hello" (package-version hello))
594 (((? (cut eq? hello <>))) #t)
595 (wrong (pk 'find-packages-by-name wrong #f))))
596
cf81a236
LC
597(test-assert "--search-paths with pattern"
598 ;; Make sure 'guix package --search-paths' correctly reports environment
599 ;; variables when file patterns are used (in particular, it must follow
600 ;; symlinks when looking for 'catalog.xml'.) To do that, we rely on the
601 ;; libxml2 package specification, which contains such a definition.
602 (let* ((p1 (package
603 (name "foo") (version "0") (source #f)
604 (build-system trivial-build-system)
605 (arguments
606 `(#:guile ,%bootstrap-guile
607 #:modules ((guix build utils))
608 #:builder (begin
609 (use-modules (guix build utils))
610 (let ((out (assoc-ref %outputs "out")))
611 (mkdir-p (string-append out "/xml/bar/baz"))
612 (call-with-output-file
613 (string-append out "/xml/bar/baz/catalog.xml")
614 (lambda (port)
615 (display "xml? wat?!" port)))))))
616 (synopsis #f) (description #f)
617 (home-page #f) (license #f)))
618 (p2 (package
619 ;; Provide a fake libxml2 to avoid building the real one. This
620 ;; is OK because 'guix package' gets search path specifications
621 ;; from the same-named package found in the distro.
622 (name "libxml2") (version "0.0.0") (source #f)
623 (build-system trivial-build-system)
624 (arguments
625 `(#:guile ,%bootstrap-guile
626 #:builder (mkdir (assoc-ref %outputs "out"))))
627 (native-search-paths (package-native-search-paths libxml2))
628 (synopsis #f) (description #f)
629 (home-page #f) (license #f)))
630 (prof (run-with-store %store
631 (profile-derivation
632 (manifest (map package->manifest-entry
633 (list p1 p2)))
aa46a028 634 #:hooks '())
cf81a236
LC
635 #:guile-for-build (%guile-for-build))))
636 (build-derivations %store (list prof))
637 (string-match (format #f "^export XML_CATALOG_FILES=\"~a/xml/+bar/baz/catalog\\.xml\"\n"
638 (derivation->output-path prof))
639 (with-output-to-string
640 (lambda ()
641 (guix-package "-p" (derivation->output-path prof)
642 "--search-paths"))))))
643
e3ce5d70
LC
644(test-end "packages")
645
646\f
647(exit (= (test-runner-fail-count (test-runner-current)) 0))
648
649;;; Local Variables:
a3d73f59 650;;; eval: (put 'dummy-package 'scheme-indent-function 1)
e3ce5d70 651;;; End: