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