gnu: surgescript: Update to 0.5.4.4.
[jackhill/guix/guix.git] / tests / inferior.scm
CommitLineData
2ca299ca 1;;; GNU Guix --- Functional package management for GNU
f7537e30 2;;; Copyright © 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
2ca299ca
LC
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (test-inferior)
9daf046c 20 #:use-module (guix tests)
2ca299ca
LC
21 #:use-module (guix inferior)
22 #:use-module (guix packages)
9daf046c 23 #:use-module (guix store)
2e6d64e1 24 #:use-module (guix profiles)
9daf046c 25 #:use-module (guix derivations)
2ca299ca 26 #:use-module (gnu packages)
9daf046c 27 #:use-module (gnu packages bootstrap)
6030396a 28 #:use-module (gnu packages guile)
2ca299ca 29 #:use-module (srfi srfi-1)
71507435 30 #:use-module (srfi srfi-34)
6030396a
LC
31 #:use-module (srfi srfi-64)
32 #:use-module (ice-9 match))
2ca299ca
LC
33
34(define %top-srcdir
35 (dirname (search-path %load-path "guix.scm")))
36
37(define %top-builddir
38 (dirname (search-path %load-compiled-path "guix.go")))
39
9daf046c
LC
40(define %store
41 (open-connection-for-tests))
42
2e6d64e1
LC
43(define (manifest-entry->list entry)
44 (list (manifest-entry-name entry)
45 (manifest-entry-version entry)
46 (manifest-entry-output entry)
47 (manifest-entry-search-paths entry)
48 (map manifest-entry->list (manifest-entry-dependencies entry))))
49
2ca299ca
LC
50\f
51(test-begin "inferior")
52
53(test-equal "open-inferior"
54 '(42 #t)
55 (let ((inferior (open-inferior %top-builddir
56 #:command "scripts/guix")))
57 (and (inferior? inferior)
58 (let ((a (inferior-eval '(apply * '(6 7)) inferior))
59 (b (inferior-eval '(@ (gnu packages base) coreutils)
60 inferior)))
61 (close-inferior inferior)
62 (list a (inferior-object? b))))))
63
f7537e30
LC
64(test-equal "&inferior-exception"
65 '(a b c d)
66 (let ((inferior (open-inferior %top-builddir
67 #:command "scripts/guix")))
68 (guard (c ((inferior-exception? c)
69 (close-inferior inferior)
70 (and (eq? inferior (inferior-exception-inferior c))
1dca6aaa
LC
71 (match (inferior-exception-stack c)
72 (((_ (files lines columns)) ..1)
73 (member "guix/repl.scm" files)))
f7537e30
LC
74 (inferior-exception-arguments c))))
75 (inferior-eval '(throw 'a 'b 'c 'd) inferior)
76 'badness)))
77
2ca299ca
LC
78(test-equal "inferior-packages"
79 (take (sort (fold-packages (lambda (package lst)
7e1d2290 80 (cons (list (package-name package)
2ca299ca 81 (package-version package)
7e1d2290
LC
82 (package-home-page package)
83 (package-location package))
84 lst))
2ca299ca
LC
85 '())
86 (lambda (x y)
87 (string<? (car x) (car y))))
88 10)
89 (let* ((inferior (open-inferior %top-builddir
90 #:command "scripts/guix"))
91 (packages (inferior-packages inferior)))
92 (and (every string? (map inferior-package-synopsis packages))
7e1d2290
LC
93 (let ()
94 (define result
95 (take (sort (map (lambda (package)
96 (list (inferior-package-name package)
97 (inferior-package-version package)
98 (inferior-package-home-page package)
99 (inferior-package-location package)))
100 packages)
101 (lambda (x y)
102 (string<? (car x) (car y))))
103 10))
2ca299ca 104 (close-inferior inferior)
7e1d2290 105 result))))
2ca299ca 106
73938054
LC
107(test-equal "inferior-available-packages"
108 (take (sort (fold-available-packages
109 (lambda* (name version result
110 #:key supported? deprecated?
111 #:allow-other-keys)
112 (if (and supported? (not deprecated?))
113 (alist-cons name version result)
114 result))
115 '())
116 (lambda (x y)
117 (string<? (car x) (car y))))
118 10)
119 (let* ((inferior (open-inferior %top-builddir
120 #:command "scripts/guix"))
121 (packages (inferior-available-packages inferior)))
122 (close-inferior inferior)
123 (take (sort packages (lambda (x y)
124 (string<? (car x) (car y))))
125 10)))
126
e1a4ffda
LC
127(test-equal "lookup-inferior-packages"
128 (let ((->list (lambda (package)
129 (list (package-name package)
130 (package-version package)
131 (package-location package)))))
132 (list (map ->list (find-packages-by-name "guile" #f))
133 (map ->list (find-packages-by-name "guile" "2.2"))))
134 (let* ((inferior (open-inferior %top-builddir
135 #:command "scripts/guix"))
136 (->list (lambda (package)
137 (list (inferior-package-name package)
138 (inferior-package-version package)
139 (inferior-package-location package))))
140 (lst1 (map ->list
141 (lookup-inferior-packages inferior "guile")))
142 (lst2 (map ->list
143 (lookup-inferior-packages inferior
144 "guile" "2.2"))))
145 (close-inferior inferior)
146 (list lst1 lst2)))
147
148(test-assert "lookup-inferior-packages and eq?-ness"
149 (let* ((inferior (open-inferior %top-builddir
150 #:command "scripts/guix"))
151 (lst1 (lookup-inferior-packages inferior "guile"))
152 (lst2 (lookup-inferior-packages inferior "guile")))
153 (close-inferior inferior)
154 (every eq? lst1 lst2)))
155
6030396a
LC
156(test-equal "inferior-package-inputs"
157 (let ((->list (match-lambda
158 ((label (? package? package) . rest)
159 `(,label
160 (package ,(package-name package)
161 ,(package-version package)
162 ,(package-location package))
163 ,@rest)))))
164 (list (map ->list (package-inputs guile-2.2))
165 (map ->list (package-native-inputs guile-2.2))
166 (map ->list (package-propagated-inputs guile-2.2))))
167 (let* ((inferior (open-inferior %top-builddir
168 #:command "scripts/guix"))
169 (guile (first (lookup-inferior-packages inferior "guile")))
170 (->list (match-lambda
171 ((label (? inferior-package? package) . rest)
172 `(,label
173 (package ,(inferior-package-name package)
174 ,(inferior-package-version package)
175 ,(inferior-package-location package))
176 ,@rest))))
177 (result (list (map ->list (inferior-package-inputs guile))
178 (map ->list
179 (inferior-package-native-inputs guile))
180 (map ->list
181 (inferior-package-propagated-inputs
182 guile)))))
183 (close-inferior inferior)
184 result))
185
eee8b303 186(test-equal "inferior-package-search-paths"
9d0c2c6e 187 (package-native-search-paths guile-3.0)
eee8b303
LC
188 (let* ((inferior (open-inferior %top-builddir
189 #:command "scripts/guix"))
190 (guile (first (lookup-inferior-packages inferior "guile")))
191 (result (inferior-package-native-search-paths guile)))
192 (close-inferior inferior)
193 result))
194
94c0e61f
LC
195(test-equal "inferior-eval-with-store"
196 (add-text-to-store %store "foo" "Hello, world!")
197 (let* ((inferior (open-inferior %top-builddir
198 #:command "scripts/guix")))
199 (inferior-eval-with-store inferior %store
200 '(lambda (store)
201 (add-text-to-store store "foo"
202 "Hello, world!")))))
203
71507435
LC
204(test-assert "inferior-eval-with-store, &store-protocol-error"
205 (let* ((inferior (open-inferior %top-builddir
206 #:command "scripts/guix")))
207 (guard (c ((store-protocol-error? c)
208 (string-contains (store-protocol-error-message c)
209 "invalid character")))
210 (inferior-eval-with-store inferior %store
211 '(lambda (store)
212 (add-text-to-store store "we|rd/?!@"
213 "uh uh")))
214 #f)))
215
9daf046c
LC
216(test-equal "inferior-package-derivation"
217 (map derivation-file-name
218 (list (package-derivation %store %bootstrap-guile "x86_64-linux")
219 (package-derivation %store %bootstrap-guile "armhf-linux")))
220 (let* ((inferior (open-inferior %top-builddir
221 #:command "scripts/guix"))
222 (packages (inferior-packages inferior))
223 (guile (find (lambda (package)
224 (string=? (package-name %bootstrap-guile)
225 (inferior-package-name package)))
226 packages)))
227 (map derivation-file-name
228 (list (inferior-package-derivation %store guile "x86_64-linux")
229 (inferior-package-derivation %store guile "armhf-linux")))))
230
2e6d64e1
LC
231(test-equal "inferior-package->manifest-entry"
232 (manifest-entry->list (package->manifest-entry
233 (first (find-best-packages-by-name "guile" #f))))
234 (let* ((inferior (open-inferior %top-builddir
235 #:command "scripts/guix"))
236 (guile (first (lookup-inferior-packages inferior "guile")))
237 (entry (inferior-package->manifest-entry guile)))
238 (close-inferior inferior)
239 (manifest-entry->list entry)))
240
811b21fb
LC
241(test-equal "packages->manifest"
242 (map manifest-entry->list
243 (manifest-entries (packages->manifest
244 (find-best-packages-by-name "guile" #f))))
245 (let* ((inferior (open-inferior %top-builddir
246 #:command "scripts/guix"))
247 (guile (first (lookup-inferior-packages inferior "guile")))
248 (manifest (packages->manifest (list guile))))
249 (close-inferior inferior)
250 (map manifest-entry->list (manifest-entries manifest))))
251
2ca299ca 252(test-end "inferior")