packages: 'generate-package-cache' uses 'supported-package?'.
[jackhill/guix/guix.git] / tests / packages.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
465a0d65 2;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
0db65c16 3;;; Copyright © Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
e3ce5d70 4;;;
233e7676 5;;; This file is part of GNU Guix.
e3ce5d70 6;;;
233e7676 7;;; GNU Guix is free software; you can redistribute it and/or modify it
e3ce5d70
LC
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
233e7676 12;;; GNU Guix is distributed in the hope that it will be useful, but
e3ce5d70
LC
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
233e7676 18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
e3ce5d70 19
e3ce5d70 20(define-module (test-packages)
c1bc358f 21 #:use-module (guix tests)
e3ce5d70 22 #:use-module (guix store)
cf81a236 23 #:use-module (guix monads)
fcadd9ff 24 #:use-module (guix grafts)
da675305 25 #:use-module ((guix gexp) #:select (local-file local-file-file))
2e1bafb0
LC
26 #:use-module ((guix utils)
27 ;; Rename the 'location' binding to allow proper syntax
28 ;; matching when setting the 'location' field of a package.
29 #:renamer (lambda (name)
30 (cond ((eq? name 'location) 'make-location)
31 (else name))))
ca719424 32 #:use-module (gcrypt hash)
e3ce5d70
LC
33 #:use-module (guix derivations)
34 #:use-module (guix packages)
7adf9b84 35 #:use-module (guix grafts)
aa8e0515 36 #:use-module (guix search-paths)
a18eda27 37 #:use-module (guix build-system)
be13fbfa 38 #:use-module (guix build-system trivial)
a3d73f59 39 #:use-module (guix build-system gnu)
0db65c16 40 #:use-module (guix memoization)
cf81a236
LC
41 #:use-module (guix profiles)
42 #:use-module (guix scripts package)
59a43334 43 #:use-module (gnu packages)
1ffa7090 44 #:use-module (gnu packages base)
05962f29 45 #:use-module (gnu packages guile)
1ffa7090 46 #:use-module (gnu packages bootstrap)
fcd75bdb 47 #:use-module (gnu packages version-control)
cf81a236 48 #:use-module (gnu packages xml)
05962f29 49 #:use-module (srfi srfi-1)
6b1891b0 50 #:use-module (srfi srfi-26)
9b222abe 51 #:use-module (srfi srfi-34)
dbab5150 52 #:use-module (srfi srfi-35)
6b1891b0 53 #:use-module (srfi srfi-64)
860a6f1a 54 #:use-module (rnrs io ports)
5239f3d9 55 #:use-module (ice-9 vlist)
2e1bafb0 56 #:use-module (ice-9 regex)
6b1891b0 57 #:use-module (ice-9 match))
e3ce5d70
LC
58
59;; Test the high-level packaging layer.
60
61(define %store
c1bc358f 62 (open-connection-for-tests))
e3ce5d70 63
b4c42a4b
LC
64;; Globally disable grafting to avoid rebuilding the world ('graft-derivation'
65;; can trigger builds early.)
66(%graft? #f)
67
05962f29
LC
68\f
69(test-begin "packages")
70
2e1bafb0 71(test-assert "printer with location"
74e667d1 72 (string-match "^#<package foo@0 foo.scm:42 [[:xdigit:]]+>$"
2e1bafb0
LC
73 (with-output-to-string
74 (lambda ()
75 (write
76 (dummy-package "foo"
77 (location (make-location "foo.scm" 42 7))))))))
78
79(test-assert "printer without location"
74e667d1 80 (string-match "^#<package foo@0 [[:xdigit:]]+>$"
2e1bafb0
LC
81 (with-output-to-string
82 (lambda ()
83 (write
84 (dummy-package "foo" (location #f)))))))
85
6980511b
LC
86(test-assert "hidden-package"
87 (and (hidden-package? (hidden-package (dummy-package "foo")))
88 (not (hidden-package? (dummy-package "foo")))))
89
01afdab8
LC
90(test-assert "package-superseded"
91 (let* ((new (dummy-package "bar"))
92 (old (deprecated-package "foo" new)))
93 (and (eq? (package-superseded old) new)
94 (mock ((gnu packages) find-best-packages-by-name (const (list old)))
95 (specification->package "foo")
96 (and (eq? new (specification->package "foo"))
97 (eq? new (specification->package+output "foo")))))))
98
5239f3d9
LC
99(test-assert "transaction-upgrade-entry, zero upgrades"
100 (let* ((old (dummy-package "foo" (version "1")))
465a0d65
LC
101 (tx (mock ((gnu packages) find-best-packages-by-name
102 (const '()))
5239f3d9
LC
103 ((@@ (guix scripts package) transaction-upgrade-entry)
104 (manifest-entry
105 (inherit (package->manifest-entry old))
106 (item (string-append (%store-prefix) "/"
107 (make-string 32 #\e) "-foo-1")))
108 (manifest-transaction)))))
109 (manifest-transaction-null? tx)))
110
111(test-assert "transaction-upgrade-entry, one upgrade"
112 (let* ((old (dummy-package "foo" (version "1")))
113 (new (dummy-package "foo" (version "2")))
465a0d65
LC
114 (tx (mock ((gnu packages) find-best-packages-by-name
115 (const (list new)))
5239f3d9
LC
116 ((@@ (guix scripts package) transaction-upgrade-entry)
117 (manifest-entry
118 (inherit (package->manifest-entry old))
119 (item (string-append (%store-prefix) "/"
120 (make-string 32 #\e) "-foo-1")))
121 (manifest-transaction)))))
122 (and (match (manifest-transaction-install tx)
123 ((($ <manifest-entry> "foo" "2" "out" item))
124 (eq? item new)))
125 (null? (manifest-transaction-remove tx)))))
126
01afdab8
LC
127(test-assert "transaction-upgrade-entry, superseded package"
128 (let* ((old (dummy-package "foo" (version "1")))
129 (new (dummy-package "bar" (version "2")))
130 (dep (deprecated-package "foo" new))
465a0d65
LC
131 (tx (mock ((gnu packages) find-best-packages-by-name
132 (const (list dep)))
01afdab8
LC
133 ((@@ (guix scripts package) transaction-upgrade-entry)
134 (manifest-entry
135 (inherit (package->manifest-entry old))
136 (item (string-append (%store-prefix) "/"
137 (make-string 32 #\e) "-foo-1")))
138 (manifest-transaction)))))
139 (and (match (manifest-transaction-install tx)
140 ((($ <manifest-entry> "bar" "2" "out" item))
141 (eq? item new)))
142 (match (manifest-transaction-remove tx)
143 (((? manifest-pattern? pattern))
144 (and (string=? (manifest-pattern-name pattern) "foo")
145 (string=? (manifest-pattern-version pattern) "1")
146 (string=? (manifest-pattern-output pattern) "out")))))))
147
d66c7096
LC
148(test-assert "package-field-location"
149 (let ()
150 (define (goto port line column)
151 (unless (and (= (port-column port) (- column 1))
152 (= (port-line port) (- line 1)))
153 (unless (eof-object? (get-char port))
154 (goto port line column))))
155
156 (define read-at
157 (match-lambda
158 (($ <location> file line column)
159 (call-with-input-file (search-path %load-path file)
160 (lambda (port)
161 (goto port line column)
162 (read port))))))
163
ee48b283
LC
164 ;; Until Guile 2.0.6 included, source properties were added only to pairs.
165 ;; Thus, check against both VALUE and (FIELD VALUE).
166 (and (member (read-at (package-field-location %bootstrap-guile 'name))
167 (let ((name (package-name %bootstrap-guile)))
168 (list name `(name ,name))))
169 (member (read-at (package-field-location %bootstrap-guile 'version))
170 (let ((version (package-version %bootstrap-guile)))
171 (list version `(version ,version))))
f903dc05 172 (not (package-field-location %bootstrap-guile 'does-not-exist)))))
d66c7096 173
0b8749b7
LC
174;; Make sure we don't change the file name to an absolute file name.
175(test-equal "package-field-location, relative file name"
176 (location-file (package-location %bootstrap-guile))
177 (with-fluids ((%file-port-name-canonicalization 'absolute))
178 (location-file (package-field-location %bootstrap-guile 'version))))
179
a3d73f59
LC
180(test-assert "package-transitive-inputs"
181 (let* ((a (dummy-package "a"))
182 (b (dummy-package "b"
183 (propagated-inputs `(("a" ,a)))))
184 (c (dummy-package "c"
185 (inputs `(("a" ,a)))))
186 (d (dummy-package "d"
187 (propagated-inputs `(("x" "something.drv")))))
188 (e (dummy-package "e"
189 (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
190 (and (null? (package-transitive-inputs a))
191 (equal? `(("a" ,a)) (package-transitive-inputs b))
192 (equal? `(("a" ,a)) (package-transitive-inputs c))
193 (equal? (package-propagated-inputs d)
194 (package-transitive-inputs d))
161094c8
LC
195 (equal? `(("b" ,b) ("c" ,c) ("d" ,d)
196 ("a" ,a) ("x" "something.drv"))
a3d73f59
LC
197 (pk 'x (package-transitive-inputs e))))))
198
161094c8
LC
199(test-assert "package-transitive-inputs, no duplicates"
200 (let* ((a (dummy-package "a"))
201 (b (dummy-package "b"
202 (inputs `(("a+" ,a)))
203 (native-inputs `(("a*" ,a)))
204 (propagated-inputs `(("a" ,a)))))
205 (c (dummy-package "c"
206 (propagated-inputs `(("b" ,b)))))
207 (d (dummy-package "d"
208 (inputs `(("a" ,a) ("c" ,c)))))
209 (e (dummy-package "e"
210 (inputs `(("b" ,b) ("c" ,c))))))
211 (and (null? (package-transitive-inputs a))
212 (equal? `(("a*" ,a) ("a+" ,a) ("a" ,a)) ;here duplicates are kept
213 (package-transitive-inputs b))
214 (equal? `(("b" ,b) ("a" ,a))
215 (package-transitive-inputs c))
216 (equal? `(("a" ,a) ("c" ,c) ("b" ,b)) ;duplicate A removed
217 (package-transitive-inputs d))
218 (equal? `(("b" ,b) ("c" ,c) ("a" ,a))
219 (package-transitive-inputs e))))) ;ditto
220
7c3c0374 221(test-equal "package-transitive-supported-systems"
c37a74bd
LC
222 '(("x" "y" "z") ;a
223 ("x" "y") ;b
224 ("y") ;c
225 ("y") ;d
226 ("y")) ;e
9bf3ced0
LC
227 ;; Use TRIVIAL-BUILD-SYSTEM because it doesn't add implicit inputs and thus
228 ;; doesn't restrict the set of supported systems.
229 (let* ((a (dummy-package "a"
230 (build-system trivial-build-system)
231 (supported-systems '("x" "y" "z"))))
232 (b (dummy-package "b"
233 (build-system trivial-build-system)
234 (supported-systems '("x" "y"))
235 (inputs `(("a" ,a)))))
236 (c (dummy-package "c"
237 (build-system trivial-build-system)
238 (supported-systems '("y" "z"))
239 (inputs `(("b" ,b)))))
240 (d (dummy-package "d"
241 (build-system trivial-build-system)
242 (supported-systems '("x" "y" "z"))
243 (inputs `(("b" ,b) ("c" ,c)))))
244 (e (dummy-package "e"
245 (build-system trivial-build-system)
246 (supported-systems '("x" "y" "z"))
247 (inputs `(("d" ,d))))))
7c3c0374
LC
248 (list (package-transitive-supported-systems a)
249 (package-transitive-supported-systems b)
c37a74bd
LC
250 (package-transitive-supported-systems c)
251 (package-transitive-supported-systems d)
252 (package-transitive-supported-systems e))))
7c3c0374 253
3e223a22
LC
254(test-assert "package-closure"
255 (let-syntax ((dummy-package/no-implicit
256 (syntax-rules ()
257 ((_ name rest ...)
258 (package
259 (inherit (dummy-package name rest ...))
260 (build-system trivial-build-system))))))
261 (let* ((a (dummy-package/no-implicit "a"))
262 (b (dummy-package/no-implicit "b"
263 (propagated-inputs `(("a" ,a)))))
264 (c (dummy-package/no-implicit "c"
265 (inputs `(("a" ,a)))))
266 (d (dummy-package/no-implicit "d"
267 (native-inputs `(("b" ,b)))))
268 (e (dummy-package/no-implicit "e"
269 (inputs `(("c" ,c) ("d" ,d))))))
270 (lset= eq?
271 (list a b c d e)
272 (package-closure (list e))
273 (package-closure (list e d))
274 (package-closure (list e c b))))))
275
3b4d0103
EB
276(test-equal "origin-actual-file-name"
277 "foo-1.tar.gz"
278 (let ((o (dummy-origin (uri "http://www.example.com/foo-1.tar.gz"))))
279 (origin-actual-file-name o)))
280
281(test-equal "origin-actual-file-name, file-name"
282 "foo-1.tar.gz"
283 (let ((o (dummy-origin
284 (uri "http://www.example.com/tarball")
285 (file-name "foo-1.tar.gz"))))
286 (origin-actual-file-name o)))
287
f77bcbc3
EB
288(let* ((o (dummy-origin))
289 (u (dummy-origin))
290 (i (dummy-origin))
291 (a (dummy-package "a"))
292 (b (dummy-package "b"
293 (inputs `(("a" ,a) ("i" ,i)))))
294 (c (package (inherit b) (source o)))
295 (d (dummy-package "d"
296 (build-system trivial-build-system)
297 (source u) (inputs `(("c" ,c))))))
298 (test-assert "package-direct-sources, no source"
299 (null? (package-direct-sources a)))
300 (test-equal "package-direct-sources, #f source"
301 (list i)
302 (package-direct-sources b))
303 (test-equal "package-direct-sources, not input source"
304 (list u)
305 (package-direct-sources d))
306 (test-assert "package-direct-sources"
307 (let ((s (package-direct-sources c)))
308 (and (= (length (pk 's-sources s)) 2)
309 (member o s)
310 (member i s))))
311 (test-assert "package-transitive-sources"
312 (let ((s (package-transitive-sources d)))
313 (and (= (length (pk 'd-sources s)) 3)
314 (member o s)
315 (member i s)
316 (member u s)))))
317
a6d0b306
EB
318(test-assert "transitive-input-references"
319 (let* ((a (dummy-package "a"))
320 (b (dummy-package "b"))
321 (c (dummy-package "c"
322 (inputs `(("a" ,a)))
323 (propagated-inputs `(("boo" ,b)))))
324 (d (dummy-package "d"
325 (inputs `(("c*" ,c)))))
326 (keys (map (match-lambda
327 (('assoc-ref 'l key)
328 key))
329 (pk 'refs (transitive-input-references
330 'l (package-inputs d))))))
331 (and (= (length keys) 2)
332 (member "c*" keys)
333 (member "boo" keys))))
334
9bf3ced0
LC
335(test-equal "package-transitive-supported-systems, implicit inputs"
336 %supported-systems
337
0db65c16
JN
338 ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on
339 ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored.
340 (let ((p (dummy-package "foo"
341 (build-system gnu-build-system)
342 (supported-systems
343 `("does-not-exist" "foobar" ,@%supported-systems)))))
344 (invalidate-memoization! package-transitive-supported-systems)
345 (parameterize ((%current-system "armhf-linux")) ; a traditionally-bootstrapped architecture
346 (package-transitive-supported-systems p))))
347
348(test-equal "package-transitive-supported-systems: reduced binary seed, implicit inputs"
349 '("x86_64-linux" "i686-linux")
350
9bf3ced0
LC
351 ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on
352 ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored.
353 (let ((p (dummy-package "foo"
354 (build-system gnu-build-system)
355 (supported-systems
356 `("does-not-exist" "foobar" ,@%supported-systems)))))
0db65c16
JN
357 (invalidate-memoization! package-transitive-supported-systems)
358 (parameterize ((%current-system "x86_64-linux"))
359 (package-transitive-supported-systems p))))
9bf3ced0 360
bbceb0ef
LC
361(test-assert "supported-package?"
362 (let ((p (dummy-package "foo"
363 (build-system gnu-build-system)
364 (supported-systems '("x86_64-linux" "does-not-exist")))))
365 (and (supported-package? p "x86_64-linux")
366 (not (supported-package? p "does-not-exist"))
367 (not (supported-package? p "i686-linux")))))
368
7357138b
LC
369(test-skip (if (not %store) 8 0))
370
371(test-assert "package-source-derivation, file"
372 (let* ((file (search-path %load-path "guix.scm"))
373 (package (package (inherit (dummy-package "p"))
374 (source file)))
375 (source (package-source-derivation %store
376 (package-source package))))
377 (and (store-path? source)
378 (valid-path? %store source)
379 (equal? (call-with-input-file source get-bytevector-all)
380 (call-with-input-file file get-bytevector-all)))))
381
382(test-assert "package-source-derivation, store path"
383 (let* ((file (add-to-store %store "guix.scm" #t "sha256"
384 (search-path %load-path "guix.scm")))
385 (package (package (inherit (dummy-package "p"))
386 (source file)))
387 (source (package-source-derivation %store
388 (package-source package))))
389 (string=? file source)))
e509d152 390
f80594cc
LC
391(test-assert "package-source-derivation, indirect store path"
392 (let* ((dir (add-to-store %store "guix-build" #t "sha256"
393 (dirname (search-path %load-path
394 "guix/build/utils.scm"))))
395 (package (package (inherit (dummy-package "p"))
396 (source (string-append dir "/utils.scm"))))
397 (source (package-source-derivation %store
398 (package-source package))))
399 (and (direct-store-path? source)
400 (string-suffix? "utils.scm" source))))
401
da675305
LC
402(test-assert "package-source-derivation, local-file"
403 (let* ((file (local-file "../guix/base32.scm"))
404 (package (package (inherit (dummy-package "p"))
405 (source file)))
406 (source (package-source-derivation %store
407 (package-source package))))
408 (and (store-path? source)
409 (string-suffix? "base32.scm" source)
410 (valid-path? %store source)
411 (equal? (call-with-input-file source get-bytevector-all)
412 (call-with-input-file
413 (search-path %load-path "guix/base32.scm")
414 get-bytevector-all)))))
415
12d720fd 416(unless (network-reachable?) (test-skip 1))
f9cc8971
LC
417(test-equal "package-source-derivation, snippet"
418 "OK"
f8ec8d96 419 (let* ((source (bootstrap-origin
f9cc8971 420 (origin
f8ec8d96 421 (inherit (bootstrap-guile-origin (%current-system)))
f9cc8971
LC
422 (patch-inputs
423 `(("tar" ,%bootstrap-coreutils&co)
424 ("xz" ,%bootstrap-coreutils&co)
425 ("patch" ,%bootstrap-coreutils&co)))
7db9608d 426 (patch-guile %bootstrap-guile)
f9cc8971 427 (modules '((guix build utils)))
f9cc8971
LC
428 (snippet '(begin
429 ;; We end up in 'bin', because it's the first
430 ;; directory, alphabetically. Not a very good
431 ;; example but hey.
432 (chmod "." #o777)
433 (symlink "guile" "guile-rocks")
434 (copy-recursively "../share/guile/2.0/scripts"
d6445dff
LC
435 "scripts")
436
437 ;; Make sure '.file_list' can be created.
438 (chmod ".." #o777))))))
f9cc8971
LC
439 (package (package (inherit (dummy-package "with-snippet"))
440 (source source)
441 (build-system trivial-build-system)
442 (inputs
443 `(("tar" ,(search-bootstrap-binary "tar"
444 (%current-system)))
445 ("xz" ,(search-bootstrap-binary "xz"
446 (%current-system)))))
447 (arguments
448 `(#:guile ,%bootstrap-guile
1e868858 449 #:modules ((guix build utils))
f9cc8971 450 #:builder
1e868858
MW
451 (begin
452 (use-modules (guix build utils))
453 (let ((tar (assoc-ref %build-inputs "tar"))
454 (xz (assoc-ref %build-inputs "xz"))
455 (source (assoc-ref %build-inputs "source")))
456 (invoke tar "xvf" source
457 "--use-compress-program" xz)
458 (unless (and (string=? "guile" (readlink "bin/guile-rocks"))
459 (file-exists? "bin/scripts/compile.scm"))
460 (error "the snippet apparently failed"))
461 (let ((out (assoc-ref %outputs "out")))
462 (call-with-output-file out
463 (lambda (p)
464 (display "OK" p))))
465 #t))))))
f9cc8971
LC
466 (drv (package-derivation %store package))
467 (out (derivation->output-path drv)))
468 (and (build-derivations %store (list (pk 'snippet-drv drv)))
469 (call-with-input-file out get-string-all))))
470
59688fc4
LC
471(test-assert "return value"
472 (let ((drv (package-derivation %store (dummy-package "p"))))
473 (and (derivation? drv)
474 (file-exists? (derivation-file-name drv)))))
be13fbfa 475
d510ab46
LC
476(test-assert "package-output"
477 (let* ((package (dummy-package "p"))
59688fc4
LC
478 (drv (package-derivation %store package)))
479 (and (derivation? drv)
480 (string=? (derivation->output-path drv)
d510ab46
LC
481 (package-output %store package "out")))))
482
dbab5150
LC
483(test-assert "patch not found yields a run-time error"
484 (guard (c ((condition-has-type? c &message)
485 (and (string-contains (condition-message c)
486 "does-not-exist.patch")
487 (string-contains (condition-message c)
488 "not found"))))
489 (let ((p (package
490 (inherit (dummy-package "p"))
491 (source (origin
492 (method (const #f))
493 (uri "http://whatever")
494 (patches
495 (list (search-patch "does-not-exist.patch")))
496 (sha256
497 (base32
498 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks4")))))))
499 (package-derivation %store p)
500 #f)))
501
76c48619
LC
502(let ((dummy (dummy-package "foo" (inputs `(("x" ,(current-module)))))))
503 (test-equal "&package-input-error"
504 (list dummy (current-module))
505 (guard (c ((package-input-error? c)
506 (list (package-error-package c)
507 (package-error-invalid-input c))))
508 (package-derivation %store dummy))))
509
f304c9c2
LC
510(test-assert "reference to non-existent output"
511 ;; See <http://bugs.gnu.org/19630>.
862abf8f
LC
512 (parameterize ((%graft? #f))
513 (let* ((dep (dummy-package "dep"))
514 (p (dummy-package "p"
515 (inputs `(("dep" ,dep "non-existent"))))))
516 (guard (c ((derivation-missing-output-error? c)
517 (and (string=? (derivation-missing-output c) "non-existent")
518 (equal? (package-derivation %store dep)
519 (derivation-error-derivation c)))))
520 (package-derivation %store p)))))
f304c9c2 521
be13fbfa
LC
522(test-assert "trivial"
523 (let* ((p (package (inherit (dummy-package "trivial"))
524 (build-system trivial-build-system)
525 (source #f)
526 (arguments
14da91e2
LC
527 `(#:guile ,%bootstrap-guile
528 #:builder
be13fbfa
LC
529 (begin
530 (mkdir %output)
531 (call-with-output-file (string-append %output "/test")
532 (lambda (p)
1e868858
MW
533 (display '(hello guix) p)))
534 #t)))))
be13fbfa
LC
535 (d (package-derivation %store p)))
536 (and (build-derivations %store (list d))
59688fc4 537 (let ((p (pk 'drv d (derivation->output-path d))))
be13fbfa
LC
538 (equal? '(hello guix)
539 (call-with-input-file (string-append p "/test") read))))))
e3ce5d70 540
860a6f1a
LC
541(test-assert "trivial with local file as input"
542 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
543 (p (package (inherit (dummy-package "trivial-with-input-file"))
544 (build-system trivial-build-system)
545 (source #f)
546 (arguments
547 `(#:guile ,%bootstrap-guile
1e868858
MW
548 #:builder (begin
549 (copy-file (assoc-ref %build-inputs "input")
550 %output)
551 #t)))
860a6f1a
LC
552 (inputs `(("input" ,i)))))
553 (d (package-derivation %store p)))
554 (and (build-derivations %store (list d))
59688fc4 555 (let ((p (pk 'drv d (derivation->output-path d))))
860a6f1a
LC
556 (equal? (call-with-input-file p get-bytevector-all)
557 (call-with-input-file i get-bytevector-all))))))
558
03761a44
LC
559(test-assert "trivial with source"
560 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
561 (p (package (inherit (dummy-package "trivial-with-source"))
562 (build-system trivial-build-system)
563 (source i)
564 (arguments
565 `(#:guile ,%bootstrap-guile
1e868858
MW
566 #:builder (begin
567 (copy-file (assoc-ref %build-inputs "source")
568 %output)
569 #t)))))
03761a44
LC
570 (d (package-derivation %store p)))
571 (and (build-derivations %store (list d))
572 (let ((p (derivation->output-path d)))
573 (equal? (call-with-input-file p get-bytevector-all)
574 (call-with-input-file i get-bytevector-all))))))
575
592ef6c8
LC
576(test-assert "trivial with system-dependent input"
577 (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
578 (build-system trivial-build-system)
579 (source #f)
580 (arguments
581 `(#:guile ,%bootstrap-guile
1e868858 582 #:modules ((guix build utils))
592ef6c8 583 #:builder
1e868858
MW
584 (begin
585 (use-modules (guix build utils))
586 (let ((out (assoc-ref %outputs "out"))
587 (bash (assoc-ref %build-inputs "bash")))
588 (invoke bash "-c"
589 (format #f "echo hello > ~a" out))))))
dd6b9a37
LC
590 (inputs `(("bash" ,(search-bootstrap-binary "bash"
591 (%current-system)))))))
592ef6c8
LC
592 (d (package-derivation %store p)))
593 (and (build-derivations %store (list d))
59688fc4 594 (let ((p (pk 'drv d (derivation->output-path d))))
592ef6c8
LC
595 (eq? 'hello (call-with-input-file p read))))))
596
29760251
LC
597(test-assert "trivial with #:allowed-references"
598 (let* ((p (package
599 (inherit (dummy-package "trivial"))
600 (build-system trivial-build-system)
601 (arguments
602 `(#:guile ,%bootstrap-guile
603 #:allowed-references (,%bootstrap-guile)
604 #:builder
605 (begin
606 (mkdir %output)
607 ;; The reference to itself isn't allowed so building it
608 ;; should fail.
1e868858
MW
609 (symlink %output (string-append %output "/self"))
610 #t)))))
29760251 611 (d (package-derivation %store p)))
f9e8a123 612 (guard (c ((store-protocol-error? c) #t))
29760251
LC
613 (build-derivations %store (list d))
614 #f)))
615
a18eda27
LC
616(test-assert "search paths"
617 (let* ((p (make-prompt-tag "return-search-paths"))
618 (s (build-system
0d5a559f 619 (name 'raw)
a18eda27 620 (description "Raw build system with direct store access")
d3d337d2
LC
621 (lower (lambda* (name #:key source inputs system target
622 #:allow-other-keys)
0d5a559f
LC
623 (bag
624 (name name)
d3d337d2 625 (system system) (target target)
0d5a559f
LC
626 (build-inputs inputs)
627 (build
628 (lambda* (store name inputs
629 #:key outputs system search-paths)
630 search-paths)))))))
a18eda27
LC
631 (x (list (search-path-specification
632 (variable "GUILE_LOAD_PATH")
af070955 633 (files '("share/guile/site/2.0")))
a18eda27
LC
634 (search-path-specification
635 (variable "GUILE_LOAD_COMPILED_PATH")
af070955 636 (files '("share/guile/site/2.0")))))
a18eda27
LC
637 (a (package (inherit (dummy-package "guile"))
638 (build-system s)
639 (native-search-paths x)))
640 (b (package (inherit (dummy-package "guile-foo"))
641 (build-system s)
642 (inputs `(("guile" ,a)))))
643 (c (package (inherit (dummy-package "guile-bar"))
644 (build-system s)
645 (inputs `(("guile" ,a)
646 ("guile-foo" ,b))))))
647 (let-syntax ((collect (syntax-rules ()
648 ((_ body ...)
649 (call-with-prompt p
650 (lambda ()
651 body ...)
652 (lambda (k search-paths)
653 search-paths))))))
654 (and (null? (collect (package-derivation %store a)))
655 (equal? x (collect (package-derivation %store b)))
656 (equal? x (collect (package-derivation %store c)))))))
657
aa8e0515
LC
658(test-assert "package-transitive-native-search-paths"
659 (let* ((sp (lambda (name)
660 (list (search-path-specification
661 (variable name)
662 (files '("foo/bar"))))))
663 (p0 (dummy-package "p0" (native-search-paths (sp "PATH0"))))
664 (p1 (dummy-package "p1" (native-search-paths (sp "PATH1"))))
665 (p2 (dummy-package "p2"
666 (native-search-paths (sp "PATH2"))
667 (inputs `(("p0" ,p0)))
668 (propagated-inputs `(("p1" ,p1)))))
669 (p3 (dummy-package "p3"
670 (native-search-paths (sp "PATH3"))
671 (native-inputs `(("p0" ,p0)))
672 (propagated-inputs `(("p2" ,p2))))))
673 (lset= string=?
674 '("PATH1" "PATH2" "PATH3")
675 (map search-path-specification-variable
676 (package-transitive-native-search-paths p3)))))
677
9c1edabd 678(test-assert "package-cross-derivation"
59688fc4
LC
679 (let ((drv (package-cross-derivation %store (dummy-package "p")
680 "mips64el-linux-gnu")))
681 (and (derivation? drv)
682 (file-exists? (derivation-file-name drv)))))
9c1edabd 683
5dce8218
LC
684(test-assert "package-cross-derivation, trivial-build-system"
685 (let ((p (package (inherit (dummy-package "p"))
686 (build-system trivial-build-system)
687 (arguments '(#:builder (exit 1))))))
59688fc4
LC
688 (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu")))
689 (derivation? drv))))
5dce8218 690
9b222abe
LC
691(test-assert "package-cross-derivation, no cross builder"
692 (let* ((b (build-system (inherit trivial-build-system)
0d5a559f 693 (lower (const #f))))
9b222abe
LC
694 (p (package (inherit (dummy-package "p"))
695 (build-system b))))
696 (guard (c ((package-cross-build-system-error? c)
697 (eq? (package-error-package c) p)))
698 (package-cross-derivation %store p "mips64el-linux-gnu")
699 #f)))
700
b4c42a4b
LC
701;; XXX: The next two tests can trigger builds when the distro defines
702;; replacements on core packages, so they're disable for lack of a better
703;; solution.
704
705;; (test-equal "package-derivation, direct graft"
706;; (package-derivation %store gnu-make #:graft? #f)
707;; (let ((p (package (inherit coreutils)
708;; (replacement gnu-make))))
709;; (package-derivation %store p #:graft? #t)))
05962f29 710
b4c42a4b
LC
711;; (test-equal "package-cross-derivation, direct graft"
712;; (package-cross-derivation %store gnu-make "mips64el-linux-gnu"
713;; #:graft? #f)
714;; (let ((p (package (inherit coreutils)
715;; (replacement gnu-make))))
716;; (package-cross-derivation %store p "mips64el-linux-gnu"
717;; #:graft? #t)))
05962f29
LC
718
719(test-assert "package-grafts, indirect grafts"
720 (let* ((new (dummy-package "dep"
721 (arguments '(#:implicit-inputs? #f))))
722 (dep (package (inherit new) (version "0.0")))
723 (dep* (package (inherit dep) (replacement new)))
724 (dummy (dummy-package "dummy"
725 (arguments '(#:implicit-inputs? #f))
726 (inputs `(("dep" ,dep*))))))
727 (equal? (package-grafts %store dummy)
728 (list (graft
729 (origin (package-derivation %store dep))
730 (replacement (package-derivation %store new)))))))
731
d0025d01
LC
732;; XXX: This test would require building the cross toolchain just to see if it
733;; needs grafting, which is obviously too expensive, and thus disabled.
734;;
735;; (test-assert "package-grafts, indirect grafts, cross"
736;; (let* ((new (dummy-package "dep"
737;; (arguments '(#:implicit-inputs? #f))))
738;; (dep (package (inherit new) (version "0.0")))
739;; (dep* (package (inherit dep) (replacement new)))
740;; (dummy (dummy-package "dummy"
741;; (arguments '(#:implicit-inputs? #f))
742;; (inputs `(("dep" ,dep*)))))
743;; (target "mips64el-linux-gnu"))
744;; ;; XXX: There might be additional grafts, for instance if the distro
745;; ;; defines replacements for core packages like Perl.
746;; (member (graft
747;; (origin (package-cross-derivation %store dep target))
748;; (replacement
749;; (package-cross-derivation %store new target)))
750;; (package-grafts %store dummy #:target target))))
05962f29
LC
751
752(test-assert "package-grafts, indirect grafts, propagated inputs"
753 (let* ((new (dummy-package "dep"
754 (arguments '(#:implicit-inputs? #f))))
755 (dep (package (inherit new) (version "0.0")))
756 (dep* (package (inherit dep) (replacement new)))
757 (prop (dummy-package "propagated"
758 (propagated-inputs `(("dep" ,dep*)))
759 (arguments '(#:implicit-inputs? #f))))
760 (dummy (dummy-package "dummy"
761 (arguments '(#:implicit-inputs? #f))
762 (inputs `(("prop" ,prop))))))
763 (equal? (package-grafts %store dummy)
764 (list (graft
765 (origin (package-derivation %store dep))
766 (replacement (package-derivation %store new)))))))
767
fcadd9ff
LC
768(test-assert "package-grafts, same replacement twice"
769 (let* ((new (dummy-package "dep"
770 (version "1")
771 (arguments '(#:implicit-inputs? #f))))
772 (dep (package (inherit new) (version "0") (replacement new)))
773 (p1 (dummy-package "intermediate1"
774 (arguments '(#:implicit-inputs? #f))
775 (inputs `(("dep" ,dep)))))
776 (p2 (dummy-package "intermediate2"
777 (arguments '(#:implicit-inputs? #f))
778 ;; Here we copy DEP to have an equivalent package that is not
779 ;; 'eq?' to DEP. This is similar to what happens with
780 ;; 'package-with-explicit-inputs' & co.
781 (inputs `(("dep" ,(package (inherit dep)))))))
782 (p3 (dummy-package "final"
783 (arguments '(#:implicit-inputs? #f))
784 (inputs `(("p1" ,p1) ("p2" ,p2))))))
785 (equal? (package-grafts %store p3)
786 (list (graft
787 (origin (package-derivation %store
788 (package (inherit dep)
789 (replacement #f))))
790 (replacement (package-derivation %store new)))))))
791
d0025d01
LC
792(test-assert "replacement also grafted"
793 ;; We build a DAG as below, where dotted arrows represent replacements and
794 ;; solid arrows represent dependencies:
795 ;;
796 ;; P1 ·············> P1R
797 ;; |\__________________.
798 ;; v v
799 ;; P2 ·············> P2R
800 ;; |
801 ;; v
802 ;; P3
803 ;;
804 ;; We want to make sure that:
805 ;; grafts(P3) = (P1,P1R) + (P2, grafted(P2R, (P1,P1R)))
806 ;; where:
807 ;; (A,B) is a graft to replace A by B
808 ;; grafted(DRV,G) denoted DRV with graft G applied
809 (let* ((p1r (dummy-package "P1"
810 (build-system trivial-build-system)
811 (arguments
812 `(#:guile ,%bootstrap-guile
813 #:builder (let ((out (assoc-ref %outputs "out")))
814 (mkdir out)
815 (call-with-output-file
816 (string-append out "/replacement")
817 (const #t)))))))
818 (p1 (package
819 (inherit p1r) (name "p1") (replacement p1r)
820 (arguments
821 `(#:guile ,%bootstrap-guile
1e868858
MW
822 #:builder (begin
823 (mkdir (assoc-ref %outputs "out"))
824 #t)))))
d0025d01
LC
825 (p2r (dummy-package "P2"
826 (build-system trivial-build-system)
827 (inputs `(("p1" ,p1)))
828 (arguments
829 `(#:guile ,%bootstrap-guile
830 #:builder (let ((out (assoc-ref %outputs "out")))
831 (mkdir out)
832 (chdir out)
833 (symlink (assoc-ref %build-inputs "p1") "p1")
834 (call-with-output-file (string-append out "/replacement")
835 (const #t)))))))
836 (p2 (package
837 (inherit p2r) (name "p2") (replacement p2r)
838 (arguments
839 `(#:guile ,%bootstrap-guile
840 #:builder (let ((out (assoc-ref %outputs "out")))
841 (mkdir out)
842 (chdir out)
843 (symlink (assoc-ref %build-inputs "p1")
1e868858
MW
844 "p1")
845 #t)))))
d0025d01
LC
846 (p3 (dummy-package "p3"
847 (build-system trivial-build-system)
848 (inputs `(("p2" ,p2)))
849 (arguments
850 `(#:guile ,%bootstrap-guile
851 #:builder (let ((out (assoc-ref %outputs "out")))
852 (mkdir out)
853 (chdir out)
854 (symlink (assoc-ref %build-inputs "p2")
1e868858
MW
855 "p2")
856 #t))))))
d0025d01
LC
857 (lset= equal?
858 (package-grafts %store p3)
859 (list (graft
860 (origin (package-derivation %store p1 #:graft? #f))
861 (replacement (package-derivation %store p1r)))
862 (graft
863 (origin (package-derivation %store p2 #:graft? #f))
864 (replacement
865 (package-derivation %store p2r #:graft? #t)))))))
866
c22a1324
LC
867;;; XXX: Nowadays 'graft-derivation' needs to build derivations beforehand to
868;;; find out about their run-time dependencies, so this test is no longer
869;;; applicable since it would trigger a full rebuild.
870;;
871;; (test-assert "package-derivation, indirect grafts"
872;; (let* ((new (dummy-package "dep"
873;; (arguments '(#:implicit-inputs? #f))))
874;; (dep (package (inherit new) (version "0.0")))
875;; (dep* (package (inherit dep) (replacement new)))
876;; (dummy (dummy-package "dummy"
877;; (arguments '(#:implicit-inputs? #f))
878;; (inputs `(("dep" ,dep*)))))
879;; (guile (package-derivation %store (canonical-package guile-2.0)
880;; #:graft? #f)))
881;; (equal? (package-derivation %store dummy)
882;; (graft-derivation %store
883;; (package-derivation %store dummy #:graft? #f)
884;; (package-grafts %store dummy)
885
886;; ;; Use the same Guile as 'package-derivation'.
887;; #:guile guile))))
05962f29 888
d3d337d2
LC
889(test-equal "package->bag"
890 `("foo86-hurd" #f (,(package-source gnu-make))
891 (,(canonical-package glibc)) (,(canonical-package coreutils)))
892 (let ((bag (package->bag gnu-make "foo86-hurd")))
893 (list (bag-system bag) (bag-target bag)
894 (assoc-ref (bag-build-inputs bag) "source")
895 (assoc-ref (bag-build-inputs bag) "libc")
896 (assoc-ref (bag-build-inputs bag) "coreutils"))))
897
898(test-equal "package->bag, cross-compilation"
899 `(,(%current-system) "foo86-hurd"
900 (,(package-source gnu-make))
901 (,(canonical-package glibc)) (,(canonical-package coreutils)))
902 (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd")))
903 (list (bag-system bag) (bag-target bag)
904 (assoc-ref (bag-build-inputs bag) "source")
905 (assoc-ref (bag-build-inputs bag) "libc")
906 (assoc-ref (bag-build-inputs bag) "coreutils"))))
907
50373bab
LC
908(test-assert "package->bag, propagated inputs"
909 (let* ((dep (dummy-package "dep"))
910 (prop (dummy-package "prop"
911 (propagated-inputs `(("dep" ,dep)))))
912 (dummy (dummy-package "dummy"
913 (inputs `(("prop" ,prop)))))
914 (inputs (bag-transitive-inputs (package->bag dummy #:graft? #f))))
161094c8
LC
915 (match (assoc "dep" inputs)
916 (("dep" package)
50373bab
LC
917 (eq? package dep)))))
918
d3d337d2 919(test-assert "bag->derivation"
05962f29
LC
920 (parameterize ((%graft? #f))
921 (let ((bag (package->bag gnu-make))
922 (drv (package-derivation %store gnu-make)))
923 (parameterize ((%current-system "foox86-hurd")) ;should have no effect
924 (equal? drv (bag->derivation %store bag))))))
d3d337d2
LC
925
926(test-assert "bag->derivation, cross-compilation"
05962f29
LC
927 (parameterize ((%graft? #f))
928 (let* ((target "mips64el-linux-gnu")
929 (bag (package->bag gnu-make (%current-system) target))
930 (drv (package-cross-derivation %store gnu-make target)))
931 (parameterize ((%current-system "foox86-hurd") ;should have no effect
932 (%current-target-system "foo64-linux-gnu"))
933 (equal? drv (bag->derivation %store bag))))))
d3d337d2 934
b69c5c2c
LC
935(when (or (not (network-reachable?)) (shebang-too-long?))
936 (test-skip 1))
9e782349 937(test-assert "GNU Make, bootstrap"
03d76577
LC
938 ;; GNU-MAKE-FOR-TESTS can be built cheaply; we choose it here so that the
939 ;; test doesn't last for too long.
940 (let ((gnu-make gnu-make-for-tests))
9e782349
LC
941 (and (package? gnu-make)
942 (or (location? (package-location gnu-make))
943 (not (package-location gnu-make)))
944 (let* ((drv (package-derivation %store gnu-make))
59688fc4 945 (out (derivation->output-path drv)))
14da91e2 946 (and (build-derivations %store (list drv))
9e782349 947 (file-exists? (string-append out "/bin/make")))))))
e3ce5d70 948
f37f2b83
LC
949(test-equal "package-mapping"
950 42
951 (let* ((dep (dummy-package "chbouib"
952 (native-inputs `(("x" ,grep)))))
953 (p0 (dummy-package "example"
954 (inputs `(("foo" ,coreutils)
955 ("bar" ,grep)
956 ("baz" ,dep)))))
957 (transform (lambda (p)
958 (package (inherit p) (source 42))))
959 (rewrite (package-mapping transform))
960 (p1 (rewrite p0)))
961 (and (eq? p1 (rewrite p0))
962 (eqv? 42 (package-source p1))
963 (match (package-inputs p1)
964 ((("foo" dep1) ("bar" dep2) ("baz" dep3))
965 (and (eq? dep1 (rewrite coreutils)) ;memoization
966 (eq? dep2 (rewrite grep))
967 (eq? dep3 (rewrite dep))
968 (eqv? 42
969 (package-source dep1) (package-source dep2)
970 (package-source dep3))
971 (match (package-native-inputs dep3)
972 ((("x" dep))
973 (and (eq? dep (rewrite grep))
974 (package-source dep))))))))))
975
2a75b0b6
LC
976(test-assert "package-input-rewriting"
977 (let* ((dep (dummy-package "chbouib"
978 (native-inputs `(("x" ,grep)))))
979 (p0 (dummy-package "example"
980 (inputs `(("foo" ,coreutils)
981 ("bar" ,grep)
982 ("baz" ,dep)))))
983 (rewrite (package-input-rewriting `((,coreutils . ,sed)
984 (,grep . ,findutils))
985 (cut string-append "r-" <>)))
986 (p1 (rewrite p0))
987 (p2 (rewrite p0)))
988 (and (not (eq? p1 p0))
989 (eq? p1 p2) ;memoization
990 (string=? "r-example" (package-name p1))
991 (match (package-inputs p1)
992 ((("foo" dep1) ("bar" dep2) ("baz" dep3))
993 (and (eq? dep1 sed)
994 (eq? dep2 findutils)
995 (string=? (package-name dep3) "r-chbouib")
996 (eq? dep3 (rewrite dep)) ;memoization
997 (match (package-native-inputs dep3)
998 ((("x" dep))
999 (eq? dep findutils)))))))))
1000
f258d886
LC
1001(test-assert "package-input-rewriting/spec"
1002 (let* ((dep (dummy-package "chbouib"
1003 (native-inputs `(("x" ,grep)))))
1004 (p0 (dummy-package "example"
1005 (inputs `(("foo" ,coreutils)
1006 ("bar" ,grep)
1007 ("baz" ,dep)))))
1008 (rewrite (package-input-rewriting/spec
1009 `(("coreutils" . ,(const sed))
1010 ("grep" . ,(const findutils)))))
1011 (p1 (rewrite p0))
1012 (p2 (rewrite p0)))
1013 (and (not (eq? p1 p0))
1014 (eq? p1 p2) ;memoization
1015 (string=? "example" (package-name p1))
1016 (match (package-inputs p1)
1017 ((("foo" dep1) ("bar" dep2) ("baz" dep3))
1018 (and (string=? (package-full-name dep1)
1019 (package-full-name sed))
1020 (string=? (package-full-name dep2)
1021 (package-full-name findutils))
1022 (string=? (package-name dep3) "chbouib")
1023 (eq? dep3 (rewrite dep)) ;memoization
1024 (match (package-native-inputs dep3)
1025 ((("x" dep))
1026 (string=? (package-full-name dep)
1027 (package-full-name findutils))))))))))
1028
1029(test-assert "package-input-rewriting/spec, partial match"
1030 (let* ((dep (dummy-package "chbouib"
1031 (version "1")
1032 (native-inputs `(("x" ,grep)))))
1033 (p0 (dummy-package "example"
1034 (inputs `(("foo" ,coreutils)
1035 ("bar" ,dep)))))
1036 (rewrite (package-input-rewriting/spec
1037 `(("chbouib@123" . ,(const sed)) ;not matched
1038 ("grep" . ,(const findutils)))))
1039 (p1 (rewrite p0)))
1040 (and (not (eq? p1 p0))
1041 (string=? "example" (package-name p1))
1042 (match (package-inputs p1)
1043 ((("foo" dep1) ("bar" dep2))
1044 (and (string=? (package-full-name dep1)
1045 (package-full-name coreutils))
1046 (eq? dep2 (rewrite dep)) ;memoization
1047 (match (package-native-inputs dep2)
1048 ((("x" dep))
1049 (string=? (package-full-name dep)
1050 (package-full-name findutils))))))))))
1051
c423ae89
LC
1052(test-equal "package-patched-vulnerabilities"
1053 '(("CVE-2015-1234")
1054 ("CVE-2016-1234" "CVE-2018-4567")
1055 ())
1056 (let ((p1 (dummy-package "pi"
1057 (source (dummy-origin
1058 (patches (list "/a/b/pi-CVE-2015-1234.patch"))))))
1059 (p2 (dummy-package "pi"
1060 (source (dummy-origin
1061 (patches (list
1062 "/a/b/pi-CVE-2016-1234-CVE-2018-4567.patch"))))))
1063 (p3 (dummy-package "pi" (source (dummy-origin)))))
1064 (map package-patched-vulnerabilities
1065 (list p1 p2 p3))))
1066
ba326ce4
LC
1067(test-eq "fold-packages" hello
1068 (fold-packages (lambda (p r)
1069 (if (string=? (package-name p) "hello")
1070 p
1071 r))
1072 #f))
1073
386b71d1
LC
1074(test-assert "fold-packages, hidden package"
1075 ;; There are two public variables providing "guile@2.0" ('guile-final' in
b66d6d52 1076 ;; commencement.scm and 'guile-2.0' in guile.scm), but only the latter
386b71d1
LC
1077 ;; should show up.
1078 (match (fold-packages (lambda (p r)
1079 (if (and (string=? (package-name p) "guile")
1080 (string-prefix? "2.0"
1081 (package-version p)))
1082 (cons p r)
1083 r))
1084 '())
1085 ((one)
b66d6d52 1086 (eq? one guile-2.0))))
386b71d1 1087
0ea939fb
LC
1088(test-assert "fold-available-packages with/without cache"
1089 (let ()
1090 (define no-cache
1091 (fold-available-packages (lambda* (name version result #:rest rest)
1092 (cons (cons* name version rest)
1093 result))
1094 '()))
1095
1096 (define from-cache
1097 (call-with-temporary-directory
1098 (lambda (cache)
1099 (generate-package-cache cache)
1100 (mock ((guix describe) current-profile (const cache))
1101 (mock ((gnu packages) cache-is-authoritative? (const #t))
1102 (fold-available-packages (lambda* (name version result
1103 #:rest rest)
1104 (cons (cons* name version rest)
1105 result))
1106 '()))))))
1107
36754eee
LC
1108 (and (equal? (delete-duplicates from-cache) from-cache)
1109 (lset= equal? no-cache from-cache))))
0ea939fb 1110
6b1891b0
LC
1111(test-assert "find-packages-by-name"
1112 (match (find-packages-by-name "hello")
1113 (((? (cut eq? hello <>))) #t)
1114 (wrong (pk 'find-packages-by-name wrong #f))))
1115
1116(test-assert "find-packages-by-name with version"
1117 (match (find-packages-by-name "hello" (package-version hello))
1118 (((? (cut eq? hello <>))) #t)
1119 (wrong (pk 'find-packages-by-name wrong #f))))
1120
5fbdc9a5
LC
1121(test-equal "find-packages-by-name with cache"
1122 (find-packages-by-name "guile")
1123 (call-with-temporary-directory
1124 (lambda (cache)
1125 (generate-package-cache cache)
1126 (mock ((guix describe) current-profile (const cache))
1127 (mock ((gnu packages) cache-is-authoritative? (const #t))
1128 (find-packages-by-name "guile"))))))
1129
1130(test-equal "find-packages-by-name + version, with cache"
1131 (find-packages-by-name "guile" "2")
1132 (call-with-temporary-directory
1133 (lambda (cache)
1134 (generate-package-cache cache)
1135 (mock ((guix describe) current-profile (const cache))
1136 (mock ((gnu packages) cache-is-authoritative? (const #t))
1137 (find-packages-by-name "guile" "2"))))))
1138
cf81a236
LC
1139(test-assert "--search-paths with pattern"
1140 ;; Make sure 'guix package --search-paths' correctly reports environment
1141 ;; variables when file patterns are used (in particular, it must follow
1142 ;; symlinks when looking for 'catalog.xml'.) To do that, we rely on the
1143 ;; libxml2 package specification, which contains such a definition.
1144 (let* ((p1 (package
1145 (name "foo") (version "0") (source #f)
1146 (build-system trivial-build-system)
1147 (arguments
1148 `(#:guile ,%bootstrap-guile
1149 #:modules ((guix build utils))
1150 #:builder (begin
1151 (use-modules (guix build utils))
1152 (let ((out (assoc-ref %outputs "out")))
1153 (mkdir-p (string-append out "/xml/bar/baz"))
1154 (call-with-output-file
1155 (string-append out "/xml/bar/baz/catalog.xml")
1156 (lambda (port)
1e868858
MW
1157 (display "xml? wat?!" port)))
1158 #t))))
cf81a236
LC
1159 (synopsis #f) (description #f)
1160 (home-page #f) (license #f)))
1161 (p2 (package
1162 ;; Provide a fake libxml2 to avoid building the real one. This
1163 ;; is OK because 'guix package' gets search path specifications
1164 ;; from the same-named package found in the distro.
1165 (name "libxml2") (version "0.0.0") (source #f)
1166 (build-system trivial-build-system)
1167 (arguments
1168 `(#:guile ,%bootstrap-guile
1e868858
MW
1169 #:builder (begin
1170 (mkdir (assoc-ref %outputs "out"))
1171 #t)))
cf81a236
LC
1172 (native-search-paths (package-native-search-paths libxml2))
1173 (synopsis #f) (description #f)
1174 (home-page #f) (license #f)))
1175 (prof (run-with-store %store
1176 (profile-derivation
1177 (manifest (map package->manifest-entry
1178 (list p1 p2)))
a6562c7e
LC
1179 #:hooks '()
1180 #:locales? #f)
cf81a236
LC
1181 #:guile-for-build (%guile-for-build))))
1182 (build-derivations %store (list prof))
1183 (string-match (format #f "^export XML_CATALOG_FILES=\"~a/xml/+bar/baz/catalog\\.xml\"\n"
77559f23 1184 (regexp-quote (derivation->output-path prof)))
cf81a236
LC
1185 (with-output-to-string
1186 (lambda ()
1187 (guix-package "-p" (derivation->output-path prof)
1188 "--search-paths"))))))
1189
fcd75bdb
LC
1190(test-assert "--search-paths with single-item search path"
1191 ;; Make sure 'guix package --search-paths' correctly reports environment
1192 ;; variables for things like 'GIT_SSL_CAINFO' that have #f as their
1193 ;; separator, meaning that the first match wins.
1194 (let* ((p1 (dummy-package "foo"
1195 (build-system trivial-build-system)
1196 (arguments
1197 `(#:guile ,%bootstrap-guile
1198 #:modules ((guix build utils))
1199 #:builder (begin
1200 (use-modules (guix build utils))
1201 (let ((out (assoc-ref %outputs "out")))
1202 (mkdir-p (string-append out "/etc/ssl/certs"))
1203 (call-with-output-file
1204 (string-append
1205 out "/etc/ssl/certs/ca-certificates.crt")
1206 (const #t))))))))
1207 (p2 (package (inherit p1) (name "bar")))
1208 (p3 (dummy-package "git"
1209 ;; Provide a fake Git to avoid building the real one.
1210 (build-system trivial-build-system)
1211 (arguments
1212 `(#:guile ,%bootstrap-guile
1e868858
MW
1213 #:builder (begin
1214 (mkdir (assoc-ref %outputs "out"))
1215 #t)))
fcd75bdb
LC
1216 (native-search-paths (package-native-search-paths git))))
1217 (prof1 (run-with-store %store
1218 (profile-derivation
1219 (packages->manifest (list p1 p3))
1220 #:hooks '()
1221 #:locales? #f)
1222 #:guile-for-build (%guile-for-build)))
1223 (prof2 (run-with-store %store
1224 (profile-derivation
1225 (packages->manifest (list p2 p3))
1226 #:hooks '()
1227 #:locales? #f)
1228 #:guile-for-build (%guile-for-build))))
1229 (build-derivations %store (list prof1 prof2))
1230 (string-match (format #f "^export GIT_SSL_CAINFO=\"~a/etc/ssl/certs/ca-certificates.crt"
1231 (regexp-quote (derivation->output-path prof1)))
1232 (with-output-to-string
1233 (lambda ()
1234 (guix-package "-p" (derivation->output-path prof1)
1235 "-p" (derivation->output-path prof2)
1236 "--search-paths"))))))
1237
efb107e0
LC
1238(test-equal "specification->package when not found"
1239 'quit
1240 (catch 'quit
1241 (lambda ()
1242 ;; This should call 'leave', producing an error message.
1243 (specification->package "this-package-does-not-exist"))
1244 (lambda (key . args)
1245 key)))
1246
066eeae1
LC
1247(test-equal "specification->package+output"
1248 `((,coreutils "out") (,coreutils "debug"))
1249 (list (call-with-values (lambda ()
1250 (specification->package+output "coreutils"))
1251 list)
1252 (call-with-values (lambda ()
1253 (specification->package+output "coreutils:debug"))
1254 list)))
1255
1256(test-equal "specification->package+output invalid output"
1257 'error
1258 (catch 'quit
1259 (lambda ()
1260 (specification->package+output "coreutils:does-not-exist"))
1261 (lambda _
1262 'error)))
1263
1264(test-equal "specification->package+output no default output"
1265 `(,coreutils #f)
1266 (call-with-values
1267 (lambda ()
1268 (specification->package+output "coreutils" #f))
1269 list))
1270
1271(test-equal "specification->package+output invalid output, no default"
1272 'error
1273 (catch 'quit
1274 (lambda ()
1275 (specification->package+output "coreutils:does-not-exist" #f))
1276 (lambda _
1277 'error)))
1278
ee8099f5
LC
1279(test-equal "find-package-locations"
1280 (map (lambda (package)
1281 (cons (package-version package)
1282 (package-location package)))
1283 (find-packages-by-name "guile"))
1284 (find-package-locations "guile"))
1285
1286(test-equal "find-package-locations with cache"
1287 (map (lambda (package)
1288 (cons (package-version package)
1289 (package-location package)))
1290 (find-packages-by-name "guile"))
1291 (call-with-temporary-directory
1292 (lambda (cache)
1293 (generate-package-cache cache)
1294 (mock ((guix describe) current-profile (const cache))
1295 (mock ((gnu packages) cache-is-authoritative? (const #t))
1296 (find-package-locations "guile"))))))
1297
1298(test-equal "specification->location"
1299 (package-location (specification->package "guile@2"))
1300 (specification->location "guile@2"))
1301
e3ce5d70
LC
1302(test-end "packages")
1303
e3ce5d70 1304;;; Local Variables:
a3d73f59 1305;;; eval: (put 'dummy-package 'scheme-indent-function 1)
3e223a22 1306;;; eval: (put 'dummy-package/no-implicit 'scheme-indent-function 1)
e3ce5d70 1307;;; End: