import: cpan: Gracefully handle missing projects.
[jackhill/guix/guix.git] / tests / inferior.scm
CommitLineData
2ca299ca 1;;; GNU Guix --- Functional package management for GNU
73938054 2;;; Copyright © 2018, 2019 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
64(test-equal "inferior-packages"
65 (take (sort (fold-packages (lambda (package lst)
7e1d2290 66 (cons (list (package-name package)
2ca299ca 67 (package-version package)
7e1d2290
LC
68 (package-home-page package)
69 (package-location package))
70 lst))
2ca299ca
LC
71 '())
72 (lambda (x y)
73 (string<? (car x) (car y))))
74 10)
75 (let* ((inferior (open-inferior %top-builddir
76 #:command "scripts/guix"))
77 (packages (inferior-packages inferior)))
78 (and (every string? (map inferior-package-synopsis packages))
7e1d2290
LC
79 (let ()
80 (define result
81 (take (sort (map (lambda (package)
82 (list (inferior-package-name package)
83 (inferior-package-version package)
84 (inferior-package-home-page package)
85 (inferior-package-location package)))
86 packages)
87 (lambda (x y)
88 (string<? (car x) (car y))))
89 10))
2ca299ca 90 (close-inferior inferior)
7e1d2290 91 result))))
2ca299ca 92
73938054
LC
93(test-equal "inferior-available-packages"
94 (take (sort (fold-available-packages
95 (lambda* (name version result
96 #:key supported? deprecated?
97 #:allow-other-keys)
98 (if (and supported? (not deprecated?))
99 (alist-cons name version result)
100 result))
101 '())
102 (lambda (x y)
103 (string<? (car x) (car y))))
104 10)
105 (let* ((inferior (open-inferior %top-builddir
106 #:command "scripts/guix"))
107 (packages (inferior-available-packages inferior)))
108 (close-inferior inferior)
109 (take (sort packages (lambda (x y)
110 (string<? (car x) (car y))))
111 10)))
112
e1a4ffda
LC
113(test-equal "lookup-inferior-packages"
114 (let ((->list (lambda (package)
115 (list (package-name package)
116 (package-version package)
117 (package-location package)))))
118 (list (map ->list (find-packages-by-name "guile" #f))
119 (map ->list (find-packages-by-name "guile" "2.2"))))
120 (let* ((inferior (open-inferior %top-builddir
121 #:command "scripts/guix"))
122 (->list (lambda (package)
123 (list (inferior-package-name package)
124 (inferior-package-version package)
125 (inferior-package-location package))))
126 (lst1 (map ->list
127 (lookup-inferior-packages inferior "guile")))
128 (lst2 (map ->list
129 (lookup-inferior-packages inferior
130 "guile" "2.2"))))
131 (close-inferior inferior)
132 (list lst1 lst2)))
133
134(test-assert "lookup-inferior-packages and eq?-ness"
135 (let* ((inferior (open-inferior %top-builddir
136 #:command "scripts/guix"))
137 (lst1 (lookup-inferior-packages inferior "guile"))
138 (lst2 (lookup-inferior-packages inferior "guile")))
139 (close-inferior inferior)
140 (every eq? lst1 lst2)))
141
6030396a
LC
142(test-equal "inferior-package-inputs"
143 (let ((->list (match-lambda
144 ((label (? package? package) . rest)
145 `(,label
146 (package ,(package-name package)
147 ,(package-version package)
148 ,(package-location package))
149 ,@rest)))))
150 (list (map ->list (package-inputs guile-2.2))
151 (map ->list (package-native-inputs guile-2.2))
152 (map ->list (package-propagated-inputs guile-2.2))))
153 (let* ((inferior (open-inferior %top-builddir
154 #:command "scripts/guix"))
155 (guile (first (lookup-inferior-packages inferior "guile")))
156 (->list (match-lambda
157 ((label (? inferior-package? package) . rest)
158 `(,label
159 (package ,(inferior-package-name package)
160 ,(inferior-package-version package)
161 ,(inferior-package-location package))
162 ,@rest))))
163 (result (list (map ->list (inferior-package-inputs guile))
164 (map ->list
165 (inferior-package-native-inputs guile))
166 (map ->list
167 (inferior-package-propagated-inputs
168 guile)))))
169 (close-inferior inferior)
170 result))
171
eee8b303
LC
172(test-equal "inferior-package-search-paths"
173 (package-native-search-paths guile-2.2)
174 (let* ((inferior (open-inferior %top-builddir
175 #:command "scripts/guix"))
176 (guile (first (lookup-inferior-packages inferior "guile")))
177 (result (inferior-package-native-search-paths guile)))
178 (close-inferior inferior)
179 result))
180
94c0e61f
LC
181(test-equal "inferior-eval-with-store"
182 (add-text-to-store %store "foo" "Hello, world!")
183 (let* ((inferior (open-inferior %top-builddir
184 #:command "scripts/guix")))
185 (inferior-eval-with-store inferior %store
186 '(lambda (store)
187 (add-text-to-store store "foo"
188 "Hello, world!")))))
189
71507435
LC
190(test-assert "inferior-eval-with-store, &store-protocol-error"
191 (let* ((inferior (open-inferior %top-builddir
192 #:command "scripts/guix")))
193 (guard (c ((store-protocol-error? c)
194 (string-contains (store-protocol-error-message c)
195 "invalid character")))
196 (inferior-eval-with-store inferior %store
197 '(lambda (store)
198 (add-text-to-store store "we|rd/?!@"
199 "uh uh")))
200 #f)))
201
9daf046c
LC
202(test-equal "inferior-package-derivation"
203 (map derivation-file-name
204 (list (package-derivation %store %bootstrap-guile "x86_64-linux")
205 (package-derivation %store %bootstrap-guile "armhf-linux")))
206 (let* ((inferior (open-inferior %top-builddir
207 #:command "scripts/guix"))
208 (packages (inferior-packages inferior))
209 (guile (find (lambda (package)
210 (string=? (package-name %bootstrap-guile)
211 (inferior-package-name package)))
212 packages)))
213 (map derivation-file-name
214 (list (inferior-package-derivation %store guile "x86_64-linux")
215 (inferior-package-derivation %store guile "armhf-linux")))))
216
2e6d64e1
LC
217(test-equal "inferior-package->manifest-entry"
218 (manifest-entry->list (package->manifest-entry
219 (first (find-best-packages-by-name "guile" #f))))
220 (let* ((inferior (open-inferior %top-builddir
221 #:command "scripts/guix"))
222 (guile (first (lookup-inferior-packages inferior "guile")))
223 (entry (inferior-package->manifest-entry guile)))
224 (close-inferior inferior)
225 (manifest-entry->list entry)))
226
811b21fb
LC
227(test-equal "packages->manifest"
228 (map manifest-entry->list
229 (manifest-entries (packages->manifest
230 (find-best-packages-by-name "guile" #f))))
231 (let* ((inferior (open-inferior %top-builddir
232 #:command "scripts/guix"))
233 (guile (first (lookup-inferior-packages inferior "guile")))
234 (manifest (packages->manifest (list guile))))
235 (close-inferior inferior)
236 (map manifest-entry->list (manifest-entries manifest))))
237
2ca299ca 238(test-end "inferior")