Commit | Line | Data |
---|---|---|
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 | ||
c8c25704 LC |
190 | (test-assert "manifest-transaction-null?" |
191 | (manifest-transaction-null? (manifest-transaction))) | |
192 | ||
ebf5ad46 LC |
193 | (test-assertm "profile-derivation" |
194 | (mlet* %store-monad | |
195 | ((entry -> (package->manifest-entry %bootstrap-guile)) | |
196 | (guile (package->derivation %bootstrap-guile)) | |
197 | (drv (profile-derivation (manifest (list entry)) | |
a6562c7e LC |
198 | #:hooks '() |
199 | #:locales? #f)) | |
ebf5ad46 LC |
200 | (profile -> (derivation->output-path drv)) |
201 | (bindir -> (string-append profile "/bin")) | |
202 | (_ (built-derivations (list drv)))) | |
203 | (return (and (file-exists? (string-append bindir "/guile")) | |
204 | (string=? (dirname (readlink bindir)) | |
205 | (derivation->output-path guile)))))) | |
462f5cca | 206 | |
e39d1461 LC |
207 | (test-assertm "profile-derivation, inputs" |
208 | (mlet* %store-monad | |
209 | ((entry -> (package->manifest-entry packages:glibc "debug")) | |
210 | (drv (profile-derivation (manifest (list entry)) | |
a6562c7e LC |
211 | #:hooks '() |
212 | #:locales? #f))) | |
e39d1461 LC |
213 | (return (derivation-inputs drv)))) |
214 | ||
9e90fc77 LC |
215 | (test-assert "package->manifest-entry defaults to \"out\"" |
216 | (let ((outputs (package-outputs packages:glibc))) | |
217 | (equal? (manifest-entry-output | |
218 | (package->manifest-entry (package | |
219 | (inherit packages:glibc) | |
220 | (outputs (reverse outputs))))) | |
221 | (manifest-entry-output | |
222 | (package->manifest-entry packages:glibc)) | |
223 | "out"))) | |
224 | ||
dedb17ad LC |
225 | (test-assertm "profile-manifest, search-paths" |
226 | (mlet* %store-monad | |
227 | ((guile -> (package | |
228 | (inherit %bootstrap-guile) | |
229 | (native-search-paths | |
230 | (package-native-search-paths packages:guile-2.0)))) | |
231 | (entry -> (package->manifest-entry guile)) | |
232 | (drv (profile-derivation (manifest (list entry)) | |
a6562c7e LC |
233 | #:hooks '() |
234 | #:locales? #f)) | |
dedb17ad LC |
235 | (profile -> (derivation->output-path drv))) |
236 | (mbegin %store-monad | |
237 | (built-derivations (list drv)) | |
238 | ||
239 | ;; Read the manifest back and make sure search paths are preserved. | |
240 | (let ((manifest (profile-manifest profile))) | |
241 | (match (manifest-entries manifest) | |
242 | ((result) | |
243 | (return (equal? (manifest-entry-search-paths result) | |
244 | (manifest-entry-search-paths entry) | |
245 | (package-native-search-paths | |
246 | packages:guile-2.0))))))))) | |
d664f1b4 | 247 | |
ccda8f7d LC |
248 | (test-assert "package->manifest-entry, search paths" |
249 | ;; See <http://bugs.gnu.org/22073>. | |
250 | (let ((mpl (@ (gnu packages python) python2-matplotlib))) | |
251 | (lset= eq? | |
252 | (package-transitive-native-search-paths mpl) | |
253 | (manifest-entry-search-paths | |
254 | (package->manifest-entry mpl))))) | |
255 | ||
d664f1b4 LC |
256 | (test-assertm "etc/profile" |
257 | ;; Make sure we get an 'etc/profile' file that at least defines $PATH. | |
258 | (mlet* %store-monad | |
259 | ((guile -> (package | |
260 | (inherit %bootstrap-guile) | |
261 | (native-search-paths | |
262 | (package-native-search-paths packages:guile-2.0)))) | |
263 | (entry -> (package->manifest-entry guile)) | |
264 | (drv (profile-derivation (manifest (list entry)) | |
a6562c7e LC |
265 | #:hooks '() |
266 | #:locales? #f)) | |
d664f1b4 LC |
267 | (profile -> (derivation->output-path drv))) |
268 | (mbegin %store-monad | |
269 | (built-derivations (list drv)) | |
270 | (let* ((pipe (open-input-pipe | |
9e006fb3 TUBK |
271 | (string-append "unset GUIX_PROFILE; " |
272 | ;; 'source' is a Bashism; use '.' (dot). | |
273 | ". " profile "/etc/profile; " | |
274 | ;; Don't try to parse set(1) output because | |
275 | ;; it differs among shells; just use echo. | |
276 | "echo $PATH"))) | |
277 | (path (get-string-all pipe))) | |
d664f1b4 LC |
278 | (return |
279 | (and (zero? (close-pipe pipe)) | |
9e006fb3 | 280 | (string-contains path (string-append profile "/bin")))))))) |
d664f1b4 | 281 | |
a0dac7a0 LC |
282 | (test-assertm "etc/profile when etc/ already exists" |
283 | ;; Here 'union-build' makes the profile's etc/ a symlink to the package's | |
284 | ;; etc/ directory, which makes it read-only. Make sure the profile build | |
285 | ;; handles that. | |
286 | (mlet* %store-monad | |
287 | ((thing -> (dummy-package "dummy" | |
288 | (build-system trivial-build-system) | |
289 | (arguments | |
290 | `(#:guile ,%bootstrap-guile | |
291 | #:builder | |
292 | (let ((out (assoc-ref %outputs "out"))) | |
293 | (mkdir out) | |
294 | (mkdir (string-append out "/etc")) | |
295 | (call-with-output-file (string-append out "/etc/foo") | |
296 | (lambda (port) | |
297 | (display "foo!" port)))))))) | |
298 | (entry -> (package->manifest-entry thing)) | |
299 | (drv (profile-derivation (manifest (list entry)) | |
a6562c7e LC |
300 | #:hooks '() |
301 | #:locales? #f)) | |
a0dac7a0 LC |
302 | (profile -> (derivation->output-path drv))) |
303 | (mbegin %store-monad | |
304 | (built-derivations (list drv)) | |
305 | (return (and (file-exists? (string-append profile "/etc/profile")) | |
306 | (string=? (call-with-input-file | |
307 | (string-append profile "/etc/foo") | |
308 | get-string-all) | |
309 | "foo!")))))) | |
310 | ||
113c17a0 LC |
311 | (test-assertm "etc/profile when etc/ is a symlink" |
312 | ;; When etc/ is a symlink, the unsymlink code in 0.8.2 would fail | |
313 | ;; gracelessly because 'scandir' would return #f. | |
314 | (mlet* %store-monad | |
315 | ((thing -> (dummy-package "dummy" | |
316 | (build-system trivial-build-system) | |
317 | (arguments | |
318 | `(#:guile ,%bootstrap-guile | |
319 | #:builder | |
320 | (let ((out (assoc-ref %outputs "out"))) | |
321 | (mkdir out) | |
322 | (mkdir (string-append out "/foo")) | |
323 | (symlink "foo" (string-append out "/etc")) | |
324 | (call-with-output-file (string-append out "/etc/bar") | |
325 | (lambda (port) | |
326 | (display "foo!" port)))))))) | |
327 | (entry -> (package->manifest-entry thing)) | |
328 | (drv (profile-derivation (manifest (list entry)) | |
a6562c7e LC |
329 | #:hooks '() |
330 | #:locales? #f)) | |
113c17a0 LC |
331 | (profile -> (derivation->output-path drv))) |
332 | (mbegin %store-monad | |
333 | (built-derivations (list drv)) | |
334 | (return (and (file-exists? (string-append profile "/etc/profile")) | |
335 | (string=? (call-with-input-file | |
336 | (string-append profile "/etc/bar") | |
337 | get-string-all) | |
338 | "foo!")))))) | |
339 | ||
a2078770 LC |
340 | (test-end "profiles") |
341 | ||
a2078770 LC |
342 | ;;; Local Variables: |
343 | ;;; eval: (put 'dummy-package 'scheme-indent-function 1) | |
344 | ;;; End: |