gnu: valgrind: Don't build on mipsel64-linux.
[jackhill/guix/guix.git] / tests / packages.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
c1bc358f 2;;; Copyright © 2012, 2013, 2014 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)
2e1bafb0
LC
22 #:use-module ((guix utils)
23 ;; Rename the 'location' binding to allow proper syntax
24 ;; matching when setting the 'location' field of a package.
25 #:renamer (lambda (name)
26 (cond ((eq? name 'location) 'make-location)
27 (else name))))
f9cc8971 28 #:use-module (guix hash)
e3ce5d70
LC
29 #:use-module (guix derivations)
30 #:use-module (guix packages)
a18eda27 31 #:use-module (guix build-system)
be13fbfa 32 #:use-module (guix build-system trivial)
a3d73f59 33 #:use-module (guix build-system gnu)
59a43334 34 #:use-module (gnu packages)
1ffa7090
LC
35 #:use-module (gnu packages base)
36 #:use-module (gnu packages bootstrap)
e509d152 37 #:use-module (srfi srfi-11)
6b1891b0 38 #:use-module (srfi srfi-26)
9b222abe 39 #:use-module (srfi srfi-34)
6b1891b0 40 #:use-module (srfi srfi-64)
860a6f1a 41 #:use-module (rnrs io ports)
2e1bafb0 42 #:use-module (ice-9 regex)
6b1891b0 43 #:use-module (ice-9 match))
e3ce5d70
LC
44
45;; Test the high-level packaging layer.
46
47(define %store
c1bc358f 48 (open-connection-for-tests))
e3ce5d70 49
81dbd783 50
14da91e2 51\f
e3ce5d70
LC
52(test-begin "packages")
53
a3d73f59
LC
54(define-syntax-rule (dummy-package name* extra-fields ...)
55 (package (name name*) (version "0") (source #f)
56 (build-system gnu-build-system)
d45122f5 57 (synopsis #f) (description #f)
1fb78cb2 58 (home-page #f) (license #f)
a3d73f59
LC
59 extra-fields ...))
60
2e1bafb0
LC
61(test-assert "printer with location"
62 (string-match "^#<package foo-0 foo.scm:42 [[:xdigit:]]+>$"
63 (with-output-to-string
64 (lambda ()
65 (write
66 (dummy-package "foo"
67 (location (make-location "foo.scm" 42 7))))))))
68
69(test-assert "printer without location"
70 (string-match "^#<package foo-0 [[:xdigit:]]+>$"
71 (with-output-to-string
72 (lambda ()
73 (write
74 (dummy-package "foo" (location #f)))))))
75
d66c7096
LC
76(test-assert "package-field-location"
77 (let ()
78 (define (goto port line column)
79 (unless (and (= (port-column port) (- column 1))
80 (= (port-line port) (- line 1)))
81 (unless (eof-object? (get-char port))
82 (goto port line column))))
83
84 (define read-at
85 (match-lambda
86 (($ <location> file line column)
87 (call-with-input-file (search-path %load-path file)
88 (lambda (port)
89 (goto port line column)
90 (read port))))))
91
ee48b283
LC
92 ;; Until Guile 2.0.6 included, source properties were added only to pairs.
93 ;; Thus, check against both VALUE and (FIELD VALUE).
94 (and (member (read-at (package-field-location %bootstrap-guile 'name))
95 (let ((name (package-name %bootstrap-guile)))
96 (list name `(name ,name))))
97 (member (read-at (package-field-location %bootstrap-guile 'version))
98 (let ((version (package-version %bootstrap-guile)))
99 (list version `(version ,version))))
f903dc05 100 (not (package-field-location %bootstrap-guile 'does-not-exist)))))
d66c7096 101
0b8749b7
LC
102;; Make sure we don't change the file name to an absolute file name.
103(test-equal "package-field-location, relative file name"
104 (location-file (package-location %bootstrap-guile))
105 (with-fluids ((%file-port-name-canonicalization 'absolute))
106 (location-file (package-field-location %bootstrap-guile 'version))))
107
a3d73f59
LC
108(test-assert "package-transitive-inputs"
109 (let* ((a (dummy-package "a"))
110 (b (dummy-package "b"
111 (propagated-inputs `(("a" ,a)))))
112 (c (dummy-package "c"
113 (inputs `(("a" ,a)))))
114 (d (dummy-package "d"
115 (propagated-inputs `(("x" "something.drv")))))
116 (e (dummy-package "e"
117 (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
118 (and (null? (package-transitive-inputs a))
119 (equal? `(("a" ,a)) (package-transitive-inputs b))
120 (equal? `(("a" ,a)) (package-transitive-inputs c))
121 (equal? (package-propagated-inputs d)
122 (package-transitive-inputs d))
123 (equal? `(("b" ,b) ("b/a" ,a) ("c" ,c)
124 ("d" ,d) ("d/x" "something.drv"))
125 (pk 'x (package-transitive-inputs e))))))
126
7357138b
LC
127(test-skip (if (not %store) 8 0))
128
129(test-assert "package-source-derivation, file"
130 (let* ((file (search-path %load-path "guix.scm"))
131 (package (package (inherit (dummy-package "p"))
132 (source file)))
133 (source (package-source-derivation %store
134 (package-source package))))
135 (and (store-path? source)
136 (valid-path? %store source)
137 (equal? (call-with-input-file source get-bytevector-all)
138 (call-with-input-file file get-bytevector-all)))))
139
140(test-assert "package-source-derivation, store path"
141 (let* ((file (add-to-store %store "guix.scm" #t "sha256"
142 (search-path %load-path "guix.scm")))
143 (package (package (inherit (dummy-package "p"))
144 (source file)))
145 (source (package-source-derivation %store
146 (package-source package))))
147 (string=? file source)))
e509d152 148
f80594cc
LC
149(test-assert "package-source-derivation, indirect store path"
150 (let* ((dir (add-to-store %store "guix-build" #t "sha256"
151 (dirname (search-path %load-path
152 "guix/build/utils.scm"))))
153 (package (package (inherit (dummy-package "p"))
154 (source (string-append dir "/utils.scm"))))
155 (source (package-source-derivation %store
156 (package-source package))))
157 (and (direct-store-path? source)
158 (string-suffix? "utils.scm" source))))
159
b29f947d
LC
160(unless (false-if-exception (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV))
161 (test-skip 1))
f9cc8971
LC
162(test-equal "package-source-derivation, snippet"
163 "OK"
127ed6a9 164 (let* ((file (search-bootstrap-binary "guile-2.0.9.tar.xz"
f9cc8971
LC
165 (%current-system)))
166 (sha256 (call-with-input-file file port-sha256))
167 (fetch (lambda* (store url hash-algo hash
168 #:optional name #:key system)
169 (pk 'fetch url hash-algo hash name system)
170 (add-to-store store (basename url) #f "sha256" url)))
171 (source (bootstrap-origin
172 (origin
173 (method fetch)
174 (uri file)
175 (sha256 sha256)
176 (patch-inputs
177 `(("tar" ,%bootstrap-coreutils&co)
178 ("xz" ,%bootstrap-coreutils&co)
179 ("patch" ,%bootstrap-coreutils&co)))
7db9608d 180 (patch-guile %bootstrap-guile)
f9cc8971
LC
181 (modules '((guix build utils)))
182 (imported-modules modules)
183 (snippet '(begin
184 ;; We end up in 'bin', because it's the first
185 ;; directory, alphabetically. Not a very good
186 ;; example but hey.
187 (chmod "." #o777)
188 (symlink "guile" "guile-rocks")
189 (copy-recursively "../share/guile/2.0/scripts"
190 "scripts")
191
192 ;; These variables must exist.
193 (pk %build-inputs %outputs))))))
194 (package (package (inherit (dummy-package "with-snippet"))
195 (source source)
196 (build-system trivial-build-system)
197 (inputs
198 `(("tar" ,(search-bootstrap-binary "tar"
199 (%current-system)))
200 ("xz" ,(search-bootstrap-binary "xz"
201 (%current-system)))))
202 (arguments
203 `(#:guile ,%bootstrap-guile
204 #:builder
205 (let ((tar (assoc-ref %build-inputs "tar"))
206 (xz (assoc-ref %build-inputs "xz"))
207 (source (assoc-ref %build-inputs "source")))
208 (and (zero? (system* tar "xvf" source
209 "--use-compress-program" xz))
210 (string=? "guile" (readlink "bin/guile-rocks"))
211 (file-exists? "bin/scripts/compile.scm")
212 (let ((out (assoc-ref %outputs "out")))
213 (call-with-output-file out
214 (lambda (p)
215 (display "OK" p))))))))))
216 (drv (package-derivation %store package))
217 (out (derivation->output-path drv)))
218 (and (build-derivations %store (list (pk 'snippet-drv drv)))
219 (call-with-input-file out get-string-all))))
220
59688fc4
LC
221(test-assert "return value"
222 (let ((drv (package-derivation %store (dummy-package "p"))))
223 (and (derivation? drv)
224 (file-exists? (derivation-file-name drv)))))
be13fbfa 225
d510ab46
LC
226(test-assert "package-output"
227 (let* ((package (dummy-package "p"))
59688fc4
LC
228 (drv (package-derivation %store package)))
229 (and (derivation? drv)
230 (string=? (derivation->output-path drv)
d510ab46
LC
231 (package-output %store package "out")))))
232
be13fbfa
LC
233(test-assert "trivial"
234 (let* ((p (package (inherit (dummy-package "trivial"))
235 (build-system trivial-build-system)
236 (source #f)
237 (arguments
14da91e2
LC
238 `(#:guile ,%bootstrap-guile
239 #:builder
be13fbfa
LC
240 (begin
241 (mkdir %output)
242 (call-with-output-file (string-append %output "/test")
243 (lambda (p)
244 (display '(hello guix) p))))))))
245 (d (package-derivation %store p)))
246 (and (build-derivations %store (list d))
59688fc4 247 (let ((p (pk 'drv d (derivation->output-path d))))
be13fbfa
LC
248 (equal? '(hello guix)
249 (call-with-input-file (string-append p "/test") read))))))
e3ce5d70 250
860a6f1a
LC
251(test-assert "trivial with local file as input"
252 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
253 (p (package (inherit (dummy-package "trivial-with-input-file"))
254 (build-system trivial-build-system)
255 (source #f)
256 (arguments
257 `(#:guile ,%bootstrap-guile
258 #:builder (copy-file (assoc-ref %build-inputs "input")
259 %output)))
260 (inputs `(("input" ,i)))))
261 (d (package-derivation %store p)))
262 (and (build-derivations %store (list d))
59688fc4 263 (let ((p (pk 'drv d (derivation->output-path d))))
860a6f1a
LC
264 (equal? (call-with-input-file p get-bytevector-all)
265 (call-with-input-file i get-bytevector-all))))))
266
03761a44
LC
267(test-assert "trivial with source"
268 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
269 (p (package (inherit (dummy-package "trivial-with-source"))
270 (build-system trivial-build-system)
271 (source i)
272 (arguments
273 `(#:guile ,%bootstrap-guile
274 #:builder (copy-file (assoc-ref %build-inputs "source")
275 %output)))))
276 (d (package-derivation %store p)))
277 (and (build-derivations %store (list d))
278 (let ((p (derivation->output-path d)))
279 (equal? (call-with-input-file p get-bytevector-all)
280 (call-with-input-file i get-bytevector-all))))))
281
592ef6c8
LC
282(test-assert "trivial with system-dependent input"
283 (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
284 (build-system trivial-build-system)
285 (source #f)
286 (arguments
287 `(#:guile ,%bootstrap-guile
288 #:builder
289 (let ((out (assoc-ref %outputs "out"))
290 (bash (assoc-ref %build-inputs "bash")))
291 (zero? (system* bash "-c"
292 (format #f "echo hello > ~a" out))))))
dd6b9a37
LC
293 (inputs `(("bash" ,(search-bootstrap-binary "bash"
294 (%current-system)))))))
592ef6c8
LC
295 (d (package-derivation %store p)))
296 (and (build-derivations %store (list d))
59688fc4 297 (let ((p (pk 'drv d (derivation->output-path d))))
592ef6c8
LC
298 (eq? 'hello (call-with-input-file p read))))))
299
a18eda27
LC
300(test-assert "search paths"
301 (let* ((p (make-prompt-tag "return-search-paths"))
302 (s (build-system
0d5a559f 303 (name 'raw)
a18eda27 304 (description "Raw build system with direct store access")
d3d337d2
LC
305 (lower (lambda* (name #:key source inputs system target
306 #:allow-other-keys)
0d5a559f
LC
307 (bag
308 (name name)
d3d337d2 309 (system system) (target target)
0d5a559f
LC
310 (build-inputs inputs)
311 (build
312 (lambda* (store name inputs
313 #:key outputs system search-paths)
314 search-paths)))))))
a18eda27
LC
315 (x (list (search-path-specification
316 (variable "GUILE_LOAD_PATH")
317 (directories '("share/guile/site/2.0")))
318 (search-path-specification
319 (variable "GUILE_LOAD_COMPILED_PATH")
320 (directories '("share/guile/site/2.0")))))
321 (a (package (inherit (dummy-package "guile"))
322 (build-system s)
323 (native-search-paths x)))
324 (b (package (inherit (dummy-package "guile-foo"))
325 (build-system s)
326 (inputs `(("guile" ,a)))))
327 (c (package (inherit (dummy-package "guile-bar"))
328 (build-system s)
329 (inputs `(("guile" ,a)
330 ("guile-foo" ,b))))))
331 (let-syntax ((collect (syntax-rules ()
332 ((_ body ...)
333 (call-with-prompt p
334 (lambda ()
335 body ...)
336 (lambda (k search-paths)
337 search-paths))))))
338 (and (null? (collect (package-derivation %store a)))
339 (equal? x (collect (package-derivation %store b)))
340 (equal? x (collect (package-derivation %store c)))))))
341
9c1edabd 342(test-assert "package-cross-derivation"
59688fc4
LC
343 (let ((drv (package-cross-derivation %store (dummy-package "p")
344 "mips64el-linux-gnu")))
345 (and (derivation? drv)
346 (file-exists? (derivation-file-name drv)))))
9c1edabd 347
5dce8218
LC
348(test-assert "package-cross-derivation, trivial-build-system"
349 (let ((p (package (inherit (dummy-package "p"))
350 (build-system trivial-build-system)
351 (arguments '(#:builder (exit 1))))))
59688fc4
LC
352 (let ((drv (package-cross-derivation %store p "mips64el-linux-gnu")))
353 (derivation? drv))))
5dce8218 354
9b222abe
LC
355(test-assert "package-cross-derivation, no cross builder"
356 (let* ((b (build-system (inherit trivial-build-system)
0d5a559f 357 (lower (const #f))))
9b222abe
LC
358 (p (package (inherit (dummy-package "p"))
359 (build-system b))))
360 (guard (c ((package-cross-build-system-error? c)
361 (eq? (package-error-package c) p)))
362 (package-cross-derivation %store p "mips64el-linux-gnu")
363 #f)))
364
d3d337d2
LC
365(test-equal "package->bag"
366 `("foo86-hurd" #f (,(package-source gnu-make))
367 (,(canonical-package glibc)) (,(canonical-package coreutils)))
368 (let ((bag (package->bag gnu-make "foo86-hurd")))
369 (list (bag-system bag) (bag-target bag)
370 (assoc-ref (bag-build-inputs bag) "source")
371 (assoc-ref (bag-build-inputs bag) "libc")
372 (assoc-ref (bag-build-inputs bag) "coreutils"))))
373
374(test-equal "package->bag, cross-compilation"
375 `(,(%current-system) "foo86-hurd"
376 (,(package-source gnu-make))
377 (,(canonical-package glibc)) (,(canonical-package coreutils)))
378 (let ((bag (package->bag gnu-make (%current-system) "foo86-hurd")))
379 (list (bag-system bag) (bag-target bag)
380 (assoc-ref (bag-build-inputs bag) "source")
381 (assoc-ref (bag-build-inputs bag) "libc")
382 (assoc-ref (bag-build-inputs bag) "coreutils"))))
383
384(test-assert "bag->derivation"
385 (let ((bag (package->bag gnu-make))
386 (drv (package-derivation %store gnu-make)))
387 (parameterize ((%current-system "foox86-hurd")) ;should have no effect
388 (equal? drv (bag->derivation %store bag)))))
389
390(test-assert "bag->derivation, cross-compilation"
391 (let ((bag (package->bag gnu-make (%current-system) "mips64el-linux-gnu"))
392 (drv (package-cross-derivation %store gnu-make "mips64el-linux-gnu")))
393 (parameterize ((%current-system "foox86-hurd") ;should have no effect
394 (%current-target-system "foo64-linux-gnu"))
395 (equal? drv (bag->derivation %store bag)))))
396
ad1ebab3
LC
397(unless (false-if-exception (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV))
398 (test-skip 1))
9e782349
LC
399(test-assert "GNU Make, bootstrap"
400 ;; GNU Make is the first program built during bootstrap; we choose it
401 ;; here so that the test doesn't last for too long.
bdb36958 402 (let ((gnu-make (@@ (gnu packages commencement) gnu-make-boot0)))
9e782349
LC
403 (and (package? gnu-make)
404 (or (location? (package-location gnu-make))
405 (not (package-location gnu-make)))
406 (let* ((drv (package-derivation %store gnu-make))
59688fc4 407 (out (derivation->output-path drv)))
14da91e2 408 (and (build-derivations %store (list drv))
9e782349 409 (file-exists? (string-append out "/bin/make")))))))
e3ce5d70 410
ba326ce4
LC
411(test-eq "fold-packages" hello
412 (fold-packages (lambda (p r)
413 (if (string=? (package-name p) "hello")
414 p
415 r))
416 #f))
417
6b1891b0
LC
418(test-assert "find-packages-by-name"
419 (match (find-packages-by-name "hello")
420 (((? (cut eq? hello <>))) #t)
421 (wrong (pk 'find-packages-by-name wrong #f))))
422
423(test-assert "find-packages-by-name with version"
424 (match (find-packages-by-name "hello" (package-version hello))
425 (((? (cut eq? hello <>))) #t)
426 (wrong (pk 'find-packages-by-name wrong #f))))
427
e3ce5d70
LC
428(test-end "packages")
429
430\f
431(exit (= (test-runner-fail-count (test-runner-current)) 0))
432
433;;; Local Variables:
a3d73f59 434;;; eval: (put 'dummy-package 'scheme-indent-function 1)
e3ce5d70 435;;; End: