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) | |
27 | #:use-module (gnu packages bootstrap) | |
e39d1461 | 28 | #:use-module ((gnu packages base) #:prefix packages:) |
dedb17ad | 29 | #:use-module ((gnu packages guile) #:prefix packages:) |
a2078770 | 30 | #:use-module (ice-9 match) |
ef8993e2 | 31 | #:use-module (ice-9 regex) |
d664f1b4 LC |
32 | #:use-module (ice-9 popen) |
33 | #:use-module (rnrs io ports) | |
79601521 | 34 | #:use-module (srfi srfi-11) |
a2078770 LC |
35 | #:use-module (srfi srfi-64)) |
36 | ||
343745c8 | 37 | ;; Test the (guix profiles) module. |
a2078770 | 38 | |
462f5cca | 39 | (define %store |
c1bc358f | 40 | (open-connection-for-tests)) |
a2078770 | 41 | |
ebf5ad46 LC |
42 | (define-syntax-rule (test-assertm name exp) |
43 | (test-assert name | |
44 | (run-with-store %store exp | |
45 | #:guile-for-build (%guile-for-build)))) | |
46 | ||
a2078770 LC |
47 | ;; Example manifest entries. |
48 | ||
f7554030 AK |
49 | (define guile-1.8.8 |
50 | (manifest-entry | |
51 | (name "guile") | |
52 | (version "1.8.8") | |
53 | (item "/gnu/store/...") | |
54 | (output "out"))) | |
55 | ||
a2078770 LC |
56 | (define guile-2.0.9 |
57 | (manifest-entry | |
58 | (name "guile") | |
59 | (version "2.0.9") | |
a54c94a4 | 60 | (item "/gnu/store/...") |
a2078770 LC |
61 | (output "out"))) |
62 | ||
63 | (define guile-2.0.9:debug | |
64 | (manifest-entry (inherit guile-2.0.9) | |
65 | (output "debug"))) | |
66 | ||
79601521 LC |
67 | (define glibc |
68 | (manifest-entry | |
69 | (name "glibc") | |
70 | (version "2.19") | |
71 | (item "/gnu/store/...") | |
72 | (output "out"))) | |
73 | ||
a2078770 LC |
74 | \f |
75 | (test-begin "profiles") | |
76 | ||
77 | (test-assert "manifest-installed?" | |
78 | (let ((m (manifest (list guile-2.0.9 guile-2.0.9:debug)))) | |
79 | (and (manifest-installed? m (manifest-pattern (name "guile"))) | |
80 | (manifest-installed? m (manifest-pattern | |
81 | (name "guile") (output "debug"))) | |
82 | (manifest-installed? m (manifest-pattern | |
83 | (name "guile") (output "out") | |
84 | (version "2.0.9"))) | |
85 | (not (manifest-installed? | |
86 | m (manifest-pattern (name "guile") (version "1.8.8")))) | |
87 | (not (manifest-installed? | |
88 | m (manifest-pattern (name "guile") (output "foobar"))))))) | |
89 | ||
90 | (test-assert "manifest-matching-entries" | |
91 | (let* ((e (list guile-2.0.9 guile-2.0.9:debug)) | |
92 | (m (manifest e))) | |
93 | (and (null? (manifest-matching-entries m | |
94 | (list (manifest-pattern | |
95 | (name "python"))))) | |
96 | (equal? e | |
97 | (manifest-matching-entries m | |
98 | (list (manifest-pattern | |
99 | (name "guile") | |
100 | (output #f))))) | |
101 | (equal? (list guile-2.0.9) | |
102 | (manifest-matching-entries m | |
103 | (list (manifest-pattern | |
104 | (name "guile") | |
105 | (version "2.0.9")))))))) | |
106 | ||
107 | (test-assert "manifest-remove" | |
108 | (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug))) | |
109 | (m1 (manifest-remove m0 | |
110 | (list (manifest-pattern (name "guile"))))) | |
111 | (m2 (manifest-remove m1 | |
112 | (list (manifest-pattern (name "guile"))))) ; same | |
113 | (m3 (manifest-remove m2 | |
114 | (list (manifest-pattern | |
115 | (name "guile") (output "debug"))))) | |
116 | (m4 (manifest-remove m3 | |
117 | (list (manifest-pattern (name "guile")))))) | |
118 | (match (manifest-entries m2) | |
119 | ((($ <manifest-entry> "guile" "2.0.9" "debug")) | |
120 | (and (equal? m1 m2) | |
121 | (null? (manifest-entries m3)) | |
122 | (null? (manifest-entries m4))))))) | |
123 | ||
f7554030 AK |
124 | (test-assert "manifest-add" |
125 | (let* ((m0 (manifest '())) | |
126 | (m1 (manifest-add m0 (list guile-1.8.8))) | |
127 | (m2 (manifest-add m1 (list guile-2.0.9))) | |
128 | (m3 (manifest-add m2 (list guile-2.0.9:debug))) | |
129 | (m4 (manifest-add m3 (list guile-2.0.9:debug)))) | |
130 | (and (match (manifest-entries m1) | |
131 | ((($ <manifest-entry> "guile" "1.8.8" "out")) #t) | |
132 | (_ #f)) | |
133 | (match (manifest-entries m2) | |
134 | ((($ <manifest-entry> "guile" "2.0.9" "out")) #t) | |
135 | (_ #f)) | |
136 | (equal? m3 m4)))) | |
137 | ||
343745c8 AK |
138 | (test-assert "manifest-perform-transaction" |
139 | (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug))) | |
140 | (t1 (manifest-transaction | |
141 | (install (list guile-1.8.8)) | |
142 | (remove (list (manifest-pattern (name "guile") | |
143 | (output "debug")))))) | |
144 | (t2 (manifest-transaction | |
145 | (remove (list (manifest-pattern (name "guile") | |
146 | (version "2.0.9") | |
147 | (output #f)))))) | |
148 | (m1 (manifest-perform-transaction m0 t1)) | |
149 | (m2 (manifest-perform-transaction m1 t2)) | |
150 | (m3 (manifest-perform-transaction m0 t2))) | |
151 | (and (match (manifest-entries m1) | |
152 | ((($ <manifest-entry> "guile" "1.8.8" "out")) #t) | |
153 | (_ #f)) | |
154 | (equal? m1 m2) | |
155 | (null? (manifest-entries m3))))) | |
156 | ||
79601521 LC |
157 | (test-assert "manifest-transaction-effects" |
158 | (let* ((m0 (manifest (list guile-1.8.8))) | |
159 | (t (manifest-transaction | |
160 | (install (list guile-2.0.9 glibc)) | |
161 | (remove (list (manifest-pattern (name "coreutils"))))))) | |
46b23e1a | 162 | (let-values (((remove install upgrade downgrade) |
79601521 | 163 | (manifest-transaction-effects m0 t))) |
46b23e1a | 164 | (and (null? remove) (null? downgrade) |
79601521 | 165 | (equal? (list glibc) install) |
ef8993e2 LC |
166 | (equal? (list (cons guile-1.8.8 guile-2.0.9)) upgrade))))) |
167 | ||
46b23e1a LC |
168 | (test-assert "manifest-transaction-effects and downgrades" |
169 | (let* ((m0 (manifest (list guile-2.0.9))) | |
170 | (t (manifest-transaction (install (list guile-1.8.8))))) | |
171 | (let-values (((remove install upgrade downgrade) | |
172 | (manifest-transaction-effects m0 t))) | |
173 | (and (null? remove) (null? install) (null? upgrade) | |
174 | (equal? (list (cons guile-2.0.9 guile-1.8.8)) downgrade))))) | |
175 | ||
3bea13bb LC |
176 | (test-assert "manifest-transaction-effects and pseudo-upgrades" |
177 | (let* ((m0 (manifest (list guile-2.0.9))) | |
178 | (t (manifest-transaction (install (list guile-2.0.9))))) | |
179 | (let-values (((remove install upgrade downgrade) | |
180 | (manifest-transaction-effects m0 t))) | |
181 | (and (null? remove) (null? install) (null? downgrade) | |
182 | (equal? (list (cons guile-2.0.9 guile-2.0.9)) upgrade))))) | |
183 | ||
ebf5ad46 LC |
184 | (test-assertm "profile-derivation" |
185 | (mlet* %store-monad | |
186 | ((entry -> (package->manifest-entry %bootstrap-guile)) | |
187 | (guile (package->derivation %bootstrap-guile)) | |
188 | (drv (profile-derivation (manifest (list entry)) | |
aa46a028 | 189 | #:hooks '())) |
ebf5ad46 LC |
190 | (profile -> (derivation->output-path drv)) |
191 | (bindir -> (string-append profile "/bin")) | |
192 | (_ (built-derivations (list drv)))) | |
193 | (return (and (file-exists? (string-append bindir "/guile")) | |
194 | (string=? (dirname (readlink bindir)) | |
195 | (derivation->output-path guile)))))) | |
462f5cca | 196 | |
e39d1461 LC |
197 | (test-assertm "profile-derivation, inputs" |
198 | (mlet* %store-monad | |
199 | ((entry -> (package->manifest-entry packages:glibc "debug")) | |
200 | (drv (profile-derivation (manifest (list entry)) | |
aa46a028 | 201 | #:hooks '()))) |
e39d1461 LC |
202 | (return (derivation-inputs drv)))) |
203 | ||
dedb17ad LC |
204 | (test-assertm "profile-manifest, search-paths" |
205 | (mlet* %store-monad | |
206 | ((guile -> (package | |
207 | (inherit %bootstrap-guile) | |
208 | (native-search-paths | |
209 | (package-native-search-paths packages:guile-2.0)))) | |
210 | (entry -> (package->manifest-entry guile)) | |
211 | (drv (profile-derivation (manifest (list entry)) | |
212 | #:hooks '())) | |
213 | (profile -> (derivation->output-path drv))) | |
214 | (mbegin %store-monad | |
215 | (built-derivations (list drv)) | |
216 | ||
217 | ;; Read the manifest back and make sure search paths are preserved. | |
218 | (let ((manifest (profile-manifest profile))) | |
219 | (match (manifest-entries manifest) | |
220 | ((result) | |
221 | (return (equal? (manifest-entry-search-paths result) | |
222 | (manifest-entry-search-paths entry) | |
223 | (package-native-search-paths | |
224 | packages:guile-2.0))))))))) | |
d664f1b4 LC |
225 | |
226 | (test-assertm "etc/profile" | |
227 | ;; Make sure we get an 'etc/profile' file that at least defines $PATH. | |
228 | (mlet* %store-monad | |
229 | ((guile -> (package | |
230 | (inherit %bootstrap-guile) | |
231 | (native-search-paths | |
232 | (package-native-search-paths packages:guile-2.0)))) | |
233 | (entry -> (package->manifest-entry guile)) | |
234 | (drv (profile-derivation (manifest (list entry)) | |
235 | #:hooks '())) | |
236 | (profile -> (derivation->output-path drv))) | |
237 | (mbegin %store-monad | |
238 | (built-derivations (list drv)) | |
239 | (let* ((pipe (open-input-pipe | |
240 | (string-append "source " | |
241 | profile "/etc/profile; " | |
242 | "unset GUIX_PROFILE; set"))) | |
243 | (env (get-string-all pipe))) | |
244 | (return | |
245 | (and (zero? (close-pipe pipe)) | |
246 | (string-contains env | |
247 | (string-append "PATH=" profile "/bin")))))))) | |
248 | ||
a2078770 LC |
249 | (test-end "profiles") |
250 | ||
251 | \f | |
252 | (exit (= (test-runner-fail-count (test-runner-current)) 0)) | |
253 | ||
254 | ;;; Local Variables: | |
255 | ;;; eval: (put 'dummy-package 'scheme-indent-function 1) | |
256 | ;;; End: |