distro: Change the module name space to (gnu ...).
[jackhill/guix/guix.git] / tests / packages.scm
CommitLineData
233e7676
LC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2012 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
LC
18
19
20(define-module (test-packages)
21 #:use-module (guix store)
22 #:use-module (guix utils)
23 #:use-module (guix derivations)
24 #:use-module (guix packages)
be13fbfa 25 #:use-module (guix build-system trivial)
a3d73f59 26 #:use-module (guix build-system gnu)
6b1891b0 27 #:use-module (distro)
1ffa7090
LC
28 #:use-module (gnu packages base)
29 #:use-module (gnu packages bootstrap)
6b1891b0
LC
30 #:use-module (srfi srfi-26)
31 #:use-module (srfi srfi-64)
860a6f1a 32 #:use-module (rnrs io ports)
6b1891b0 33 #:use-module (ice-9 match))
e3ce5d70
LC
34
35;; Test the high-level packaging layer.
36
37(define %store
38 (false-if-exception (open-connection)))
39
81dbd783
LC
40(when %store
41 ;; Make sure we build everything by ourselves.
42 (set-build-options %store #:use-substitutes? #f))
43
14da91e2 44\f
e3ce5d70
LC
45(test-begin "packages")
46
a3d73f59
LC
47(define-syntax-rule (dummy-package name* extra-fields ...)
48 (package (name name*) (version "0") (source #f)
49 (build-system gnu-build-system)
d45122f5 50 (synopsis #f) (description #f)
a3d73f59
LC
51 (home-page #f)
52 extra-fields ...))
53
54(test-assert "package-transitive-inputs"
55 (let* ((a (dummy-package "a"))
56 (b (dummy-package "b"
57 (propagated-inputs `(("a" ,a)))))
58 (c (dummy-package "c"
59 (inputs `(("a" ,a)))))
60 (d (dummy-package "d"
61 (propagated-inputs `(("x" "something.drv")))))
62 (e (dummy-package "e"
63 (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
64 (and (null? (package-transitive-inputs a))
65 (equal? `(("a" ,a)) (package-transitive-inputs b))
66 (equal? `(("a" ,a)) (package-transitive-inputs c))
67 (equal? (package-propagated-inputs d)
68 (package-transitive-inputs d))
69 (equal? `(("b" ,b) ("b/a" ,a) ("c" ,c)
70 ("d" ,d) ("d/x" "something.drv"))
71 (pk 'x (package-transitive-inputs e))))))
72
be13fbfa
LC
73(test-skip (if (not %store) 2 0))
74
75(test-assert "trivial"
76 (let* ((p (package (inherit (dummy-package "trivial"))
77 (build-system trivial-build-system)
78 (source #f)
79 (arguments
14da91e2
LC
80 `(#:guile ,%bootstrap-guile
81 #:builder
be13fbfa
LC
82 (begin
83 (mkdir %output)
84 (call-with-output-file (string-append %output "/test")
85 (lambda (p)
86 (display '(hello guix) p))))))))
87 (d (package-derivation %store p)))
88 (and (build-derivations %store (list d))
89 (let ((p (pk 'drv d (derivation-path->output-path d))))
90 (equal? '(hello guix)
91 (call-with-input-file (string-append p "/test") read))))))
e3ce5d70 92
860a6f1a
LC
93(test-assert "trivial with local file as input"
94 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
95 (p (package (inherit (dummy-package "trivial-with-input-file"))
96 (build-system trivial-build-system)
97 (source #f)
98 (arguments
99 `(#:guile ,%bootstrap-guile
100 #:builder (copy-file (assoc-ref %build-inputs "input")
101 %output)))
102 (inputs `(("input" ,i)))))
103 (d (package-derivation %store p)))
104 (and (build-derivations %store (list d))
105 (let ((p (pk 'drv d (derivation-path->output-path d))))
106 (equal? (call-with-input-file p get-bytevector-all)
107 (call-with-input-file i get-bytevector-all))))))
108
592ef6c8
LC
109(test-assert "trivial with system-dependent input"
110 (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
111 (build-system trivial-build-system)
112 (source #f)
113 (arguments
114 `(#:guile ,%bootstrap-guile
115 #:builder
116 (let ((out (assoc-ref %outputs "out"))
117 (bash (assoc-ref %build-inputs "bash")))
118 (zero? (system* bash "-c"
119 (format #f "echo hello > ~a" out))))))
120 (inputs `(("bash" ,(lambda (system)
121 (search-bootstrap-binary "bash"
122 system)))))))
123 (d (package-derivation %store p)))
124 (and (build-derivations %store (list d))
125 (let ((p (pk 'drv d (derivation-path->output-path d))))
126 (eq? 'hello (call-with-input-file p read))))))
127
ad1ebab3
LC
128(unless (false-if-exception (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV))
129 (test-skip 1))
9e782349
LC
130(test-assert "GNU Make, bootstrap"
131 ;; GNU Make is the first program built during bootstrap; we choose it
132 ;; here so that the test doesn't last for too long.
1ffa7090 133 (let ((gnu-make (@@ (gnu packages base) gnu-make-boot0)))
9e782349
LC
134 (and (package? gnu-make)
135 (or (location? (package-location gnu-make))
136 (not (package-location gnu-make)))
137 (let* ((drv (package-derivation %store gnu-make))
14da91e2
LC
138 (out (derivation-path->output-path drv)))
139 (and (build-derivations %store (list drv))
9e782349 140 (file-exists? (string-append out "/bin/make")))))))
e3ce5d70 141
ba326ce4
LC
142(test-eq "fold-packages" hello
143 (fold-packages (lambda (p r)
144 (if (string=? (package-name p) "hello")
145 p
146 r))
147 #f))
148
6b1891b0
LC
149(test-assert "find-packages-by-name"
150 (match (find-packages-by-name "hello")
151 (((? (cut eq? hello <>))) #t)
152 (wrong (pk 'find-packages-by-name wrong #f))))
153
154(test-assert "find-packages-by-name with version"
155 (match (find-packages-by-name "hello" (package-version hello))
156 (((? (cut eq? hello <>))) #t)
157 (wrong (pk 'find-packages-by-name wrong #f))))
158
e3ce5d70
LC
159(test-end "packages")
160
161\f
162(exit (= (test-runner-fail-count (test-runner-current)) 0))
163
164;;; Local Variables:
ba326ce4 165;;; eval: (put 'test-equal 'scheme-indent-function 2)
e3ce5d70 166;;; eval: (put 'test-assert 'scheme-indent-function 1)
a3d73f59 167;;; eval: (put 'dummy-package 'scheme-indent-function 1)
e3ce5d70 168;;; End: