profiles: Output in 'package->manifest-entry' defaults to "out".
[jackhill/guix/guix.git] / tests / profiles.scm
CommitLineData
a2078770 1;;; GNU Guix --- Functional package management for GNU
ef8de985 2;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
343745c8 3;;; Copyright © 2014 Alex Kost <alezost@gmail.com>
a2078770
LC
4;;;
5;;; This file is part of GNU Guix.
6;;;
7;;; GNU Guix is free software; you can redistribute it and/or modify it
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
12;;; GNU Guix is distributed in the hope that it will be useful, but
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20(define-module (test-profiles)
c1bc358f 21 #:use-module (guix tests)
a2078770 22 #:use-module (guix profiles)
462f5cca
LC
23 #:use-module (guix store)
24 #:use-module (guix monads)
ef8de985 25 #:use-module (guix grafts)
462f5cca
LC
26 #:use-module (guix packages)
27 #:use-module (guix derivations)
a0dac7a0 28 #:use-module (guix build-system trivial)
462f5cca 29 #:use-module (gnu packages bootstrap)
e39d1461 30 #:use-module ((gnu packages base) #:prefix packages:)
dedb17ad 31 #:use-module ((gnu packages guile) #:prefix packages:)
a2078770 32 #:use-module (ice-9 match)
ef8993e2 33 #:use-module (ice-9 regex)
d664f1b4
LC
34 #:use-module (ice-9 popen)
35 #:use-module (rnrs io ports)
ccda8f7d 36 #:use-module (srfi srfi-1)
79601521 37 #:use-module (srfi srfi-11)
a2078770
LC
38 #:use-module (srfi srfi-64))
39
343745c8 40;; Test the (guix profiles) module.
a2078770 41
462f5cca 42(define %store
c1bc358f 43 (open-connection-for-tests))
a2078770 44
ef8de985
LC
45;; Globally disable grafts because they can trigger early builds.
46(%graft? #f)
47
ebf5ad46
LC
48(define-syntax-rule (test-assertm name exp)
49 (test-assert name
50 (run-with-store %store exp
51 #:guile-for-build (%guile-for-build))))
52
a2078770
LC
53;; Example manifest entries.
54
f7554030
AK
55(define guile-1.8.8
56 (manifest-entry
57 (name "guile")
58 (version "1.8.8")
59 (item "/gnu/store/...")
60 (output "out")))
61
a2078770
LC
62(define guile-2.0.9
63 (manifest-entry
64 (name "guile")
65 (version "2.0.9")
a54c94a4 66 (item "/gnu/store/...")
a2078770
LC
67 (output "out")))
68
69(define guile-2.0.9:debug
70 (manifest-entry (inherit guile-2.0.9)
71 (output "debug")))
72
79601521
LC
73(define glibc
74 (manifest-entry
75 (name "glibc")
76 (version "2.19")
77 (item "/gnu/store/...")
78 (output "out")))
79
a2078770
LC
80\f
81(test-begin "profiles")
82
83(test-assert "manifest-installed?"
84 (let ((m (manifest (list guile-2.0.9 guile-2.0.9:debug))))
85 (and (manifest-installed? m (manifest-pattern (name "guile")))
86 (manifest-installed? m (manifest-pattern
87 (name "guile") (output "debug")))
88 (manifest-installed? m (manifest-pattern
89 (name "guile") (output "out")
90 (version "2.0.9")))
91 (not (manifest-installed?
92 m (manifest-pattern (name "guile") (version "1.8.8"))))
93 (not (manifest-installed?
94 m (manifest-pattern (name "guile") (output "foobar")))))))
95
96(test-assert "manifest-matching-entries"
97 (let* ((e (list guile-2.0.9 guile-2.0.9:debug))
98 (m (manifest e)))
99 (and (null? (manifest-matching-entries m
100 (list (manifest-pattern
101 (name "python")))))
102 (equal? e
103 (manifest-matching-entries m
104 (list (manifest-pattern
105 (name "guile")
106 (output #f)))))
107 (equal? (list guile-2.0.9)
108 (manifest-matching-entries m
109 (list (manifest-pattern
110 (name "guile")
111 (version "2.0.9"))))))))
112
113(test-assert "manifest-remove"
114 (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug)))
115 (m1 (manifest-remove m0
116 (list (manifest-pattern (name "guile")))))
117 (m2 (manifest-remove m1
118 (list (manifest-pattern (name "guile"))))) ; same
119 (m3 (manifest-remove m2
120 (list (manifest-pattern
121 (name "guile") (output "debug")))))
122 (m4 (manifest-remove m3
123 (list (manifest-pattern (name "guile"))))))
124 (match (manifest-entries m2)
125 ((($ <manifest-entry> "guile" "2.0.9" "debug"))
126 (and (equal? m1 m2)
127 (null? (manifest-entries m3))
128 (null? (manifest-entries m4)))))))
129
f7554030
AK
130(test-assert "manifest-add"
131 (let* ((m0 (manifest '()))
132 (m1 (manifest-add m0 (list guile-1.8.8)))
133 (m2 (manifest-add m1 (list guile-2.0.9)))
134 (m3 (manifest-add m2 (list guile-2.0.9:debug)))
135 (m4 (manifest-add m3 (list guile-2.0.9:debug))))
136 (and (match (manifest-entries m1)
137 ((($ <manifest-entry> "guile" "1.8.8" "out")) #t)
138 (_ #f))
139 (match (manifest-entries m2)
140 ((($ <manifest-entry> "guile" "2.0.9" "out")) #t)
141 (_ #f))
142 (equal? m3 m4))))
143
343745c8
AK
144(test-assert "manifest-perform-transaction"
145 (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug)))
146 (t1 (manifest-transaction
147 (install (list guile-1.8.8))
148 (remove (list (manifest-pattern (name "guile")
149 (output "debug"))))))
150 (t2 (manifest-transaction
151 (remove (list (manifest-pattern (name "guile")
152 (version "2.0.9")
153 (output #f))))))
154 (m1 (manifest-perform-transaction m0 t1))
155 (m2 (manifest-perform-transaction m1 t2))
156 (m3 (manifest-perform-transaction m0 t2)))
157 (and (match (manifest-entries m1)
158 ((($ <manifest-entry> "guile" "1.8.8" "out")) #t)
159 (_ #f))
160 (equal? m1 m2)
161 (null? (manifest-entries m3)))))
162
79601521
LC
163(test-assert "manifest-transaction-effects"
164 (let* ((m0 (manifest (list guile-1.8.8)))
165 (t (manifest-transaction
166 (install (list guile-2.0.9 glibc))
167 (remove (list (manifest-pattern (name "coreutils")))))))
46b23e1a 168 (let-values (((remove install upgrade downgrade)
79601521 169 (manifest-transaction-effects m0 t)))
46b23e1a 170 (and (null? remove) (null? downgrade)
79601521 171 (equal? (list glibc) install)
ef8993e2
LC
172 (equal? (list (cons guile-1.8.8 guile-2.0.9)) upgrade)))))
173
46b23e1a
LC
174(test-assert "manifest-transaction-effects and downgrades"
175 (let* ((m0 (manifest (list guile-2.0.9)))
176 (t (manifest-transaction (install (list guile-1.8.8)))))
177 (let-values (((remove install upgrade downgrade)
178 (manifest-transaction-effects m0 t)))
179 (and (null? remove) (null? install) (null? upgrade)
180 (equal? (list (cons guile-2.0.9 guile-1.8.8)) downgrade)))))
181
3bea13bb
LC
182(test-assert "manifest-transaction-effects and pseudo-upgrades"
183 (let* ((m0 (manifest (list guile-2.0.9)))
184 (t (manifest-transaction (install (list guile-2.0.9)))))
185 (let-values (((remove install upgrade downgrade)
186 (manifest-transaction-effects m0 t)))
187 (and (null? remove) (null? install) (null? downgrade)
188 (equal? (list (cons guile-2.0.9 guile-2.0.9)) upgrade)))))
189
ebf5ad46
LC
190(test-assertm "profile-derivation"
191 (mlet* %store-monad
192 ((entry -> (package->manifest-entry %bootstrap-guile))
193 (guile (package->derivation %bootstrap-guile))
194 (drv (profile-derivation (manifest (list entry))
aa46a028 195 #:hooks '()))
ebf5ad46
LC
196 (profile -> (derivation->output-path drv))
197 (bindir -> (string-append profile "/bin"))
198 (_ (built-derivations (list drv))))
199 (return (and (file-exists? (string-append bindir "/guile"))
200 (string=? (dirname (readlink bindir))
201 (derivation->output-path guile))))))
462f5cca 202
e39d1461
LC
203(test-assertm "profile-derivation, inputs"
204 (mlet* %store-monad
205 ((entry -> (package->manifest-entry packages:glibc "debug"))
206 (drv (profile-derivation (manifest (list entry))
aa46a028 207 #:hooks '())))
e39d1461
LC
208 (return (derivation-inputs drv))))
209
9e90fc77
LC
210(test-assert "package->manifest-entry defaults to \"out\""
211 (let ((outputs (package-outputs packages:glibc)))
212 (equal? (manifest-entry-output
213 (package->manifest-entry (package
214 (inherit packages:glibc)
215 (outputs (reverse outputs)))))
216 (manifest-entry-output
217 (package->manifest-entry packages:glibc))
218 "out")))
219
dedb17ad
LC
220(test-assertm "profile-manifest, search-paths"
221 (mlet* %store-monad
222 ((guile -> (package
223 (inherit %bootstrap-guile)
224 (native-search-paths
225 (package-native-search-paths packages:guile-2.0))))
226 (entry -> (package->manifest-entry guile))
227 (drv (profile-derivation (manifest (list entry))
228 #:hooks '()))
229 (profile -> (derivation->output-path drv)))
230 (mbegin %store-monad
231 (built-derivations (list drv))
232
233 ;; Read the manifest back and make sure search paths are preserved.
234 (let ((manifest (profile-manifest profile)))
235 (match (manifest-entries manifest)
236 ((result)
237 (return (equal? (manifest-entry-search-paths result)
238 (manifest-entry-search-paths entry)
239 (package-native-search-paths
240 packages:guile-2.0)))))))))
d664f1b4 241
ccda8f7d
LC
242(test-assert "package->manifest-entry, search paths"
243 ;; See <http://bugs.gnu.org/22073>.
244 (let ((mpl (@ (gnu packages python) python2-matplotlib)))
245 (lset= eq?
246 (package-transitive-native-search-paths mpl)
247 (manifest-entry-search-paths
248 (package->manifest-entry mpl)))))
249
d664f1b4
LC
250(test-assertm "etc/profile"
251 ;; Make sure we get an 'etc/profile' file that at least defines $PATH.
252 (mlet* %store-monad
253 ((guile -> (package
254 (inherit %bootstrap-guile)
255 (native-search-paths
256 (package-native-search-paths packages:guile-2.0))))
257 (entry -> (package->manifest-entry guile))
258 (drv (profile-derivation (manifest (list entry))
259 #:hooks '()))
260 (profile -> (derivation->output-path drv)))
261 (mbegin %store-monad
262 (built-derivations (list drv))
263 (let* ((pipe (open-input-pipe
9e006fb3
TUBK
264 (string-append "unset GUIX_PROFILE; "
265 ;; 'source' is a Bashism; use '.' (dot).
266 ". " profile "/etc/profile; "
267 ;; Don't try to parse set(1) output because
268 ;; it differs among shells; just use echo.
269 "echo $PATH")))
270 (path (get-string-all pipe)))
d664f1b4
LC
271 (return
272 (and (zero? (close-pipe pipe))
9e006fb3 273 (string-contains path (string-append profile "/bin"))))))))
d664f1b4 274
a0dac7a0
LC
275(test-assertm "etc/profile when etc/ already exists"
276 ;; Here 'union-build' makes the profile's etc/ a symlink to the package's
277 ;; etc/ directory, which makes it read-only. Make sure the profile build
278 ;; handles that.
279 (mlet* %store-monad
280 ((thing -> (dummy-package "dummy"
281 (build-system trivial-build-system)
282 (arguments
283 `(#:guile ,%bootstrap-guile
284 #:builder
285 (let ((out (assoc-ref %outputs "out")))
286 (mkdir out)
287 (mkdir (string-append out "/etc"))
288 (call-with-output-file (string-append out "/etc/foo")
289 (lambda (port)
290 (display "foo!" port))))))))
291 (entry -> (package->manifest-entry thing))
292 (drv (profile-derivation (manifest (list entry))
293 #:hooks '()))
294 (profile -> (derivation->output-path drv)))
295 (mbegin %store-monad
296 (built-derivations (list drv))
297 (return (and (file-exists? (string-append profile "/etc/profile"))
298 (string=? (call-with-input-file
299 (string-append profile "/etc/foo")
300 get-string-all)
301 "foo!"))))))
302
113c17a0
LC
303(test-assertm "etc/profile when etc/ is a symlink"
304 ;; When etc/ is a symlink, the unsymlink code in 0.8.2 would fail
305 ;; gracelessly because 'scandir' would return #f.
306 (mlet* %store-monad
307 ((thing -> (dummy-package "dummy"
308 (build-system trivial-build-system)
309 (arguments
310 `(#:guile ,%bootstrap-guile
311 #:builder
312 (let ((out (assoc-ref %outputs "out")))
313 (mkdir out)
314 (mkdir (string-append out "/foo"))
315 (symlink "foo" (string-append out "/etc"))
316 (call-with-output-file (string-append out "/etc/bar")
317 (lambda (port)
318 (display "foo!" port))))))))
319 (entry -> (package->manifest-entry thing))
320 (drv (profile-derivation (manifest (list entry))
321 #:hooks '()))
322 (profile -> (derivation->output-path drv)))
323 (mbegin %store-monad
324 (built-derivations (list drv))
325 (return (and (file-exists? (string-append profile "/etc/profile"))
326 (string=? (call-with-input-file
327 (string-append profile "/etc/bar")
328 get-string-all)
329 "foo!"))))))
330
a2078770
LC
331(test-end "profiles")
332
a2078770
LC
333;;; Local Variables:
334;;; eval: (put 'dummy-package 'scheme-indent-function 1)
335;;; End: