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) | |
a2078770 | 28 | #:use-module (ice-9 match) |
ef8993e2 | 29 | #:use-module (ice-9 regex) |
79601521 | 30 | #:use-module (srfi srfi-11) |
a2078770 LC |
31 | #:use-module (srfi srfi-64)) |
32 | ||
343745c8 | 33 | ;; Test the (guix profiles) module. |
a2078770 | 34 | |
462f5cca | 35 | (define %store |
c1bc358f | 36 | (open-connection-for-tests)) |
a2078770 | 37 | |
ebf5ad46 LC |
38 | (define-syntax-rule (test-assertm name exp) |
39 | (test-assert name | |
40 | (run-with-store %store exp | |
41 | #:guile-for-build (%guile-for-build)))) | |
42 | ||
a2078770 LC |
43 | ;; Example manifest entries. |
44 | ||
f7554030 AK |
45 | (define guile-1.8.8 |
46 | (manifest-entry | |
47 | (name "guile") | |
48 | (version "1.8.8") | |
49 | (item "/gnu/store/...") | |
50 | (output "out"))) | |
51 | ||
a2078770 LC |
52 | (define guile-2.0.9 |
53 | (manifest-entry | |
54 | (name "guile") | |
55 | (version "2.0.9") | |
a54c94a4 | 56 | (item "/gnu/store/...") |
a2078770 LC |
57 | (output "out"))) |
58 | ||
59 | (define guile-2.0.9:debug | |
60 | (manifest-entry (inherit guile-2.0.9) | |
61 | (output "debug"))) | |
62 | ||
79601521 LC |
63 | (define glibc |
64 | (manifest-entry | |
65 | (name "glibc") | |
66 | (version "2.19") | |
67 | (item "/gnu/store/...") | |
68 | (output "out"))) | |
69 | ||
a2078770 LC |
70 | \f |
71 | (test-begin "profiles") | |
72 | ||
73 | (test-assert "manifest-installed?" | |
74 | (let ((m (manifest (list guile-2.0.9 guile-2.0.9:debug)))) | |
75 | (and (manifest-installed? m (manifest-pattern (name "guile"))) | |
76 | (manifest-installed? m (manifest-pattern | |
77 | (name "guile") (output "debug"))) | |
78 | (manifest-installed? m (manifest-pattern | |
79 | (name "guile") (output "out") | |
80 | (version "2.0.9"))) | |
81 | (not (manifest-installed? | |
82 | m (manifest-pattern (name "guile") (version "1.8.8")))) | |
83 | (not (manifest-installed? | |
84 | m (manifest-pattern (name "guile") (output "foobar"))))))) | |
85 | ||
86 | (test-assert "manifest-matching-entries" | |
87 | (let* ((e (list guile-2.0.9 guile-2.0.9:debug)) | |
88 | (m (manifest e))) | |
89 | (and (null? (manifest-matching-entries m | |
90 | (list (manifest-pattern | |
91 | (name "python"))))) | |
92 | (equal? e | |
93 | (manifest-matching-entries m | |
94 | (list (manifest-pattern | |
95 | (name "guile") | |
96 | (output #f))))) | |
97 | (equal? (list guile-2.0.9) | |
98 | (manifest-matching-entries m | |
99 | (list (manifest-pattern | |
100 | (name "guile") | |
101 | (version "2.0.9")))))))) | |
102 | ||
103 | (test-assert "manifest-remove" | |
104 | (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug))) | |
105 | (m1 (manifest-remove m0 | |
106 | (list (manifest-pattern (name "guile"))))) | |
107 | (m2 (manifest-remove m1 | |
108 | (list (manifest-pattern (name "guile"))))) ; same | |
109 | (m3 (manifest-remove m2 | |
110 | (list (manifest-pattern | |
111 | (name "guile") (output "debug"))))) | |
112 | (m4 (manifest-remove m3 | |
113 | (list (manifest-pattern (name "guile")))))) | |
114 | (match (manifest-entries m2) | |
115 | ((($ <manifest-entry> "guile" "2.0.9" "debug")) | |
116 | (and (equal? m1 m2) | |
117 | (null? (manifest-entries m3)) | |
118 | (null? (manifest-entries m4))))))) | |
119 | ||
f7554030 AK |
120 | (test-assert "manifest-add" |
121 | (let* ((m0 (manifest '())) | |
122 | (m1 (manifest-add m0 (list guile-1.8.8))) | |
123 | (m2 (manifest-add m1 (list guile-2.0.9))) | |
124 | (m3 (manifest-add m2 (list guile-2.0.9:debug))) | |
125 | (m4 (manifest-add m3 (list guile-2.0.9:debug)))) | |
126 | (and (match (manifest-entries m1) | |
127 | ((($ <manifest-entry> "guile" "1.8.8" "out")) #t) | |
128 | (_ #f)) | |
129 | (match (manifest-entries m2) | |
130 | ((($ <manifest-entry> "guile" "2.0.9" "out")) #t) | |
131 | (_ #f)) | |
132 | (equal? m3 m4)))) | |
133 | ||
343745c8 AK |
134 | (test-assert "manifest-perform-transaction" |
135 | (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug))) | |
136 | (t1 (manifest-transaction | |
137 | (install (list guile-1.8.8)) | |
138 | (remove (list (manifest-pattern (name "guile") | |
139 | (output "debug")))))) | |
140 | (t2 (manifest-transaction | |
141 | (remove (list (manifest-pattern (name "guile") | |
142 | (version "2.0.9") | |
143 | (output #f)))))) | |
144 | (m1 (manifest-perform-transaction m0 t1)) | |
145 | (m2 (manifest-perform-transaction m1 t2)) | |
146 | (m3 (manifest-perform-transaction m0 t2))) | |
147 | (and (match (manifest-entries m1) | |
148 | ((($ <manifest-entry> "guile" "1.8.8" "out")) #t) | |
149 | (_ #f)) | |
150 | (equal? m1 m2) | |
151 | (null? (manifest-entries m3))))) | |
152 | ||
79601521 LC |
153 | (test-assert "manifest-transaction-effects" |
154 | (let* ((m0 (manifest (list guile-1.8.8))) | |
155 | (t (manifest-transaction | |
156 | (install (list guile-2.0.9 glibc)) | |
157 | (remove (list (manifest-pattern (name "coreutils"))))))) | |
46b23e1a | 158 | (let-values (((remove install upgrade downgrade) |
79601521 | 159 | (manifest-transaction-effects m0 t))) |
46b23e1a | 160 | (and (null? remove) (null? downgrade) |
79601521 | 161 | (equal? (list glibc) install) |
ef8993e2 LC |
162 | (equal? (list (cons guile-1.8.8 guile-2.0.9)) upgrade))))) |
163 | ||
46b23e1a LC |
164 | (test-assert "manifest-transaction-effects and downgrades" |
165 | (let* ((m0 (manifest (list guile-2.0.9))) | |
166 | (t (manifest-transaction (install (list guile-1.8.8))))) | |
167 | (let-values (((remove install upgrade downgrade) | |
168 | (manifest-transaction-effects m0 t))) | |
169 | (and (null? remove) (null? install) (null? upgrade) | |
170 | (equal? (list (cons guile-2.0.9 guile-1.8.8)) downgrade))))) | |
171 | ||
3bea13bb LC |
172 | (test-assert "manifest-transaction-effects and pseudo-upgrades" |
173 | (let* ((m0 (manifest (list guile-2.0.9))) | |
174 | (t (manifest-transaction (install (list guile-2.0.9))))) | |
175 | (let-values (((remove install upgrade downgrade) | |
176 | (manifest-transaction-effects m0 t))) | |
177 | (and (null? remove) (null? install) (null? downgrade) | |
178 | (equal? (list (cons guile-2.0.9 guile-2.0.9)) upgrade))))) | |
179 | ||
ebf5ad46 LC |
180 | (test-assertm "profile-derivation" |
181 | (mlet* %store-monad | |
182 | ((entry -> (package->manifest-entry %bootstrap-guile)) | |
183 | (guile (package->derivation %bootstrap-guile)) | |
184 | (drv (profile-derivation (manifest (list entry)) | |
6d0b9d03 LC |
185 | #:info-dir? #f |
186 | #:ca-certificate-bundle? #f)) | |
ebf5ad46 LC |
187 | (profile -> (derivation->output-path drv)) |
188 | (bindir -> (string-append profile "/bin")) | |
189 | (_ (built-derivations (list drv)))) | |
190 | (return (and (file-exists? (string-append bindir "/guile")) | |
191 | (string=? (dirname (readlink bindir)) | |
192 | (derivation->output-path guile)))))) | |
462f5cca | 193 | |
a2078770 LC |
194 | (test-end "profiles") |
195 | ||
196 | \f | |
197 | (exit (= (test-runner-fail-count (test-runner-current)) 0)) | |
198 | ||
199 | ;;; Local Variables: | |
200 | ;;; eval: (put 'dummy-package 'scheme-indent-function 1) | |
201 | ;;; End: |