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