Commit | Line | Data |
---|---|---|
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 | ||
ee48b283 LC |
73 | ;; Until Guile 2.0.6 included, source properties were added only to pairs. |
74 | ;; Thus, check against both VALUE and (FIELD VALUE). | |
75 | (and (member (read-at (package-field-location %bootstrap-guile 'name)) | |
76 | (let ((name (package-name %bootstrap-guile))) | |
77 | (list name `(name ,name)))) | |
78 | (member (read-at (package-field-location %bootstrap-guile 'version)) | |
79 | (let ((version (package-version %bootstrap-guile))) | |
80 | (list version `(version ,version)))) | |
f903dc05 | 81 | (not (package-field-location %bootstrap-guile 'does-not-exist))))) |
d66c7096 | 82 | |
a3d73f59 LC |
83 | (test-assert "package-transitive-inputs" |
84 | (let* ((a (dummy-package "a")) | |
85 | (b (dummy-package "b" | |
86 | (propagated-inputs `(("a" ,a))))) | |
87 | (c (dummy-package "c" | |
88 | (inputs `(("a" ,a))))) | |
89 | (d (dummy-package "d" | |
90 | (propagated-inputs `(("x" "something.drv"))))) | |
91 | (e (dummy-package "e" | |
92 | (inputs `(("b" ,b) ("c" ,c) ("d" ,d)))))) | |
93 | (and (null? (package-transitive-inputs a)) | |
94 | (equal? `(("a" ,a)) (package-transitive-inputs b)) | |
95 | (equal? `(("a" ,a)) (package-transitive-inputs c)) | |
96 | (equal? (package-propagated-inputs d) | |
97 | (package-transitive-inputs d)) | |
98 | (equal? `(("b" ,b) ("b/a" ,a) ("c" ,c) | |
99 | ("d" ,d) ("d/x" "something.drv")) | |
100 | (pk 'x (package-transitive-inputs e)))))) | |
101 | ||
7357138b LC |
102 | (test-skip (if (not %store) 8 0)) |
103 | ||
104 | (test-assert "package-source-derivation, file" | |
105 | (let* ((file (search-path %load-path "guix.scm")) | |
106 | (package (package (inherit (dummy-package "p")) | |
107 | (source file))) | |
108 | (source (package-source-derivation %store | |
109 | (package-source package)))) | |
110 | (and (store-path? source) | |
111 | (valid-path? %store source) | |
112 | (equal? (call-with-input-file source get-bytevector-all) | |
113 | (call-with-input-file file get-bytevector-all))))) | |
114 | ||
115 | (test-assert "package-source-derivation, store path" | |
116 | (let* ((file (add-to-store %store "guix.scm" #t "sha256" | |
117 | (search-path %load-path "guix.scm"))) | |
118 | (package (package (inherit (dummy-package "p")) | |
119 | (source file))) | |
120 | (source (package-source-derivation %store | |
121 | (package-source package)))) | |
122 | (string=? file source))) | |
e509d152 LC |
123 | |
124 | (test-assert "return values" | |
125 | (let-values (((drv-path drv) | |
126 | (package-derivation %store (dummy-package "p")))) | |
127 | (and (derivation-path? drv-path) | |
128 | (derivation? drv)))) | |
be13fbfa | 129 | |
d510ab46 LC |
130 | (test-assert "package-output" |
131 | (let* ((package (dummy-package "p")) | |
132 | (drv-path (package-derivation %store package))) | |
133 | (and (derivation-path? drv-path) | |
134 | (string=? (derivation-path->output-path drv-path) | |
135 | (package-output %store package "out"))))) | |
136 | ||
be13fbfa LC |
137 | (test-assert "trivial" |
138 | (let* ((p (package (inherit (dummy-package "trivial")) | |
139 | (build-system trivial-build-system) | |
140 | (source #f) | |
141 | (arguments | |
14da91e2 LC |
142 | `(#:guile ,%bootstrap-guile |
143 | #:builder | |
be13fbfa LC |
144 | (begin |
145 | (mkdir %output) | |
146 | (call-with-output-file (string-append %output "/test") | |
147 | (lambda (p) | |
148 | (display '(hello guix) p)))))))) | |
149 | (d (package-derivation %store p))) | |
150 | (and (build-derivations %store (list d)) | |
151 | (let ((p (pk 'drv d (derivation-path->output-path d)))) | |
152 | (equal? '(hello guix) | |
153 | (call-with-input-file (string-append p "/test") read)))))) | |
e3ce5d70 | 154 | |
860a6f1a LC |
155 | (test-assert "trivial with local file as input" |
156 | (let* ((i (search-path %load-path "ice-9/boot-9.scm")) | |
157 | (p (package (inherit (dummy-package "trivial-with-input-file")) | |
158 | (build-system trivial-build-system) | |
159 | (source #f) | |
160 | (arguments | |
161 | `(#:guile ,%bootstrap-guile | |
162 | #:builder (copy-file (assoc-ref %build-inputs "input") | |
163 | %output))) | |
164 | (inputs `(("input" ,i))))) | |
165 | (d (package-derivation %store p))) | |
166 | (and (build-derivations %store (list d)) | |
167 | (let ((p (pk 'drv d (derivation-path->output-path d)))) | |
168 | (equal? (call-with-input-file p get-bytevector-all) | |
169 | (call-with-input-file i get-bytevector-all)))))) | |
170 | ||
592ef6c8 LC |
171 | (test-assert "trivial with system-dependent input" |
172 | (let* ((p (package (inherit (dummy-package "trivial-system-dependent-input")) | |
173 | (build-system trivial-build-system) | |
174 | (source #f) | |
175 | (arguments | |
176 | `(#:guile ,%bootstrap-guile | |
177 | #:builder | |
178 | (let ((out (assoc-ref %outputs "out")) | |
179 | (bash (assoc-ref %build-inputs "bash"))) | |
180 | (zero? (system* bash "-c" | |
181 | (format #f "echo hello > ~a" out)))))) | |
dd6b9a37 LC |
182 | (inputs `(("bash" ,(search-bootstrap-binary "bash" |
183 | (%current-system))))))) | |
592ef6c8 LC |
184 | (d (package-derivation %store p))) |
185 | (and (build-derivations %store (list d)) | |
186 | (let ((p (pk 'drv d (derivation-path->output-path d)))) | |
187 | (eq? 'hello (call-with-input-file p read)))))) | |
188 | ||
a18eda27 LC |
189 | (test-assert "search paths" |
190 | (let* ((p (make-prompt-tag "return-search-paths")) | |
191 | (s (build-system | |
192 | (name "raw") | |
193 | (description "Raw build system with direct store access") | |
194 | (build (lambda* (store name source inputs | |
195 | #:key outputs system search-paths) | |
196 | search-paths)))) | |
197 | (x (list (search-path-specification | |
198 | (variable "GUILE_LOAD_PATH") | |
199 | (directories '("share/guile/site/2.0"))) | |
200 | (search-path-specification | |
201 | (variable "GUILE_LOAD_COMPILED_PATH") | |
202 | (directories '("share/guile/site/2.0"))))) | |
203 | (a (package (inherit (dummy-package "guile")) | |
204 | (build-system s) | |
205 | (native-search-paths x))) | |
206 | (b (package (inherit (dummy-package "guile-foo")) | |
207 | (build-system s) | |
208 | (inputs `(("guile" ,a))))) | |
209 | (c (package (inherit (dummy-package "guile-bar")) | |
210 | (build-system s) | |
211 | (inputs `(("guile" ,a) | |
212 | ("guile-foo" ,b)))))) | |
213 | (let-syntax ((collect (syntax-rules () | |
214 | ((_ body ...) | |
215 | (call-with-prompt p | |
216 | (lambda () | |
217 | body ...) | |
218 | (lambda (k search-paths) | |
219 | search-paths)))))) | |
220 | (and (null? (collect (package-derivation %store a))) | |
221 | (equal? x (collect (package-derivation %store b))) | |
222 | (equal? x (collect (package-derivation %store c))))))) | |
223 | ||
9c1edabd LC |
224 | (test-assert "package-cross-derivation" |
225 | (let-values (((drv-path drv) | |
226 | (package-cross-derivation %store (dummy-package "p") | |
227 | "mips64el-linux-gnu"))) | |
228 | (and (derivation-path? drv-path) | |
229 | (derivation? drv)))) | |
230 | ||
5dce8218 LC |
231 | (test-assert "package-cross-derivation, trivial-build-system" |
232 | (let ((p (package (inherit (dummy-package "p")) | |
233 | (build-system trivial-build-system) | |
234 | (arguments '(#:builder (exit 1)))))) | |
235 | (let-values (((drv-path drv) | |
236 | (package-cross-derivation %store p "mips64el-linux-gnu"))) | |
237 | (and (derivation-path? drv-path) | |
238 | (derivation? drv))))) | |
239 | ||
9b222abe LC |
240 | (test-assert "package-cross-derivation, no cross builder" |
241 | (let* ((b (build-system (inherit trivial-build-system) | |
242 | (cross-build #f))) | |
243 | (p (package (inherit (dummy-package "p")) | |
244 | (build-system b)))) | |
245 | (guard (c ((package-cross-build-system-error? c) | |
246 | (eq? (package-error-package c) p))) | |
247 | (package-cross-derivation %store p "mips64el-linux-gnu") | |
248 | #f))) | |
249 | ||
ad1ebab3 LC |
250 | (unless (false-if-exception (getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)) |
251 | (test-skip 1)) | |
9e782349 LC |
252 | (test-assert "GNU Make, bootstrap" |
253 | ;; GNU Make is the first program built during bootstrap; we choose it | |
254 | ;; here so that the test doesn't last for too long. | |
1ffa7090 | 255 | (let ((gnu-make (@@ (gnu packages base) gnu-make-boot0))) |
9e782349 LC |
256 | (and (package? gnu-make) |
257 | (or (location? (package-location gnu-make)) | |
258 | (not (package-location gnu-make))) | |
259 | (let* ((drv (package-derivation %store gnu-make)) | |
14da91e2 LC |
260 | (out (derivation-path->output-path drv))) |
261 | (and (build-derivations %store (list drv)) | |
9e782349 | 262 | (file-exists? (string-append out "/bin/make"))))))) |
e3ce5d70 | 263 | |
ba326ce4 LC |
264 | (test-eq "fold-packages" hello |
265 | (fold-packages (lambda (p r) | |
266 | (if (string=? (package-name p) "hello") | |
267 | p | |
268 | r)) | |
269 | #f)) | |
270 | ||
6b1891b0 LC |
271 | (test-assert "find-packages-by-name" |
272 | (match (find-packages-by-name "hello") | |
273 | (((? (cut eq? hello <>))) #t) | |
274 | (wrong (pk 'find-packages-by-name wrong #f)))) | |
275 | ||
276 | (test-assert "find-packages-by-name with version" | |
277 | (match (find-packages-by-name "hello" (package-version hello)) | |
278 | (((? (cut eq? hello <>))) #t) | |
279 | (wrong (pk 'find-packages-by-name wrong #f)))) | |
280 | ||
e3ce5d70 LC |
281 | (test-end "packages") |
282 | ||
283 | \f | |
284 | (exit (= (test-runner-fail-count (test-runner-current)) 0)) | |
285 | ||
286 | ;;; Local Variables: | |
a3d73f59 | 287 | ;;; eval: (put 'dummy-package 'scheme-indent-function 1) |
e3ce5d70 | 288 | ;;; End: |