Add Ricardo to 'AUTHORS'.
[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
7c3c0374
LC
131 (let* ((a (dummy-package "a" (supported-systems '("x" "y" "z"))))
132 (b (dummy-package "b" (supported-systems '("x" "y"))
133 (inputs `(("a" ,a)))))
134 (c (dummy-package "c" (supported-systems '("y" "z"))
c37a74bd
LC
135 (inputs `(("b" ,b)))))
136 (d (dummy-package "d" (supported-systems '("x" "y" "z"))
137 (inputs `(("b" ,b) ("c" ,c)))))
138 (e (dummy-package "e" (supported-systems '("x" "y" "z"))
139 (inputs `(("d" ,d))))))
7c3c0374
LC
140 (list (package-transitive-supported-systems a)
141 (package-transitive-supported-systems b)
c37a74bd
LC
142 (package-transitive-supported-systems c)
143 (package-transitive-supported-systems d)
144 (package-transitive-supported-systems e))))
7c3c0374 145
7357138b
LC
146(test-skip (if (not %store) 8 0))
147
148(test-assert "package-source-derivation, file"
149 (let* ((file (search-path %load-path "guix.scm"))
150 (package (package (inherit (dummy-package "p"))
151 (source file)))
152 (source (package-source-derivation %store
153 (package-source package))))
154 (and (store-path? source)
155 (valid-path? %store source)
156 (equal? (call-with-input-file source get-bytevector-all)
157 (call-with-input-file file get-bytevector-all)))))
158
159(test-assert "package-source-derivation, store path"
160 (let* ((file (add-to-store %store "guix.scm" #t "sha256"
161 (search-path %load-path "guix.scm")))
162 (package (package (inherit (dummy-package "p"))
163 (source file)))
164 (source (package-source-derivation %store
165 (package-source package))))
166 (string=? file source)))
e509d152 167
f80594cc
LC
168(test-assert "package-source-derivation, indirect store path"
169 (let* ((dir (add-to-store %store "guix-build" #t "sha256"
170 (dirname (search-path %load-path
171 "guix/build/utils.scm"))))
172 (package (package (inherit (dummy-package "p"))
173 (source (string-append dir "/utils.scm"))))
174 (source (package-source-derivation %store
175 (package-source package))))
176 (and (direct-store-path? source)
177 (string-suffix? "utils.scm" source))))
178
b29f947d
LC
179(unless (false-if-exception (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV))
180 (test-skip 1))
f9cc8971
LC
181(test-equal "package-source-derivation, snippet"
182 "OK"
127ed6a9 183 (let* ((file (search-bootstrap-binary "guile-2.0.9.tar.xz"
f9cc8971
LC
184 (%current-system)))
185 (sha256 (call-with-input-file file port-sha256))
f220a838 186 (fetch (lambda* (url hash-algo hash
f9cc8971
LC
187 #:optional name #:key system)
188 (pk 'fetch url hash-algo hash name system)
f220a838 189 (interned-file url)))
f9cc8971
LC
190 (source (bootstrap-origin
191 (origin
192 (method fetch)
193 (uri file)
194 (sha256 sha256)
195 (patch-inputs
196 `(("tar" ,%bootstrap-coreutils&co)
197 ("xz" ,%bootstrap-coreutils&co)
198 ("patch" ,%bootstrap-coreutils&co)))
7db9608d 199 (patch-guile %bootstrap-guile)
f9cc8971
LC
200 (modules '((guix build utils)))
201 (imported-modules modules)
202 (snippet '(begin
203 ;; We end up in 'bin', because it's the first
204 ;; directory, alphabetically. Not a very good
205 ;; example but hey.
206 (chmod "." #o777)
207 (symlink "guile" "guile-rocks")
208 (copy-recursively "../share/guile/2.0/scripts"
209 "scripts")
210
211 ;; These variables must exist.
212 (pk %build-inputs %outputs))))))
213 (package (package (inherit (dummy-package "with-snippet"))
214 (source source)
215 (build-system trivial-build-system)
216 (inputs
217 `(("tar" ,(search-bootstrap-binary "tar"
218 (%current-system)))
219 ("xz" ,(search-bootstrap-binary "xz"
220 (%current-system)))))
221 (arguments
222 `(#:guile ,%bootstrap-guile
223 #:builder
224 (let ((tar (assoc-ref %build-inputs "tar"))
225 (xz (assoc-ref %build-inputs "xz"))
226 (source (assoc-ref %build-inputs "source")))
227 (and (zero? (system* tar "xvf" source
228 "--use-compress-program" xz))
229 (string=? "guile" (readlink "bin/guile-rocks"))
230 (file-exists? "bin/scripts/compile.scm")
231 (let ((out (assoc-ref %outputs "out")))
232 (call-with-output-file out
233 (lambda (p)
234 (display "OK" p))))))))))
235 (drv (package-derivation %store package))
236 (out (derivation->output-path drv)))
237 (and (build-derivations %store (list (pk 'snippet-drv drv)))
238 (call-with-input-file out get-string-all))))
239
59688fc4
LC
240(test-assert "return value"
241 (let ((drv (package-derivation %store (dummy-package "p"))))
242 (and (derivation? drv)
243 (file-exists? (derivation-file-name drv)))))
be13fbfa 244
d510ab46
LC
245(test-assert "package-output"
246 (let* ((package (dummy-package "p"))
59688fc4
LC
247 (drv (package-derivation %store package)))
248 (and (derivation? drv)
249 (string=? (derivation->output-path drv)
d510ab46
LC
250 (package-output %store package "out")))))
251
dbab5150
LC
252(test-assert "patch not found yields a run-time error"
253 (guard (c ((condition-has-type? c &message)
254 (and (string-contains (condition-message c)
255 "does-not-exist.patch")
256 (string-contains (condition-message c)
257 "not found"))))
258 (let ((p (package
259 (inherit (dummy-package "p"))
260 (source (origin
261 (method (const #f))
262 (uri "http://whatever")
263 (patches
264 (list (search-patch "does-not-exist.patch")))
265 (sha256
266 (base32
267 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks4")))))))
268 (package-derivation %store p)
269 #f)))
270
be13fbfa
LC
271(test-assert "trivial"
272 (let* ((p (package (inherit (dummy-package "trivial"))
273 (build-system trivial-build-system)
274 (source #f)
275 (arguments
14da91e2
LC
276 `(#:guile ,%bootstrap-guile
277 #:builder
be13fbfa
LC
278 (begin
279 (mkdir %output)
280 (call-with-output-file (string-append %output "/test")
281 (lambda (p)
282 (display '(hello guix) p))))))))
283 (d (package-derivation %store p)))
284 (and (build-derivations %store (list d))
59688fc4 285 (let ((p (pk 'drv d (derivation->output-path d))))
be13fbfa
LC
286 (equal? '(hello guix)
287 (call-with-input-file (string-append p "/test") read))))))
e3ce5d70 288
860a6f1a
LC
289(test-assert "trivial with local file as input"
290 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
291 (p (package (inherit (dummy-package "trivial-with-input-file"))
292 (build-system trivial-build-system)
293 (source #f)
294 (arguments
295 `(#:guile ,%bootstrap-guile
296 #:builder (copy-file (assoc-ref %build-inputs "input")
297 %output)))
298 (inputs `(("input" ,i)))))
299 (d (package-derivation %store p)))
300 (and (build-derivations %store (list d))
59688fc4 301 (let ((p (pk 'drv d (derivation->output-path d))))
860a6f1a
LC
302 (equal? (call-with-input-file p get-bytevector-all)
303 (call-with-input-file i get-bytevector-all))))))
304
03761a44
LC
305(test-assert "trivial with source"
306 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
307 (p (package (inherit (dummy-package "trivial-with-source"))
308 (build-system trivial-build-system)
309 (source i)
310 (arguments
311 `(#:guile ,%bootstrap-guile
312 #:builder (copy-file (assoc-ref %build-inputs "source")
313 %output)))))
314 (d (package-derivation %store p)))
315 (and (build-derivations %store (list d))
316 (let ((p (derivation->output-path d)))
317 (equal? (call-with-input-file p get-bytevector-all)
318 (call-with-input-file i get-bytevector-all))))))
319
592ef6c8
LC
320(test-assert "trivial with system-dependent input"
321 (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
322 (build-system trivial-build-system)
323 (source #f)
324 (arguments
325 `(#:guile ,%bootstrap-guile
326 #:builder
327 (let ((out (assoc-ref %outputs "out"))
328 (bash (assoc-ref %build-inputs "bash")))
329 (zero? (system* bash "-c"
330 (format #f "echo hello > ~a" out))))))
dd6b9a37
LC
331 (inputs `(("bash" ,(search-bootstrap-binary "bash"
332 (%current-system)))))))
592ef6c8
LC
333 (d (package-derivation %store p)))
334 (and (build-derivations %store (list d))
59688fc4 335 (let ((p (pk 'drv d (derivation->output-path d))))
592ef6c8
LC
336 (eq? 'hello (call-with-input-file p read))))))
337
a18eda27
LC
338(test-assert "search paths"
339 (let* ((p (make-prompt-tag "return-search-paths"))
340 (s (build-system
0d5a559f 341 (name 'raw)
a18eda27 342 (description "Raw build system with direct store access")
d3d337d2
LC
343 (lower (lambda* (name #:key source inputs system target
344 #:allow-other-keys)
0d5a559f
LC
345 (bag
346 (name name)
d3d337d2 347 (system system) (target target)
0d5a559f
LC
348 (build-inputs inputs)
349 (build
350 (lambda* (store name inputs
351 #:key outputs system search-paths)
352 search-paths)))))))
a18eda27
LC
353 (x (list (search-path-specification
354 (variable "GUILE_LOAD_PATH")
af070955 355 (files '("share/guile/site/2.0")))
a18eda27
LC
356 (search-path-specification
357 (variable "GUILE_LOAD_COMPILED_PATH")
af070955 358 (files '("share/guile/site/2.0")))))
a18eda27
LC
359 (a (package (inherit (dummy-package "guile"))
360 (build-system s)
361 (native-search-paths x)))
362 (b (package (inherit (dummy-package "guile-foo"))
363 (build-system s)
364 (inputs `(("guile" ,a)))))
365 (c (package (inherit (dummy-package "guile-bar"))
366 (build-system s)
367 (inputs `(("guile" ,a)
368 ("guile-foo" ,b))))))
369 (let-syntax ((collect (syntax-rules ()
370 ((_ body ...)
371 (call-with-prompt p
372 (lambda ()
373 body ...)
374 (lambda (k search-paths)
375 search-paths))))))
376 (and (null? (collect (package-derivation %store a)))
377 (equal? x (collect (package-derivation %store b)))
378 (equal? x (collect (package-derivation %store c)))))))
379
9c1edabd 380(test-assert "package-cross-derivation"
59688fc4
LC
381 (let ((drv (package-cross-derivation %store (dummy-package "p")
382 "mips64el-linux-gnu")))
383 (and (derivation? drv)
384 (file-exists? (derivation-file-name drv)))))
9c1edabd 385
5dce8218
LC
386(test-assert "package-cross-derivation, trivial-build-system"
387 (let ((p (package (inherit (dummy-package "p"))
388 (build-system trivial-build-system)
389 (arguments '(#:builder (exit 1))))))
59688fc4
LC
390 (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu")))
391 (derivation? drv))))
5dce8218 392
9b222abe
LC
393(test-assert "package-cross-derivation, no cross builder"
394 (let* ((b (build-system (inherit trivial-build-system)
0d5a559f 395 (lower (const #f))))
9b222abe
LC
396 (p (package (inherit (dummy-package "p"))
397 (build-system b))))
398 (guard (c ((package-cross-build-system-error? c)
399 (eq? (package-error-package c) p)))
400 (package-cross-derivation %store p "mips64el-linux-gnu")
401 #f)))
402
05962f29
LC
403(test-equal "package-derivation, direct graft"
404 (package-derivation %store gnu-make)
405 (let ((p (package (inherit coreutils)
406 (replacement gnu-make))))
407 (package-derivation %store p)))
408
409(test-equal "package-cross-derivation, direct graft"
410 (package-cross-derivation %store gnu-make "mips64el-linux-gnu")
411 (let ((p (package (inherit coreutils)
412 (replacement gnu-make))))
413 (package-cross-derivation %store p "mips64el-linux-gnu")))
414
415(test-assert "package-grafts, indirect grafts"
416 (let* ((new (dummy-package "dep"
417 (arguments '(#:implicit-inputs? #f))))
418 (dep (package (inherit new) (version "0.0")))
419 (dep* (package (inherit dep) (replacement new)))
420 (dummy (dummy-package "dummy"
421 (arguments '(#:implicit-inputs? #f))
422 (inputs `(("dep" ,dep*))))))
423 (equal? (package-grafts %store dummy)
424 (list (graft
425 (origin (package-derivation %store dep))
426 (replacement (package-derivation %store new)))))))
427
428(test-assert "package-grafts, indirect grafts, cross"
429 (let* ((new (dummy-package "dep"
430 (arguments '(#:implicit-inputs? #f))))
431 (dep (package (inherit new) (version "0.0")))
432 (dep* (package (inherit dep) (replacement new)))
433 (dummy (dummy-package "dummy"
434 (arguments '(#:implicit-inputs? #f))
435 (inputs `(("dep" ,dep*)))))
436 (target "mips64el-linux-gnu"))
437 (equal? (package-grafts %store dummy #:target target)
438 (list (graft
439 (origin (package-cross-derivation %store dep target))
440 (replacement
441 (package-cross-derivation %store new target)))))))
442
443(test-assert "package-grafts, indirect grafts, propagated inputs"
444 (let* ((new (dummy-package "dep"
445 (arguments '(#:implicit-inputs? #f))))
446 (dep (package (inherit new) (version "0.0")))
447 (dep* (package (inherit dep) (replacement new)))
448 (prop (dummy-package "propagated"
449 (propagated-inputs `(("dep" ,dep*)))
450 (arguments '(#:implicit-inputs? #f))))
451 (dummy (dummy-package "dummy"
452 (arguments '(#:implicit-inputs? #f))
453 (inputs `(("prop" ,prop))))))
454 (equal? (package-grafts %store dummy)
455 (list (graft
456 (origin (package-derivation %store dep))
457 (replacement (package-derivation %store new)))))))
458
459(test-assert "package-derivation, indirect grafts"
460 (let* ((new (dummy-package "dep"
461 (arguments '(#:implicit-inputs? #f))))
462 (dep (package (inherit new) (version "0.0")))
463 (dep* (package (inherit dep) (replacement new)))
464 (dummy (dummy-package "dummy"
465 (arguments '(#:implicit-inputs? #f))
466 (inputs `(("dep" ,dep*)))))
467 (guile (package-derivation %store (canonical-package guile-2.0)
468 #:graft? #f)))
469 (equal? (package-derivation %store dummy)
470 (graft-derivation %store "dummy-0"
471 (package-derivation %store dummy #:graft? #f)
472 (package-grafts %store dummy)
473
474 ;; Use the same Guile as 'package-derivation'.
475 #:guile guile))))
476
d3d337d2
LC
477(test-equal "package->bag"
478 `("foo86-hurd" #f (,(package-source gnu-make))
479 (,(canonical-package glibc)) (,(canonical-package coreutils)))
480 (let ((bag (package->bag gnu-make "foo86-hurd")))
481 (list (bag-system bag) (bag-target bag)
482 (assoc-ref (bag-build-inputs bag) "source")
483 (assoc-ref (bag-build-inputs bag) "libc")
484 (assoc-ref (bag-build-inputs bag) "coreutils"))))
485
486(test-equal "package->bag, cross-compilation"
487 `(,(%current-system) "foo86-hurd"
488 (,(package-source gnu-make))
489 (,(canonical-package glibc)) (,(canonical-package coreutils)))
490 (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd")))
491 (list (bag-system bag) (bag-target bag)
492 (assoc-ref (bag-build-inputs bag) "source")
493 (assoc-ref (bag-build-inputs bag) "libc")
494 (assoc-ref (bag-build-inputs bag) "coreutils"))))
495
50373bab
LC
496(test-assert "package->bag, propagated inputs"
497 (let* ((dep (dummy-package "dep"))
498 (prop (dummy-package "prop"
499 (propagated-inputs `(("dep" ,dep)))))
500 (dummy (dummy-package "dummy"
501 (inputs `(("prop" ,prop)))))
502 (inputs (bag-transitive-inputs (package->bag dummy #:graft? #f))))
503 (match (assoc "prop/dep" inputs)
504 (("prop/dep" package)
505 (eq? package dep)))))
506
d3d337d2 507(test-assert "bag->derivation"
05962f29
LC
508 (parameterize ((%graft? #f))
509 (let ((bag (package->bag gnu-make))
510 (drv (package-derivation %store gnu-make)))
511 (parameterize ((%current-system "foox86-hurd")) ;should have no effect
512 (equal? drv (bag->derivation %store bag))))))
d3d337d2
LC
513
514(test-assert "bag->derivation, cross-compilation"
05962f29
LC
515 (parameterize ((%graft? #f))
516 (let* ((target "mips64el-linux-gnu")
517 (bag (package->bag gnu-make (%current-system) target))
518 (drv (package-cross-derivation %store gnu-make target)))
519 (parameterize ((%current-system "foox86-hurd") ;should have no effect
520 (%current-target-system "foo64-linux-gnu"))
521 (equal? drv (bag->derivation %store bag))))))
d3d337d2 522
ad1ebab3
LC
523(unless (false-if-exception (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV))
524 (test-skip 1))
9e782349
LC
525(test-assert "GNU Make, bootstrap"
526 ;; GNU Make is the first program built during bootstrap; we choose it
527 ;; here so that the test doesn't last for too long.
bdb36958 528 (let ((gnu-make (@@ (gnu packages commencement) gnu-make-boot0)))
9e782349
LC
529 (and (package? gnu-make)
530 (or (location? (package-location gnu-make))
531 (not (package-location gnu-make)))
532 (let* ((drv (package-derivation %store gnu-make))
59688fc4 533 (out (derivation->output-path drv)))
14da91e2 534 (and (build-derivations %store (list drv))
9e782349 535 (file-exists? (string-append out "/bin/make")))))))
e3ce5d70 536
ba326ce4
LC
537(test-eq "fold-packages" hello
538 (fold-packages (lambda (p r)
539 (if (string=? (package-name p) "hello")
540 p
541 r))
542 #f))
543
6b1891b0
LC
544(test-assert "find-packages-by-name"
545 (match (find-packages-by-name "hello")
546 (((? (cut eq? hello <>))) #t)
547 (wrong (pk 'find-packages-by-name wrong #f))))
548
549(test-assert "find-packages-by-name with version"
550 (match (find-packages-by-name "hello" (package-version hello))
551 (((? (cut eq? hello <>))) #t)
552 (wrong (pk 'find-packages-by-name wrong #f))))
553
cf81a236
LC
554(test-assert "--search-paths with pattern"
555 ;; Make sure 'guix package --search-paths' correctly reports environment
556 ;; variables when file patterns are used (in particular, it must follow
557 ;; symlinks when looking for 'catalog.xml'.) To do that, we rely on the
558 ;; libxml2 package specification, which contains such a definition.
559 (let* ((p1 (package
560 (name "foo") (version "0") (source #f)
561 (build-system trivial-build-system)
562 (arguments
563 `(#:guile ,%bootstrap-guile
564 #:modules ((guix build utils))
565 #:builder (begin
566 (use-modules (guix build utils))
567 (let ((out (assoc-ref %outputs "out")))
568 (mkdir-p (string-append out "/xml/bar/baz"))
569 (call-with-output-file
570 (string-append out "/xml/bar/baz/catalog.xml")
571 (lambda (port)
572 (display "xml? wat?!" port)))))))
573 (synopsis #f) (description #f)
574 (home-page #f) (license #f)))
575 (p2 (package
576 ;; Provide a fake libxml2 to avoid building the real one. This
577 ;; is OK because 'guix package' gets search path specifications
578 ;; from the same-named package found in the distro.
579 (name "libxml2") (version "0.0.0") (source #f)
580 (build-system trivial-build-system)
581 (arguments
582 `(#:guile ,%bootstrap-guile
583 #:builder (mkdir (assoc-ref %outputs "out"))))
584 (native-search-paths (package-native-search-paths libxml2))
585 (synopsis #f) (description #f)
586 (home-page #f) (license #f)))
587 (prof (run-with-store %store
588 (profile-derivation
589 (manifest (map package->manifest-entry
590 (list p1 p2)))
591 #:info-dir? #f)
592 #:guile-for-build (%guile-for-build))))
593 (build-derivations %store (list prof))
594 (string-match (format #f "^export XML_CATALOG_FILES=\"~a/xml/+bar/baz/catalog\\.xml\"\n"
595 (derivation->output-path prof))
596 (with-output-to-string
597 (lambda ()
598 (guix-package "-p" (derivation->output-path prof)
599 "--search-paths"))))))
600
e3ce5d70
LC
601(test-end "packages")
602
603\f
604(exit (= (test-runner-fail-count (test-runner-current)) 0))
605
606;;; Local Variables:
a3d73f59 607;;; eval: (put 'dummy-package 'scheme-indent-function 1)
e3ce5d70 608;;; End: