gnu: Fix typo in description of xfce-desktop-service.
[jackhill/guix/guix.git] / tests / packages.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
7adf9b84 2;;; Copyright © 2012, 2013, 2014, 2015, 2016 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)
fcadd9ff 23 #:use-module (guix grafts)
da675305 24 #:use-module ((guix gexp) #:select (local-file local-file-file))
2e1bafb0
LC
25 #:use-module ((guix utils)
26 ;; Rename the 'location' binding to allow proper syntax
27 ;; matching when setting the 'location' field of a package.
28 #:renamer (lambda (name)
29 (cond ((eq? name 'location) 'make-location)
30 (else name))))
f9cc8971 31 #:use-module (guix hash)
e3ce5d70
LC
32 #:use-module (guix derivations)
33 #:use-module (guix packages)
7adf9b84 34 #:use-module (guix grafts)
aa8e0515 35 #:use-module (guix search-paths)
a18eda27 36 #:use-module (guix build-system)
be13fbfa 37 #:use-module (guix build-system trivial)
a3d73f59 38 #:use-module (guix build-system gnu)
cf81a236
LC
39 #:use-module (guix profiles)
40 #:use-module (guix scripts package)
59a43334 41 #:use-module (gnu packages)
1ffa7090 42 #:use-module (gnu packages base)
05962f29 43 #:use-module (gnu packages guile)
1ffa7090 44 #:use-module (gnu packages bootstrap)
cf81a236 45 #:use-module (gnu packages xml)
05962f29 46 #:use-module (srfi srfi-1)
6b1891b0 47 #:use-module (srfi srfi-26)
9b222abe 48 #:use-module (srfi srfi-34)
dbab5150 49 #:use-module (srfi srfi-35)
6b1891b0 50 #:use-module (srfi srfi-64)
860a6f1a 51 #:use-module (rnrs io ports)
2e1bafb0 52 #:use-module (ice-9 regex)
6b1891b0 53 #:use-module (ice-9 match))
e3ce5d70
LC
54
55;; Test the high-level packaging layer.
56
57(define %store
c1bc358f 58 (open-connection-for-tests))
e3ce5d70 59
b4c42a4b
LC
60;; Globally disable grafting to avoid rebuilding the world ('graft-derivation'
61;; can trigger builds early.)
62(%graft? #f)
63
05962f29
LC
64\f
65(test-begin "packages")
66
2e1bafb0 67(test-assert "printer with location"
74e667d1 68 (string-match "^#<package foo@0 foo.scm:42 [[:xdigit:]]+>$"
2e1bafb0
LC
69 (with-output-to-string
70 (lambda ()
71 (write
72 (dummy-package "foo"
73 (location (make-location "foo.scm" 42 7))))))))
74
75(test-assert "printer without location"
74e667d1 76 (string-match "^#<package foo@0 [[:xdigit:]]+>$"
2e1bafb0
LC
77 (with-output-to-string
78 (lambda ()
79 (write
80 (dummy-package "foo" (location #f)))))))
81
6980511b
LC
82(test-assert "hidden-package"
83 (and (hidden-package? (hidden-package (dummy-package "foo")))
84 (not (hidden-package? (dummy-package "foo")))))
85
d66c7096
LC
86(test-assert "package-field-location"
87 (let ()
88 (define (goto port line column)
89 (unless (and (= (port-column port) (- column 1))
90 (= (port-line port) (- line 1)))
91 (unless (eof-object? (get-char port))
92 (goto port line column))))
93
94 (define read-at
95 (match-lambda
96 (($ <location> file line column)
97 (call-with-input-file (search-path %load-path file)
98 (lambda (port)
99 (goto port line column)
100 (read port))))))
101
ee48b283
LC
102 ;; Until Guile 2.0.6 included, source properties were added only to pairs.
103 ;; Thus, check against both VALUE and (FIELD VALUE).
104 (and (member (read-at (package-field-location %bootstrap-guile 'name))
105 (let ((name (package-name %bootstrap-guile)))
106 (list name `(name ,name))))
107 (member (read-at (package-field-location %bootstrap-guile 'version))
108 (let ((version (package-version %bootstrap-guile)))
109 (list version `(version ,version))))
f903dc05 110 (not (package-field-location %bootstrap-guile 'does-not-exist)))))
d66c7096 111
0b8749b7
LC
112;; Make sure we don't change the file name to an absolute file name.
113(test-equal "package-field-location, relative file name"
114 (location-file (package-location %bootstrap-guile))
115 (with-fluids ((%file-port-name-canonicalization 'absolute))
116 (location-file (package-field-location %bootstrap-guile 'version))))
117
a3d73f59
LC
118(test-assert "package-transitive-inputs"
119 (let* ((a (dummy-package "a"))
120 (b (dummy-package "b"
121 (propagated-inputs `(("a" ,a)))))
122 (c (dummy-package "c"
123 (inputs `(("a" ,a)))))
124 (d (dummy-package "d"
125 (propagated-inputs `(("x" "something.drv")))))
126 (e (dummy-package "e"
127 (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
128 (and (null? (package-transitive-inputs a))
129 (equal? `(("a" ,a)) (package-transitive-inputs b))
130 (equal? `(("a" ,a)) (package-transitive-inputs c))
131 (equal? (package-propagated-inputs d)
132 (package-transitive-inputs d))
161094c8
LC
133 (equal? `(("b" ,b) ("c" ,c) ("d" ,d)
134 ("a" ,a) ("x" "something.drv"))
a3d73f59
LC
135 (pk 'x (package-transitive-inputs e))))))
136
161094c8
LC
137(test-assert "package-transitive-inputs, no duplicates"
138 (let* ((a (dummy-package "a"))
139 (b (dummy-package "b"
140 (inputs `(("a+" ,a)))
141 (native-inputs `(("a*" ,a)))
142 (propagated-inputs `(("a" ,a)))))
143 (c (dummy-package "c"
144 (propagated-inputs `(("b" ,b)))))
145 (d (dummy-package "d"
146 (inputs `(("a" ,a) ("c" ,c)))))
147 (e (dummy-package "e"
148 (inputs `(("b" ,b) ("c" ,c))))))
149 (and (null? (package-transitive-inputs a))
150 (equal? `(("a*" ,a) ("a+" ,a) ("a" ,a)) ;here duplicates are kept
151 (package-transitive-inputs b))
152 (equal? `(("b" ,b) ("a" ,a))
153 (package-transitive-inputs c))
154 (equal? `(("a" ,a) ("c" ,c) ("b" ,b)) ;duplicate A removed
155 (package-transitive-inputs d))
156 (equal? `(("b" ,b) ("c" ,c) ("a" ,a))
157 (package-transitive-inputs e))))) ;ditto
158
7c3c0374 159(test-equal "package-transitive-supported-systems"
c37a74bd
LC
160 '(("x" "y" "z") ;a
161 ("x" "y") ;b
162 ("y") ;c
163 ("y") ;d
164 ("y")) ;e
9bf3ced0
LC
165 ;; Use TRIVIAL-BUILD-SYSTEM because it doesn't add implicit inputs and thus
166 ;; doesn't restrict the set of supported systems.
167 (let* ((a (dummy-package "a"
168 (build-system trivial-build-system)
169 (supported-systems '("x" "y" "z"))))
170 (b (dummy-package "b"
171 (build-system trivial-build-system)
172 (supported-systems '("x" "y"))
173 (inputs `(("a" ,a)))))
174 (c (dummy-package "c"
175 (build-system trivial-build-system)
176 (supported-systems '("y" "z"))
177 (inputs `(("b" ,b)))))
178 (d (dummy-package "d"
179 (build-system trivial-build-system)
180 (supported-systems '("x" "y" "z"))
181 (inputs `(("b" ,b) ("c" ,c)))))
182 (e (dummy-package "e"
183 (build-system trivial-build-system)
184 (supported-systems '("x" "y" "z"))
185 (inputs `(("d" ,d))))))
7c3c0374
LC
186 (list (package-transitive-supported-systems a)
187 (package-transitive-supported-systems b)
c37a74bd
LC
188 (package-transitive-supported-systems c)
189 (package-transitive-supported-systems d)
190 (package-transitive-supported-systems e))))
7c3c0374 191
3b4d0103
EB
192(test-equal "origin-actual-file-name"
193 "foo-1.tar.gz"
194 (let ((o (dummy-origin (uri "http://www.example.com/foo-1.tar.gz"))))
195 (origin-actual-file-name o)))
196
197(test-equal "origin-actual-file-name, file-name"
198 "foo-1.tar.gz"
199 (let ((o (dummy-origin
200 (uri "http://www.example.com/tarball")
201 (file-name "foo-1.tar.gz"))))
202 (origin-actual-file-name o)))
203
f77bcbc3
EB
204(let* ((o (dummy-origin))
205 (u (dummy-origin))
206 (i (dummy-origin))
207 (a (dummy-package "a"))
208 (b (dummy-package "b"
209 (inputs `(("a" ,a) ("i" ,i)))))
210 (c (package (inherit b) (source o)))
211 (d (dummy-package "d"
212 (build-system trivial-build-system)
213 (source u) (inputs `(("c" ,c))))))
214 (test-assert "package-direct-sources, no source"
215 (null? (package-direct-sources a)))
216 (test-equal "package-direct-sources, #f source"
217 (list i)
218 (package-direct-sources b))
219 (test-equal "package-direct-sources, not input source"
220 (list u)
221 (package-direct-sources d))
222 (test-assert "package-direct-sources"
223 (let ((s (package-direct-sources c)))
224 (and (= (length (pk 's-sources s)) 2)
225 (member o s)
226 (member i s))))
227 (test-assert "package-transitive-sources"
228 (let ((s (package-transitive-sources d)))
229 (and (= (length (pk 'd-sources s)) 3)
230 (member o s)
231 (member i s)
232 (member u s)))))
233
a6d0b306
EB
234(test-assert "transitive-input-references"
235 (let* ((a (dummy-package "a"))
236 (b (dummy-package "b"))
237 (c (dummy-package "c"
238 (inputs `(("a" ,a)))
239 (propagated-inputs `(("boo" ,b)))))
240 (d (dummy-package "d"
241 (inputs `(("c*" ,c)))))
242 (keys (map (match-lambda
243 (('assoc-ref 'l key)
244 key))
245 (pk 'refs (transitive-input-references
246 'l (package-inputs d))))))
247 (and (= (length keys) 2)
248 (member "c*" keys)
249 (member "boo" keys))))
250
9bf3ced0
LC
251(test-equal "package-transitive-supported-systems, implicit inputs"
252 %supported-systems
253
254 ;; Here GNU-BUILD-SYSTEM adds implicit inputs that build only on
255 ;; %SUPPORTED-SYSTEMS. Thus the others must be ignored.
256 (let ((p (dummy-package "foo"
257 (build-system gnu-build-system)
258 (supported-systems
259 `("does-not-exist" "foobar" ,@%supported-systems)))))
260 (package-transitive-supported-systems p)))
261
bbceb0ef
LC
262(test-assert "supported-package?"
263 (let ((p (dummy-package "foo"
264 (build-system gnu-build-system)
265 (supported-systems '("x86_64-linux" "does-not-exist")))))
266 (and (supported-package? p "x86_64-linux")
267 (not (supported-package? p "does-not-exist"))
268 (not (supported-package? p "i686-linux")))))
269
7357138b
LC
270(test-skip (if (not %store) 8 0))
271
272(test-assert "package-source-derivation, file"
273 (let* ((file (search-path %load-path "guix.scm"))
274 (package (package (inherit (dummy-package "p"))
275 (source file)))
276 (source (package-source-derivation %store
277 (package-source package))))
278 (and (store-path? source)
279 (valid-path? %store source)
280 (equal? (call-with-input-file source get-bytevector-all)
281 (call-with-input-file file get-bytevector-all)))))
282
283(test-assert "package-source-derivation, store path"
284 (let* ((file (add-to-store %store "guix.scm" #t "sha256"
285 (search-path %load-path "guix.scm")))
286 (package (package (inherit (dummy-package "p"))
287 (source file)))
288 (source (package-source-derivation %store
289 (package-source package))))
290 (string=? file source)))
e509d152 291
f80594cc
LC
292(test-assert "package-source-derivation, indirect store path"
293 (let* ((dir (add-to-store %store "guix-build" #t "sha256"
294 (dirname (search-path %load-path
295 "guix/build/utils.scm"))))
296 (package (package (inherit (dummy-package "p"))
297 (source (string-append dir "/utils.scm"))))
298 (source (package-source-derivation %store
299 (package-source package))))
300 (and (direct-store-path? source)
301 (string-suffix? "utils.scm" source))))
302
da675305
LC
303(test-assert "package-source-derivation, local-file"
304 (let* ((file (local-file "../guix/base32.scm"))
305 (package (package (inherit (dummy-package "p"))
306 (source file)))
307 (source (package-source-derivation %store
308 (package-source package))))
309 (and (store-path? source)
310 (string-suffix? "base32.scm" source)
311 (valid-path? %store source)
312 (equal? (call-with-input-file source get-bytevector-all)
313 (call-with-input-file
314 (search-path %load-path "guix/base32.scm")
315 get-bytevector-all)))))
316
12d720fd 317(unless (network-reachable?) (test-skip 1))
f9cc8971
LC
318(test-equal "package-source-derivation, snippet"
319 "OK"
5cfc17cb
MW
320 (let* ((file (search-bootstrap-binary (match (%current-system)
321 ("armhf-linux"
322 "guile-2.0.11.tar.xz")
323 (_
324 "guile-2.0.9.tar.xz"))
f9cc8971
LC
325 (%current-system)))
326 (sha256 (call-with-input-file file port-sha256))
f220a838 327 (fetch (lambda* (url hash-algo hash
f9cc8971
LC
328 #:optional name #:key system)
329 (pk 'fetch url hash-algo hash name system)
f220a838 330 (interned-file url)))
f9cc8971
LC
331 (source (bootstrap-origin
332 (origin
333 (method fetch)
334 (uri file)
335 (sha256 sha256)
336 (patch-inputs
337 `(("tar" ,%bootstrap-coreutils&co)
338 ("xz" ,%bootstrap-coreutils&co)
339 ("patch" ,%bootstrap-coreutils&co)))
7db9608d 340 (patch-guile %bootstrap-guile)
f9cc8971 341 (modules '((guix build utils)))
f9cc8971
LC
342 (snippet '(begin
343 ;; We end up in 'bin', because it's the first
344 ;; directory, alphabetically. Not a very good
345 ;; example but hey.
346 (chmod "." #o777)
347 (symlink "guile" "guile-rocks")
348 (copy-recursively "../share/guile/2.0/scripts"
d6445dff
LC
349 "scripts")
350
351 ;; Make sure '.file_list' can be created.
352 (chmod ".." #o777))))))
f9cc8971
LC
353 (package (package (inherit (dummy-package "with-snippet"))
354 (source source)
355 (build-system trivial-build-system)
356 (inputs
357 `(("tar" ,(search-bootstrap-binary "tar"
358 (%current-system)))
359 ("xz" ,(search-bootstrap-binary "xz"
360 (%current-system)))))
361 (arguments
362 `(#:guile ,%bootstrap-guile
363 #:builder
364 (let ((tar (assoc-ref %build-inputs "tar"))
365 (xz (assoc-ref %build-inputs "xz"))
366 (source (assoc-ref %build-inputs "source")))
367 (and (zero? (system* tar "xvf" source
368 "--use-compress-program" xz))
369 (string=? "guile" (readlink "bin/guile-rocks"))
370 (file-exists? "bin/scripts/compile.scm")
371 (let ((out (assoc-ref %outputs "out")))
372 (call-with-output-file out
373 (lambda (p)
374 (display "OK" p))))))))))
375 (drv (package-derivation %store package))
376 (out (derivation->output-path drv)))
377 (and (build-derivations %store (list (pk 'snippet-drv drv)))
378 (call-with-input-file out get-string-all))))
379
59688fc4
LC
380(test-assert "return value"
381 (let ((drv (package-derivation %store (dummy-package "p"))))
382 (and (derivation? drv)
383 (file-exists? (derivation-file-name drv)))))
be13fbfa 384
d510ab46
LC
385(test-assert "package-output"
386 (let* ((package (dummy-package "p"))
59688fc4
LC
387 (drv (package-derivation %store package)))
388 (and (derivation? drv)
389 (string=? (derivation->output-path drv)
d510ab46
LC
390 (package-output %store package "out")))))
391
dbab5150
LC
392(test-assert "patch not found yields a run-time error"
393 (guard (c ((condition-has-type? c &message)
394 (and (string-contains (condition-message c)
395 "does-not-exist.patch")
396 (string-contains (condition-message c)
397 "not found"))))
398 (let ((p (package
399 (inherit (dummy-package "p"))
400 (source (origin
401 (method (const #f))
402 (uri "http://whatever")
403 (patches
404 (list (search-patch "does-not-exist.patch")))
405 (sha256
406 (base32
407 "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks4")))))))
408 (package-derivation %store p)
409 #f)))
410
f304c9c2
LC
411(test-assert "reference to non-existent output"
412 ;; See <http://bugs.gnu.org/19630>.
862abf8f
LC
413 (parameterize ((%graft? #f))
414 (let* ((dep (dummy-package "dep"))
415 (p (dummy-package "p"
416 (inputs `(("dep" ,dep "non-existent"))))))
417 (guard (c ((derivation-missing-output-error? c)
418 (and (string=? (derivation-missing-output c) "non-existent")
419 (equal? (package-derivation %store dep)
420 (derivation-error-derivation c)))))
421 (package-derivation %store p)))))
f304c9c2 422
be13fbfa
LC
423(test-assert "trivial"
424 (let* ((p (package (inherit (dummy-package "trivial"))
425 (build-system trivial-build-system)
426 (source #f)
427 (arguments
14da91e2
LC
428 `(#:guile ,%bootstrap-guile
429 #:builder
be13fbfa
LC
430 (begin
431 (mkdir %output)
432 (call-with-output-file (string-append %output "/test")
433 (lambda (p)
434 (display '(hello guix) p))))))))
435 (d (package-derivation %store p)))
436 (and (build-derivations %store (list d))
59688fc4 437 (let ((p (pk 'drv d (derivation->output-path d))))
be13fbfa
LC
438 (equal? '(hello guix)
439 (call-with-input-file (string-append p "/test") read))))))
e3ce5d70 440
860a6f1a
LC
441(test-assert "trivial with local file as input"
442 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
443 (p (package (inherit (dummy-package "trivial-with-input-file"))
444 (build-system trivial-build-system)
445 (source #f)
446 (arguments
447 `(#:guile ,%bootstrap-guile
448 #:builder (copy-file (assoc-ref %build-inputs "input")
449 %output)))
450 (inputs `(("input" ,i)))))
451 (d (package-derivation %store p)))
452 (and (build-derivations %store (list d))
59688fc4 453 (let ((p (pk 'drv d (derivation->output-path d))))
860a6f1a
LC
454 (equal? (call-with-input-file p get-bytevector-all)
455 (call-with-input-file i get-bytevector-all))))))
456
03761a44
LC
457(test-assert "trivial with source"
458 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
459 (p (package (inherit (dummy-package "trivial-with-source"))
460 (build-system trivial-build-system)
461 (source i)
462 (arguments
463 `(#:guile ,%bootstrap-guile
464 #:builder (copy-file (assoc-ref %build-inputs "source")
465 %output)))))
466 (d (package-derivation %store p)))
467 (and (build-derivations %store (list d))
468 (let ((p (derivation->output-path d)))
469 (equal? (call-with-input-file p get-bytevector-all)
470 (call-with-input-file i get-bytevector-all))))))
471
592ef6c8
LC
472(test-assert "trivial with system-dependent input"
473 (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
474 (build-system trivial-build-system)
475 (source #f)
476 (arguments
477 `(#:guile ,%bootstrap-guile
478 #:builder
479 (let ((out (assoc-ref %outputs "out"))
480 (bash (assoc-ref %build-inputs "bash")))
481 (zero? (system* bash "-c"
482 (format #f "echo hello > ~a" out))))))
dd6b9a37
LC
483 (inputs `(("bash" ,(search-bootstrap-binary "bash"
484 (%current-system)))))))
592ef6c8
LC
485 (d (package-derivation %store p)))
486 (and (build-derivations %store (list d))
59688fc4 487 (let ((p (pk 'drv d (derivation->output-path d))))
592ef6c8
LC
488 (eq? 'hello (call-with-input-file p read))))))
489
a18eda27
LC
490(test-assert "search paths"
491 (let* ((p (make-prompt-tag "return-search-paths"))
492 (s (build-system
0d5a559f 493 (name 'raw)
a18eda27 494 (description "Raw build system with direct store access")
d3d337d2
LC
495 (lower (lambda* (name #:key source inputs system target
496 #:allow-other-keys)
0d5a559f
LC
497 (bag
498 (name name)
d3d337d2 499 (system system) (target target)
0d5a559f
LC
500 (build-inputs inputs)
501 (build
502 (lambda* (store name inputs
503 #:key outputs system search-paths)
504 search-paths)))))))
a18eda27
LC
505 (x (list (search-path-specification
506 (variable "GUILE_LOAD_PATH")
af070955 507 (files '("share/guile/site/2.0")))
a18eda27
LC
508 (search-path-specification
509 (variable "GUILE_LOAD_COMPILED_PATH")
af070955 510 (files '("share/guile/site/2.0")))))
a18eda27
LC
511 (a (package (inherit (dummy-package "guile"))
512 (build-system s)
513 (native-search-paths x)))
514 (b (package (inherit (dummy-package "guile-foo"))
515 (build-system s)
516 (inputs `(("guile" ,a)))))
517 (c (package (inherit (dummy-package "guile-bar"))
518 (build-system s)
519 (inputs `(("guile" ,a)
520 ("guile-foo" ,b))))))
521 (let-syntax ((collect (syntax-rules ()
522 ((_ body ...)
523 (call-with-prompt p
524 (lambda ()
525 body ...)
526 (lambda (k search-paths)
527 search-paths))))))
528 (and (null? (collect (package-derivation %store a)))
529 (equal? x (collect (package-derivation %store b)))
530 (equal? x (collect (package-derivation %store c)))))))
531
aa8e0515
LC
532(test-assert "package-transitive-native-search-paths"
533 (let* ((sp (lambda (name)
534 (list (search-path-specification
535 (variable name)
536 (files '("foo/bar"))))))
537 (p0 (dummy-package "p0" (native-search-paths (sp "PATH0"))))
538 (p1 (dummy-package "p1" (native-search-paths (sp "PATH1"))))
539 (p2 (dummy-package "p2"
540 (native-search-paths (sp "PATH2"))
541 (inputs `(("p0" ,p0)))
542 (propagated-inputs `(("p1" ,p1)))))
543 (p3 (dummy-package "p3"
544 (native-search-paths (sp "PATH3"))
545 (native-inputs `(("p0" ,p0)))
546 (propagated-inputs `(("p2" ,p2))))))
547 (lset= string=?
548 '("PATH1" "PATH2" "PATH3")
549 (map search-path-specification-variable
550 (package-transitive-native-search-paths p3)))))
551
9c1edabd 552(test-assert "package-cross-derivation"
59688fc4
LC
553 (let ((drv (package-cross-derivation %store (dummy-package "p")
554 "mips64el-linux-gnu")))
555 (and (derivation? drv)
556 (file-exists? (derivation-file-name drv)))))
9c1edabd 557
5dce8218
LC
558(test-assert "package-cross-derivation, trivial-build-system"
559 (let ((p (package (inherit (dummy-package "p"))
560 (build-system trivial-build-system)
561 (arguments '(#:builder (exit 1))))))
59688fc4
LC
562 (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu")))
563 (derivation? drv))))
5dce8218 564
9b222abe
LC
565(test-assert "package-cross-derivation, no cross builder"
566 (let* ((b (build-system (inherit trivial-build-system)
0d5a559f 567 (lower (const #f))))
9b222abe
LC
568 (p (package (inherit (dummy-package "p"))
569 (build-system b))))
570 (guard (c ((package-cross-build-system-error? c)
571 (eq? (package-error-package c) p)))
572 (package-cross-derivation %store p "mips64el-linux-gnu")
573 #f)))
574
b4c42a4b
LC
575;; XXX: The next two tests can trigger builds when the distro defines
576;; replacements on core packages, so they're disable for lack of a better
577;; solution.
578
579;; (test-equal "package-derivation, direct graft"
580;; (package-derivation %store gnu-make #:graft? #f)
581;; (let ((p (package (inherit coreutils)
582;; (replacement gnu-make))))
583;; (package-derivation %store p #:graft? #t)))
05962f29 584
b4c42a4b
LC
585;; (test-equal "package-cross-derivation, direct graft"
586;; (package-cross-derivation %store gnu-make "mips64el-linux-gnu"
587;; #:graft? #f)
588;; (let ((p (package (inherit coreutils)
589;; (replacement gnu-make))))
590;; (package-cross-derivation %store p "mips64el-linux-gnu"
591;; #:graft? #t)))
05962f29
LC
592
593(test-assert "package-grafts, indirect grafts"
594 (let* ((new (dummy-package "dep"
595 (arguments '(#:implicit-inputs? #f))))
596 (dep (package (inherit new) (version "0.0")))
597 (dep* (package (inherit dep) (replacement new)))
598 (dummy (dummy-package "dummy"
599 (arguments '(#:implicit-inputs? #f))
600 (inputs `(("dep" ,dep*))))))
601 (equal? (package-grafts %store dummy)
602 (list (graft
603 (origin (package-derivation %store dep))
604 (replacement (package-derivation %store new)))))))
605
606(test-assert "package-grafts, indirect grafts, cross"
607 (let* ((new (dummy-package "dep"
608 (arguments '(#:implicit-inputs? #f))))
609 (dep (package (inherit new) (version "0.0")))
610 (dep* (package (inherit dep) (replacement new)))
611 (dummy (dummy-package "dummy"
612 (arguments '(#:implicit-inputs? #f))
613 (inputs `(("dep" ,dep*)))))
614 (target "mips64el-linux-gnu"))
b4c42a4b
LC
615 ;; XXX: There might be additional grafts, for instance if the distro
616 ;; defines replacements for core packages like Perl.
617 (member (graft
618 (origin (package-cross-derivation %store dep target))
619 (replacement
620 (package-cross-derivation %store new target)))
621 (package-grafts %store dummy #:target target))))
05962f29
LC
622
623(test-assert "package-grafts, indirect grafts, propagated inputs"
624 (let* ((new (dummy-package "dep"
625 (arguments '(#:implicit-inputs? #f))))
626 (dep (package (inherit new) (version "0.0")))
627 (dep* (package (inherit dep) (replacement new)))
628 (prop (dummy-package "propagated"
629 (propagated-inputs `(("dep" ,dep*)))
630 (arguments '(#:implicit-inputs? #f))))
631 (dummy (dummy-package "dummy"
632 (arguments '(#:implicit-inputs? #f))
633 (inputs `(("prop" ,prop))))))
634 (equal? (package-grafts %store dummy)
635 (list (graft
636 (origin (package-derivation %store dep))
637 (replacement (package-derivation %store new)))))))
638
fcadd9ff
LC
639(test-assert "package-grafts, same replacement twice"
640 (let* ((new (dummy-package "dep"
641 (version "1")
642 (arguments '(#:implicit-inputs? #f))))
643 (dep (package (inherit new) (version "0") (replacement new)))
644 (p1 (dummy-package "intermediate1"
645 (arguments '(#:implicit-inputs? #f))
646 (inputs `(("dep" ,dep)))))
647 (p2 (dummy-package "intermediate2"
648 (arguments '(#:implicit-inputs? #f))
649 ;; Here we copy DEP to have an equivalent package that is not
650 ;; 'eq?' to DEP. This is similar to what happens with
651 ;; 'package-with-explicit-inputs' & co.
652 (inputs `(("dep" ,(package (inherit dep)))))))
653 (p3 (dummy-package "final"
654 (arguments '(#:implicit-inputs? #f))
655 (inputs `(("p1" ,p1) ("p2" ,p2))))))
656 (equal? (package-grafts %store p3)
657 (list (graft
658 (origin (package-derivation %store
659 (package (inherit dep)
660 (replacement #f))))
661 (replacement (package-derivation %store new)))))))
662
c22a1324
LC
663;;; XXX: Nowadays 'graft-derivation' needs to build derivations beforehand to
664;;; find out about their run-time dependencies, so this test is no longer
665;;; applicable since it would trigger a full rebuild.
666;;
667;; (test-assert "package-derivation, indirect grafts"
668;; (let* ((new (dummy-package "dep"
669;; (arguments '(#:implicit-inputs? #f))))
670;; (dep (package (inherit new) (version "0.0")))
671;; (dep* (package (inherit dep) (replacement new)))
672;; (dummy (dummy-package "dummy"
673;; (arguments '(#:implicit-inputs? #f))
674;; (inputs `(("dep" ,dep*)))))
675;; (guile (package-derivation %store (canonical-package guile-2.0)
676;; #:graft? #f)))
677;; (equal? (package-derivation %store dummy)
678;; (graft-derivation %store
679;; (package-derivation %store dummy #:graft? #f)
680;; (package-grafts %store dummy)
681
682;; ;; Use the same Guile as 'package-derivation'.
683;; #:guile guile))))
05962f29 684
d3d337d2
LC
685(test-equal "package->bag"
686 `("foo86-hurd" #f (,(package-source gnu-make))
687 (,(canonical-package glibc)) (,(canonical-package coreutils)))
688 (let ((bag (package->bag gnu-make "foo86-hurd")))
689 (list (bag-system bag) (bag-target bag)
690 (assoc-ref (bag-build-inputs bag) "source")
691 (assoc-ref (bag-build-inputs bag) "libc")
692 (assoc-ref (bag-build-inputs bag) "coreutils"))))
693
694(test-equal "package->bag, cross-compilation"
695 `(,(%current-system) "foo86-hurd"
696 (,(package-source gnu-make))
697 (,(canonical-package glibc)) (,(canonical-package coreutils)))
698 (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd")))
699 (list (bag-system bag) (bag-target bag)
700 (assoc-ref (bag-build-inputs bag) "source")
701 (assoc-ref (bag-build-inputs bag) "libc")
702 (assoc-ref (bag-build-inputs bag) "coreutils"))))
703
50373bab
LC
704(test-assert "package->bag, propagated inputs"
705 (let* ((dep (dummy-package "dep"))
706 (prop (dummy-package "prop"
707 (propagated-inputs `(("dep" ,dep)))))
708 (dummy (dummy-package "dummy"
709 (inputs `(("prop" ,prop)))))
710 (inputs (bag-transitive-inputs (package->bag dummy #:graft? #f))))
161094c8
LC
711 (match (assoc "dep" inputs)
712 (("dep" package)
50373bab
LC
713 (eq? package dep)))))
714
d3d337d2 715(test-assert "bag->derivation"
05962f29
LC
716 (parameterize ((%graft? #f))
717 (let ((bag (package->bag gnu-make))
718 (drv (package-derivation %store gnu-make)))
719 (parameterize ((%current-system "foox86-hurd")) ;should have no effect
720 (equal? drv (bag->derivation %store bag))))))
d3d337d2
LC
721
722(test-assert "bag->derivation, cross-compilation"
05962f29
LC
723 (parameterize ((%graft? #f))
724 (let* ((target "mips64el-linux-gnu")
725 (bag (package->bag gnu-make (%current-system) target))
726 (drv (package-cross-derivation %store gnu-make target)))
727 (parameterize ((%current-system "foox86-hurd") ;should have no effect
728 (%current-target-system "foo64-linux-gnu"))
729 (equal? drv (bag->derivation %store bag))))))
d3d337d2 730
b69c5c2c
LC
731(when (or (not (network-reachable?)) (shebang-too-long?))
732 (test-skip 1))
9e782349
LC
733(test-assert "GNU Make, bootstrap"
734 ;; GNU Make is the first program built during bootstrap; we choose it
735 ;; here so that the test doesn't last for too long.
bdb36958 736 (let ((gnu-make (@@ (gnu packages commencement) gnu-make-boot0)))
9e782349
LC
737 (and (package? gnu-make)
738 (or (location? (package-location gnu-make))
739 (not (package-location gnu-make)))
740 (let* ((drv (package-derivation %store gnu-make))
59688fc4 741 (out (derivation->output-path drv)))
14da91e2 742 (and (build-derivations %store (list drv))
9e782349 743 (file-exists? (string-append out "/bin/make")))))))
e3ce5d70 744
ba326ce4
LC
745(test-eq "fold-packages" hello
746 (fold-packages (lambda (p r)
747 (if (string=? (package-name p) "hello")
748 p
749 r))
750 #f))
751
386b71d1
LC
752(test-assert "fold-packages, hidden package"
753 ;; There are two public variables providing "guile@2.0" ('guile-final' in
754 ;; commencement.scm and 'guile-2.0/fixed' in guile.scm), but only the latter
755 ;; should show up.
756 (match (fold-packages (lambda (p r)
757 (if (and (string=? (package-name p) "guile")
758 (string-prefix? "2.0"
759 (package-version p)))
760 (cons p r)
761 r))
762 '())
763 ((one)
764 (eq? one guile-2.0/fixed))))
765
6b1891b0
LC
766(test-assert "find-packages-by-name"
767 (match (find-packages-by-name "hello")
768 (((? (cut eq? hello <>))) #t)
769 (wrong (pk 'find-packages-by-name wrong #f))))
770
771(test-assert "find-packages-by-name with version"
772 (match (find-packages-by-name "hello" (package-version hello))
773 (((? (cut eq? hello <>))) #t)
774 (wrong (pk 'find-packages-by-name wrong #f))))
775
cf81a236
LC
776(test-assert "--search-paths with pattern"
777 ;; Make sure 'guix package --search-paths' correctly reports environment
778 ;; variables when file patterns are used (in particular, it must follow
779 ;; symlinks when looking for 'catalog.xml'.) To do that, we rely on the
780 ;; libxml2 package specification, which contains such a definition.
781 (let* ((p1 (package
782 (name "foo") (version "0") (source #f)
783 (build-system trivial-build-system)
784 (arguments
785 `(#:guile ,%bootstrap-guile
786 #:modules ((guix build utils))
787 #:builder (begin
788 (use-modules (guix build utils))
789 (let ((out (assoc-ref %outputs "out")))
790 (mkdir-p (string-append out "/xml/bar/baz"))
791 (call-with-output-file
792 (string-append out "/xml/bar/baz/catalog.xml")
793 (lambda (port)
794 (display "xml? wat?!" port)))))))
795 (synopsis #f) (description #f)
796 (home-page #f) (license #f)))
797 (p2 (package
798 ;; Provide a fake libxml2 to avoid building the real one. This
799 ;; is OK because 'guix package' gets search path specifications
800 ;; from the same-named package found in the distro.
801 (name "libxml2") (version "0.0.0") (source #f)
802 (build-system trivial-build-system)
803 (arguments
804 `(#:guile ,%bootstrap-guile
805 #:builder (mkdir (assoc-ref %outputs "out"))))
806 (native-search-paths (package-native-search-paths libxml2))
807 (synopsis #f) (description #f)
808 (home-page #f) (license #f)))
809 (prof (run-with-store %store
810 (profile-derivation
811 (manifest (map package->manifest-entry
812 (list p1 p2)))
aa46a028 813 #:hooks '())
cf81a236
LC
814 #:guile-for-build (%guile-for-build))))
815 (build-derivations %store (list prof))
816 (string-match (format #f "^export XML_CATALOG_FILES=\"~a/xml/+bar/baz/catalog\\.xml\"\n"
77559f23 817 (regexp-quote (derivation->output-path prof)))
cf81a236
LC
818 (with-output-to-string
819 (lambda ()
820 (guix-package "-p" (derivation->output-path prof)
821 "--search-paths"))))))
822
efb107e0
LC
823(test-equal "specification->package when not found"
824 'quit
825 (catch 'quit
826 (lambda ()
827 ;; This should call 'leave', producing an error message.
828 (specification->package "this-package-does-not-exist"))
829 (lambda (key . args)
830 key)))
831
e3ce5d70
LC
832(test-end "packages")
833
e3ce5d70 834;;; Local Variables:
a3d73f59 835;;; eval: (put 'dummy-package 'scheme-indent-function 1)
e3ce5d70 836;;; End: