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