build: Set the umask to 0022 before running the daemon for tests.
[jackhill/guix/guix.git] / tests / packages.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
e509d152 2;;; Copyright © 2012, 2013 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)
a18eda27 25 #:use-module (guix build-system)
be13fbfa 26 #:use-module (guix build-system trivial)
a3d73f59 27 #:use-module (guix build-system gnu)
59a43334 28 #:use-module (gnu packages)
1ffa7090
LC
29 #:use-module (gnu packages base)
30 #:use-module (gnu packages bootstrap)
e509d152 31 #:use-module (srfi srfi-11)
6b1891b0 32 #:use-module (srfi srfi-26)
9b222abe 33 #:use-module (srfi srfi-34)
6b1891b0 34 #:use-module (srfi srfi-64)
860a6f1a 35 #:use-module (rnrs io ports)
6b1891b0 36 #:use-module (ice-9 match))
e3ce5d70
LC
37
38;; Test the high-level packaging layer.
39
40(define %store
41 (false-if-exception (open-connection)))
42
81dbd783
LC
43(when %store
44 ;; Make sure we build everything by ourselves.
45 (set-build-options %store #:use-substitutes? #f))
46
14da91e2 47\f
e3ce5d70
LC
48(test-begin "packages")
49
a3d73f59
LC
50(define-syntax-rule (dummy-package name* extra-fields ...)
51 (package (name name*) (version "0") (source #f)
52 (build-system gnu-build-system)
d45122f5 53 (synopsis #f) (description #f)
1fb78cb2 54 (home-page #f) (license #f)
a3d73f59
LC
55 extra-fields ...))
56
d66c7096
LC
57(test-assert "package-field-location"
58 (let ()
59 (define (goto port line column)
60 (unless (and (= (port-column port) (- column 1))
61 (= (port-line port) (- line 1)))
62 (unless (eof-object? (get-char port))
63 (goto port line column))))
64
65 (define read-at
66 (match-lambda
67 (($ <location> file line column)
68 (call-with-input-file (search-path %load-path file)
69 (lambda (port)
70 (goto port line column)
71 (read port))))))
72
73 (and (equal? (read-at (package-field-location %bootstrap-guile 'name))
74 (package-name %bootstrap-guile))
75 (equal? (read-at (package-field-location %bootstrap-guile 'version))
f903dc05
LC
76 (package-version %bootstrap-guile))
77 (not (package-field-location %bootstrap-guile 'does-not-exist)))))
d66c7096 78
a3d73f59
LC
79(test-assert "package-transitive-inputs"
80 (let* ((a (dummy-package "a"))
81 (b (dummy-package "b"
82 (propagated-inputs `(("a" ,a)))))
83 (c (dummy-package "c"
84 (inputs `(("a" ,a)))))
85 (d (dummy-package "d"
86 (propagated-inputs `(("x" "something.drv")))))
87 (e (dummy-package "e"
88 (inputs `(("b" ,b) ("c" ,c) ("d" ,d))))))
89 (and (null? (package-transitive-inputs a))
90 (equal? `(("a" ,a)) (package-transitive-inputs b))
91 (equal? `(("a" ,a)) (package-transitive-inputs c))
92 (equal? (package-propagated-inputs d)
93 (package-transitive-inputs d))
94 (equal? `(("b" ,b) ("b/a" ,a) ("c" ,c)
95 ("d" ,d) ("d/x" "something.drv"))
96 (pk 'x (package-transitive-inputs e))))))
97
5dce8218 98(test-skip (if (not %store) 6 0))
e509d152
LC
99
100(test-assert "return values"
101 (let-values (((drv-path drv)
102 (package-derivation %store (dummy-package "p"))))
103 (and (derivation-path? drv-path)
104 (derivation? drv))))
be13fbfa 105
d510ab46
LC
106(test-assert "package-output"
107 (let* ((package (dummy-package "p"))
108 (drv-path (package-derivation %store package)))
109 (and (derivation-path? drv-path)
110 (string=? (derivation-path->output-path drv-path)
111 (package-output %store package "out")))))
112
be13fbfa
LC
113(test-assert "trivial"
114 (let* ((p (package (inherit (dummy-package "trivial"))
115 (build-system trivial-build-system)
116 (source #f)
117 (arguments
14da91e2
LC
118 `(#:guile ,%bootstrap-guile
119 #:builder
be13fbfa
LC
120 (begin
121 (mkdir %output)
122 (call-with-output-file (string-append %output "/test")
123 (lambda (p)
124 (display '(hello guix) p))))))))
125 (d (package-derivation %store p)))
126 (and (build-derivations %store (list d))
127 (let ((p (pk 'drv d (derivation-path->output-path d))))
128 (equal? '(hello guix)
129 (call-with-input-file (string-append p "/test") read))))))
e3ce5d70 130
860a6f1a
LC
131(test-assert "trivial with local file as input"
132 (let* ((i (search-path %load-path "ice-9/boot-9.scm"))
133 (p (package (inherit (dummy-package "trivial-with-input-file"))
134 (build-system trivial-build-system)
135 (source #f)
136 (arguments
137 `(#:guile ,%bootstrap-guile
138 #:builder (copy-file (assoc-ref %build-inputs "input")
139 %output)))
140 (inputs `(("input" ,i)))))
141 (d (package-derivation %store p)))
142 (and (build-derivations %store (list d))
143 (let ((p (pk 'drv d (derivation-path->output-path d))))
144 (equal? (call-with-input-file p get-bytevector-all)
145 (call-with-input-file i get-bytevector-all))))))
146
592ef6c8
LC
147(test-assert "trivial with system-dependent input"
148 (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input"))
149 (build-system trivial-build-system)
150 (source #f)
151 (arguments
152 `(#:guile ,%bootstrap-guile
153 #:builder
154 (let ((out (assoc-ref %outputs "out"))
155 (bash (assoc-ref %build-inputs "bash")))
156 (zero? (system* bash "-c"
157 (format #f "echo hello > ~a" out))))))
dd6b9a37
LC
158 (inputs `(("bash" ,(search-bootstrap-binary "bash"
159 (%current-system)))))))
592ef6c8
LC
160 (d (package-derivation %store p)))
161 (and (build-derivations %store (list d))
162 (let ((p (pk 'drv d (derivation-path->output-path d))))
163 (eq? 'hello (call-with-input-file p read))))))
164
a18eda27
LC
165(test-assert "search paths"
166 (let* ((p (make-prompt-tag "return-search-paths"))
167 (s (build-system
168 (name "raw")
169 (description "Raw build system with direct store access")
170 (build (lambda* (store name source inputs
171 #:key outputs system search-paths)
172 search-paths))))
173 (x (list (search-path-specification
174 (variable "GUILE_LOAD_PATH")
175 (directories '("share/guile/site/2.0")))
176 (search-path-specification
177 (variable "GUILE_LOAD_COMPILED_PATH")
178 (directories '("share/guile/site/2.0")))))
179 (a (package (inherit (dummy-package "guile"))
180 (build-system s)
181 (native-search-paths x)))
182 (b (package (inherit (dummy-package "guile-foo"))
183 (build-system s)
184 (inputs `(("guile" ,a)))))
185 (c (package (inherit (dummy-package "guile-bar"))
186 (build-system s)
187 (inputs `(("guile" ,a)
188 ("guile-foo" ,b))))))
189 (let-syntax ((collect (syntax-rules ()
190 ((_ body ...)
191 (call-with-prompt p
192 (lambda ()
193 body ...)
194 (lambda (k search-paths)
195 search-paths))))))
196 (and (null? (collect (package-derivation %store a)))
197 (equal? x (collect (package-derivation %store b)))
198 (equal? x (collect (package-derivation %store c)))))))
199
9c1edabd
LC
200(test-assert "package-cross-derivation"
201 (let-values (((drv-path drv)
202 (package-cross-derivation %store (dummy-package "p")
203 "mips64el-linux-gnu")))
204 (and (derivation-path? drv-path)
205 (derivation? drv))))
206
5dce8218
LC
207(test-assert "package-cross-derivation, trivial-build-system"
208 (let ((p (package (inherit (dummy-package "p"))
209 (build-system trivial-build-system)
210 (arguments '(#:builder (exit 1))))))
211 (let-values (((drv-path drv)
212 (package-cross-derivation %store p "mips64el-linux-gnu")))
213 (and (derivation-path? drv-path)
214 (derivation? drv)))))
215
9b222abe
LC
216(test-assert "package-cross-derivation, no cross builder"
217 (let* ((b (build-system (inherit trivial-build-system)
218 (cross-build #f)))
219 (p (package (inherit (dummy-package "p"))
220 (build-system b))))
221 (guard (c ((package-cross-build-system-error? c)
222 (eq? (package-error-package c) p)))
223 (package-cross-derivation %store p "mips64el-linux-gnu")
224 #f)))
225
ad1ebab3
LC
226(unless (false-if-exception (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV))
227 (test-skip 1))
9e782349
LC
228(test-assert "GNU Make, bootstrap"
229 ;; GNU Make is the first program built during bootstrap; we choose it
230 ;; here so that the test doesn't last for too long.
1ffa7090 231 (let ((gnu-make (@@ (gnu packages base) gnu-make-boot0)))
9e782349
LC
232 (and (package? gnu-make)
233 (or (location? (package-location gnu-make))
234 (not (package-location gnu-make)))
235 (let* ((drv (package-derivation %store gnu-make))
14da91e2
LC
236 (out (derivation-path->output-path drv)))
237 (and (build-derivations %store (list drv))
9e782349 238 (file-exists? (string-append out "/bin/make")))))))
e3ce5d70 239
ba326ce4
LC
240(test-eq "fold-packages" hello
241 (fold-packages (lambda (p r)
242 (if (string=? (package-name p) "hello")
243 p
244 r))
245 #f))
246
6b1891b0
LC
247(test-assert "find-packages-by-name"
248 (match (find-packages-by-name "hello")
249 (((? (cut eq? hello <>))) #t)
250 (wrong (pk 'find-packages-by-name wrong #f))))
251
252(test-assert "find-packages-by-name with version"
253 (match (find-packages-by-name "hello" (package-version hello))
254 (((? (cut eq? hello <>))) #t)
255 (wrong (pk 'find-packages-by-name wrong #f))))
256
e3ce5d70
LC
257(test-end "packages")
258
259\f
260(exit (= (test-runner-fail-count (test-runner-current)) 0))
261
262;;; Local Variables:
a3d73f59 263;;; eval: (put 'dummy-package 'scheme-indent-function 1)
e3ce5d70 264;;; End: