gnu: Add bullet.
[jackhill/guix/guix.git] / tests / profiles.scm
CommitLineData
a2078770 1;;; GNU Guix --- Functional package management for GNU
a54c94a4 2;;; Copyright © 2013, 2014 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
LC
37
38;; Example manifest entries.
39
f7554030
AK
40(define guile-1.8.8
41 (manifest-entry
42 (name "guile")
43 (version "1.8.8")
44 (item "/gnu/store/...")
45 (output "out")))
46
a2078770
LC
47(define guile-2.0.9
48 (manifest-entry
49 (name "guile")
50 (version "2.0.9")
a54c94a4 51 (item "/gnu/store/...")
a2078770
LC
52 (output "out")))
53
54(define guile-2.0.9:debug
55 (manifest-entry (inherit guile-2.0.9)
56 (output "debug")))
57
79601521
LC
58(define glibc
59 (manifest-entry
60 (name "glibc")
61 (version "2.19")
62 (item "/gnu/store/...")
63 (output "out")))
64
a2078770
LC
65\f
66(test-begin "profiles")
67
68(test-assert "manifest-installed?"
69 (let ((m (manifest (list guile-2.0.9 guile-2.0.9:debug))))
70 (and (manifest-installed? m (manifest-pattern (name "guile")))
71 (manifest-installed? m (manifest-pattern
72 (name "guile") (output "debug")))
73 (manifest-installed? m (manifest-pattern
74 (name "guile") (output "out")
75 (version "2.0.9")))
76 (not (manifest-installed?
77 m (manifest-pattern (name "guile") (version "1.8.8"))))
78 (not (manifest-installed?
79 m (manifest-pattern (name "guile") (output "foobar")))))))
80
81(test-assert "manifest-matching-entries"
82 (let* ((e (list guile-2.0.9 guile-2.0.9:debug))
83 (m (manifest e)))
84 (and (null? (manifest-matching-entries m
85 (list (manifest-pattern
86 (name "python")))))
87 (equal? e
88 (manifest-matching-entries m
89 (list (manifest-pattern
90 (name "guile")
91 (output #f)))))
92 (equal? (list guile-2.0.9)
93 (manifest-matching-entries m
94 (list (manifest-pattern
95 (name "guile")
96 (version "2.0.9"))))))))
97
98(test-assert "manifest-remove"
99 (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug)))
100 (m1 (manifest-remove m0
101 (list (manifest-pattern (name "guile")))))
102 (m2 (manifest-remove m1
103 (list (manifest-pattern (name "guile"))))) ; same
104 (m3 (manifest-remove m2
105 (list (manifest-pattern
106 (name "guile") (output "debug")))))
107 (m4 (manifest-remove m3
108 (list (manifest-pattern (name "guile"))))))
109 (match (manifest-entries m2)
110 ((($ <manifest-entry> "guile" "2.0.9" "debug"))
111 (and (equal? m1 m2)
112 (null? (manifest-entries m3))
113 (null? (manifest-entries m4)))))))
114
f7554030
AK
115(test-assert "manifest-add"
116 (let* ((m0 (manifest '()))
117 (m1 (manifest-add m0 (list guile-1.8.8)))
118 (m2 (manifest-add m1 (list guile-2.0.9)))
119 (m3 (manifest-add m2 (list guile-2.0.9:debug)))
120 (m4 (manifest-add m3 (list guile-2.0.9:debug))))
121 (and (match (manifest-entries m1)
122 ((($ <manifest-entry> "guile" "1.8.8" "out")) #t)
123 (_ #f))
124 (match (manifest-entries m2)
125 ((($ <manifest-entry> "guile" "2.0.9" "out")) #t)
126 (_ #f))
127 (equal? m3 m4))))
128
343745c8
AK
129(test-assert "manifest-perform-transaction"
130 (let* ((m0 (manifest (list guile-2.0.9 guile-2.0.9:debug)))
131 (t1 (manifest-transaction
132 (install (list guile-1.8.8))
133 (remove (list (manifest-pattern (name "guile")
134 (output "debug"))))))
135 (t2 (manifest-transaction
136 (remove (list (manifest-pattern (name "guile")
137 (version "2.0.9")
138 (output #f))))))
139 (m1 (manifest-perform-transaction m0 t1))
140 (m2 (manifest-perform-transaction m1 t2))
141 (m3 (manifest-perform-transaction m0 t2)))
142 (and (match (manifest-entries m1)
143 ((($ <manifest-entry> "guile" "1.8.8" "out")) #t)
144 (_ #f))
145 (equal? m1 m2)
146 (null? (manifest-entries m3)))))
147
79601521
LC
148(test-assert "manifest-transaction-effects"
149 (let* ((m0 (manifest (list guile-1.8.8)))
150 (t (manifest-transaction
151 (install (list guile-2.0.9 glibc))
152 (remove (list (manifest-pattern (name "coreutils")))))))
153 (let-values (((remove install upgrade)
154 (manifest-transaction-effects m0 t)))
155 (and (null? remove)
156 (equal? (list glibc) install)
ef8993e2
LC
157 (equal? (list (cons guile-1.8.8 guile-2.0.9)) upgrade)))))
158
462f5cca
LC
159(test-assert "profile-derivation"
160 (run-with-store %store
161 (mlet* %store-monad
162 ((entry -> (package->manifest-entry %bootstrap-guile))
163 (guile (package->derivation %bootstrap-guile))
79ee406d
LC
164 (drv (profile-derivation (manifest (list entry))
165 #:info-dir? #f))
462f5cca
LC
166 (profile -> (derivation->output-path drv))
167 (bindir -> (string-append profile "/bin"))
168 (_ (built-derivations (list drv))))
169 (return (and (file-exists? (string-append bindir "/guile"))
170 (string=? (dirname (readlink bindir))
171 (derivation->output-path guile)))))))
172
a2078770
LC
173(test-end "profiles")
174
175\f
176(exit (= (test-runner-fail-count (test-runner-current)) 0))
177
178;;; Local Variables:
179;;; eval: (put 'dummy-package 'scheme-indent-function 1)
180;;; End: