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