Commit | Line | Data |
---|---|---|
233e7676 | 1 | # GNU Guix --- Functional package management for GNU |
0fb40579 | 2 | # Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org> |
acc08466 | 3 | # Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org> |
0afdc485 | 4 | # |
233e7676 | 5 | # This file is part of GNU Guix. |
0afdc485 | 6 | # |
233e7676 | 7 | # GNU Guix is free software; you can redistribute it and/or modify it |
0afdc485 LC |
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 | # | |
233e7676 | 12 | # GNU Guix is distributed in the hope that it will be useful, but |
0afdc485 LC |
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 | |
233e7676 | 18 | # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
0afdc485 LC |
19 | |
20 | # | |
e49951eb | 21 | # Test the `guix package' command-line utility. |
0afdc485 LC |
22 | # |
23 | ||
e49951eb | 24 | guix package --version |
0afdc485 | 25 | |
24e262f0 LC |
26 | readlink_base () |
27 | { | |
28 | basename `readlink "$1"` | |
29 | } | |
30 | ||
e25234e3 | 31 | module_dir="t-guix-package-$$" |
0afdc485 | 32 | profile="t-profile-$$" |
db5a9444 LC |
33 | tmpfile="t-guix-package-file-$$" |
34 | rm -f "$profile" "$tmpfile" | |
0afdc485 | 35 | |
db5a9444 | 36 | trap 'rm -f "$profile" "$profile-"[0-9]* "$tmpfile"; rm -rf "$module_dir" t-home-'"$$" EXIT |
7a6548cb | 37 | |
5d4b411f LC |
38 | # Use `-e' with a non-package expression. |
39 | if guix package --bootstrap -e +; | |
40 | then false; else true; fi | |
41 | ||
aa042770 LC |
42 | # Install a store item and make sure the version and output in the manifest |
43 | # are correct. | |
44 | guix package --bootstrap -p "$profile" -i `guix build guile-bootstrap` | |
45 | test "`guix package -A guile-bootstrap | cut -f 1-2`" \ | |
46 | = "`guix package -p "$profile" -I | cut -f 1-2`" | |
47 | test "`guix package -p "$profile" -I | cut -f 3`" = "out" | |
48 | rm "$profile" | |
49 | ||
e49951eb | 50 | guix package --bootstrap -p "$profile" -i guile-bootstrap |
0afdc485 LC |
51 | test -L "$profile" && test -L "$profile-1-link" |
52 | test -f "$profile/bin/guile" | |
53 | ||
d2952326 LC |
54 | # Make sure the profile is a GC root. |
55 | guix gc --list-live | grep "`readlink "$profile-1-link"`" | |
56 | ||
1c67d639 | 57 | # Installing the same package a second time does nothing. |
e49951eb | 58 | guix package --bootstrap -p "$profile" -i guile-bootstrap |
1c67d639 LC |
59 | test -L "$profile" && test -L "$profile-1-link" |
60 | ! test -f "$profile-2-link" | |
61 | test -f "$profile/bin/guile" | |
0afdc485 | 62 | |
477ee222 LC |
63 | # Collisions are properly flagged (in this case, 'g-wrap' propagates |
64 | # guile@2.2, which conflicts with guile@2.0.) | |
65 | if guix package --bootstrap -n -p "$profile" -i g-wrap guile@2.0 | |
fc95dc4c LC |
66 | then false; else true; fi |
67 | ||
477ee222 | 68 | guix package --bootstrap -n -p "$profile" -i g-wrap guile@2.0 \ |
fc95dc4c LC |
69 | --allow-collisions |
70 | ||
5924080d | 71 | # No search path env. var. here. |
dbc31ab2 LC |
72 | guix package -p "$profile" --search-paths |
73 | guix package -p "$profile" --search-paths | grep '^export PATH=' | |
74 | test "`guix package -p "$profile" --search-paths | wc -l`" = 1 # $PATH | |
75 | ( set -e; set -x; \ | |
76 | eval `guix package --search-paths=prefix -p "$PWD/$profile"`; \ | |
77 | test "`type -P guile`" = "$PWD/$profile/bin/guile" ; \ | |
78 | type -P rm ) | |
5924080d | 79 | |
57b86237 LC |
80 | # Exit with 1 when a generation does not exist. |
81 | if guix package -p "$profile" --delete-generations=42; | |
82 | then false; else true; fi | |
83 | ||
84 | # Exit with 0 when trying to delete the zeroth generation. | |
85 | guix package -p "$profile" --delete-generations=0 | |
0afdc485 | 86 | |
6447738c MW |
87 | # Make sure multiple arguments to -i works. |
88 | guix package --bootstrap -i guile gcc -p "$profile" -n | |
89 | ||
9518856b | 90 | # Make sure the `:' syntax works. |
ecb1b610 | 91 | guix package --bootstrap -i "glibc:debug" -p "$profile" -n |
9518856b | 92 | |
aa92cf98 | 93 | # Make sure nonexistent outputs are reported. |
e49951eb MW |
94 | guix package --bootstrap -i "guile-bootstrap:out" -p "$profile" -n |
95 | if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile" -n; | |
aa92cf98 | 96 | then false; else true; fi |
e49951eb | 97 | if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile"; |
aa92cf98 LC |
98 | then false; else true; fi |
99 | ||
64fc89b6 | 100 | # Check whether `--list-available' returns something sensible. |
03f4ef28 | 101 | guix package -p "$profile" -A 'gui.*e' | grep guile |
64fc89b6 | 102 | |
2aa6efb0 | 103 | # Check whether `--show' returns something sensible. |
3ce9aa44 | 104 | guix package --show=guile | grep "^name: guile" |
2aa6efb0 | 105 | |
1b0a86dd | 106 | # Ensure `--show' doesn't fail for packages with non-package inputs. |
5e6feee6 EB |
107 | guix package --show=texlive |
108 | ||
65216315 LC |
109 | # Fail for non-existent packages or package/version pairs. |
110 | if guix package --show=does-not-exist; then false; else true; fi | |
111 | if guix package --show=emacs@42; then false; else true; fi | |
112 | ||
1b0a86dd LC |
113 | # Search. |
114 | LC_MESSAGES=C | |
115 | export LC_MESSAGES | |
116 | test "`guix package -s "An example GNU package" | grep ^name:`" = \ | |
117 | "name: hello" | |
118 | test -z "`guix package -s "n0t4r341p4ck4g3"`" | |
119 | ||
db5a9444 LC |
120 | # Search with one and then two regexps. |
121 | # First we get printed circuit boards *and* board games. | |
122 | guix package -s '\<board\>' > "$tmpfile" | |
123 | grep '^name: pcb' "$tmpfile" | |
124 | grep '^name: gnubg' "$tmpfile" | |
125 | ||
126 | # Second we get only board games. | |
127 | guix package -s '\<board\>' -s game > "$tmpfile" | |
128 | grep -v '^name: pcb' "$tmpfile" > /dev/null | |
129 | grep '^name: gnubg' "$tmpfile" | |
130 | ||
131 | rm -f "$tmpfile" | |
132 | ||
0fb40579 LC |
133 | # Make sure deprecated packages don't show up: <https://bugs.gnu.org/30566>. |
134 | mkdir "$module_dir" | |
135 | cat > "$module_dir/foo.scm"<<EOF | |
136 | (define-module (foo) | |
137 | #:use-module (guix packages) | |
138 | #:use-module (gnu packages base)) | |
139 | ||
140 | (define-public deprecated | |
141 | (deprecated-package "fileutils" coreutils)) | |
142 | EOF | |
143 | ||
144 | guix build -L "$module_dir" -e '(@ (foo) deprecated)' -n | |
145 | test "`guix package -L "$module_dir" -s ^fileutils$ | grep ^name:`" = "" | |
146 | ||
147 | rm -rf "$module_dir" | |
148 | ||
1b0a86dd LC |
149 | # Make sure `--search' can display all the packages. |
150 | guix package --search="" > /dev/null | |
151 | ||
d7ddb257 LC |
152 | # There's no generation older than 12 months, so the following command should |
153 | # have no effect. | |
154 | generation="`readlink_base "$profile"`" | |
155 | if guix package -p "$profile" --delete-generations=12m; | |
156 | then false; else true; fi | |
157 | test "`readlink_base "$profile"`" = "$generation" | |
158 | ||
d26eb84d LC |
159 | # The following command should not delete the current generation, even though |
160 | # it matches the given pattern (see <http://bugs.gnu.org/19978>.) And since | |
161 | # there's nothing else to delete, it should just fail. | |
162 | guix package --list-generations -p "$profile" | |
163 | if guix package --bootstrap -p "$profile" --delete-generations=1.. | |
164 | then false; else true; fi | |
165 | test "`readlink_base "$profile"`" = "$generation" | |
166 | ||
c9323a4c LC |
167 | # Make sure $profile is a GC root at this point. |
168 | real_profile="`readlink -f "$profile"`" | |
169 | if guix gc -d "$real_profile" | |
170 | then false; else true; fi | |
171 | test -d "$real_profile" | |
172 | ||
173 | # Now, let's remove all the symlinks to $real_profile, and make sure | |
174 | # $real_profile is no longer a GC root. | |
175 | rm "$profile" "$profile"-[0-9]-link | |
176 | guix gc -d "$real_profile" | |
177 | [ ! -d "$real_profile" ] | |
178 | ||
494dc2fc LC |
179 | # Package transformations. |
180 | ||
181 | # Make sure we get the right version number when using '--with-source'. | |
182 | mkdir "$module_dir" | |
183 | emacs_tarball="$module_dir/emacs-42.5.9rc7.tar.gz" | |
184 | touch "$emacs_tarball" | |
185 | guix package -p "$profile" -i emacs --with-source="$emacs_tarball" -n \ | |
186 | 2> "$tmpfile" | |
187 | grep -E 'emacs[[:blank:]]+42\.5\.9rc7[[:blank:]]+.*-emacs-42.5.9rc7' \ | |
188 | "$tmpfile" | |
189 | rm "$emacs_tarball" "$tmpfile" | |
190 | rmdir "$module_dir" | |
191 | ||
bc6e291e LC |
192 | # Profiles with a relative file name. Make sure we don't create dangling |
193 | # symlinks--see bug report at | |
194 | # <https://lists.gnu.org/archive/html/guix-devel/2018-07/msg00036.html>. | |
195 | mkdir -p "$module_dir/foo" | |
196 | ( cd "$module_dir" ; \ | |
197 | guix package --bootstrap -i guile-bootstrap -p foo/prof ) | |
198 | test -f "$module_dir/foo/prof/bin/guile" | |
199 | rm "$module_dir/foo"/* | |
200 | rmdir "$module_dir/foo" | |
201 | rmdir "$module_dir" | |
494dc2fc | 202 | |
67668155 | 203 | # |
0ec1af59 | 204 | # Try with the default profile. |
67668155 | 205 | # |
0ec1af59 LC |
206 | |
207 | XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}" | |
208 | export XDG_CACHE_HOME | |
88371f0d | 209 | HOME="$PWD/t-home-$$" |
0ec1af59 LC |
210 | export HOME |
211 | ||
212 | mkdir -p "$HOME" | |
213 | ||
59c51be2 LC |
214 | # Get the canonical directory name so that 'guix package' recognizes it. |
215 | HOME="`cd $HOME; pwd -P`" | |
216 | ||
e49951eb | 217 | guix package --bootstrap -i guile-bootstrap |
0ec1af59 LC |
218 | test -L "$HOME/.guix-profile" |
219 | test -f "$HOME/.guix-profile/bin/guile" | |
24e262f0 | 220 | |
d9307267 LC |
221 | # Move to the empty profile. |
222 | default_profile="`readlink "$HOME/.guix-profile"`" | |
223 | for i in `seq 1 3` | |
224 | do | |
d2952326 LC |
225 | # Make sure the current generation is a GC root. |
226 | profile_link="`readlink "$default_profile"`" | |
227 | guix gc --list-live | grep "`readlink "$profile_link"`" | |
228 | ||
e49951eb | 229 | guix package --bootstrap --roll-back |
d9307267 LC |
230 | ! test -f "$HOME/.guix-profile/bin" |
231 | ! test -f "$HOME/.guix-profile/lib" | |
bc6e291e | 232 | test "`readlink "$default_profile"`" = "`basename $default_profile-0-link`" |
d9307267 | 233 | done |
3b9c0020 | 234 | |
88371f0d LC |
235 | # Check whether '-p ~/.guix-profile' makes any difference. |
236 | # See <http://bugs.gnu.org/17939>. | |
237 | if test -e "$HOME/.guix-profile-0-link"; then false; fi | |
238 | if test -e "$HOME/.guix-profile-1-link"; then false; fi | |
239 | guix package --bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap | |
240 | if test -e "$HOME/.guix-profile-1-link"; then false; fi | |
241 | guix package --bootstrap --roll-back -p "$HOME/.guix-profile" | |
242 | if test -e "$HOME/.guix-profile-0-link"; then false; fi | |
243 | ||
3b9c0020 | 244 | # Extraneous argument. |
e49951eb | 245 | if guix package install foo-bar; |
aa92cf98 | 246 | then false; else true; fi |
1a43e4dc LC |
247 | |
248 | # Make sure the "broken pipe" doesn't yield an error. | |
249 | # Note: 'pipefail' is a Bash-specific option. | |
250 | set -o pipefail || true | |
251 | guix package -A g | head -1 2> "$HOME/err1" | |
252 | guix package -I | head -1 2> "$HOME/err2" | |
253 | test "`cat "$HOME/err1" "$HOME/err2"`" = "" | |
300868ba LC |
254 | |
255 | # Make sure '-L' extends the package module search path. | |
300868ba | 256 | mkdir "$module_dir" |
300868ba LC |
257 | |
258 | cat > "$module_dir/foo.scm"<<EOF | |
259 | (define-module (foo) | |
260 | #:use-module (guix packages) | |
261 | #:use-module (gnu packages emacs)) | |
262 | ||
263 | (define-public x | |
264 | (package (inherit emacs) | |
265 | (name "emacs-foo-bar") | |
266 | (version "42"))) | |
267 | EOF | |
268 | ||
269 | guix package -A emacs-foo-bar -L "$module_dir" | grep 42 | |
1b846da8 | 270 | guix package -i emacs-foo-bar@42 -n -L "$module_dir" |
8689901f LC |
271 | |
272 | # Same thing using the 'GUIX_PACKAGE_PATH' environment variable. | |
273 | GUIX_PACKAGE_PATH="$module_dir" | |
274 | export GUIX_PACKAGE_PATH | |
275 | guix package -A emacs-foo-bar | grep 42 | |
1b846da8 | 276 | guix package -i emacs-foo-bar@42 -n |
ee06af5b LC |
277 | |
278 | # Make sure patches that live under $GUIX_PACKAGE_PATH are found. | |
279 | cat > "$module_dir/emacs.patch"<<EOF | |
280 | This is a fake patch. | |
281 | EOF | |
282 | cat > "$module_dir/foo.scm"<<EOF | |
283 | (define-module (foo) | |
284 | #:use-module (guix packages) | |
285 | #:use-module (gnu packages) | |
286 | #:use-module (gnu packages emacs)) | |
287 | ||
288 | (define-public x | |
289 | (package (inherit emacs) | |
290 | (source (origin (inherit (package-source emacs)) | |
291 | (patches (list (search-patch "emacs.patch"))))) | |
292 | (name "emacs-foo-bar-patched") | |
293 | (version "42"))) | |
5763ad92 LC |
294 | |
295 | (define-public y | |
296 | (package (inherit emacs) | |
297 | (name "super-non-portable-emacs") | |
298 | (supported-systems '("foobar64-hurd")))) | |
ee06af5b LC |
299 | EOF |
300 | guix package -i emacs-foo-bar-patched -n | |
301 | ||
223d7939 LC |
302 | # Same when -L is used. |
303 | ( unset GUIX_PACKAGE_PATH; \ | |
304 | guix package -L "$module_dir" -i emacs-foo-bar-patched -n ) | |
305 | ||
0d279400 DT |
306 | # Make sure installing from a file works. |
307 | cat > "$module_dir/package.scm"<<EOF | |
308 | (use-modules (gnu)) | |
309 | (use-package-modules bootstrap) | |
310 | ||
311 | %bootstrap-guile | |
312 | EOF | |
313 | guix package --bootstrap --install-from-file="$module_dir/package.scm" | |
314 | ||
5763ad92 LC |
315 | # This one should not show up in searches since it's no supported on the |
316 | # current system. | |
317 | test "`guix package -A super-non-portable-emacs`" = "" | |
318 | test "`guix package -s super-non-portable-emacs | grep ^systems:`" = "systems: " | |
319 | ||
fc8fdcf5 LC |
320 | # Don't upgrade packages marked for removal: <http://bugs.gnu.org/27262>. |
321 | guix package --bootstrap -p "$profile" -i guile-bootstrap | |
322 | ||
323 | cat > "$module_dir/foo.scm"<<EOF | |
324 | (define-module (foo) | |
325 | #:use-module (guix) | |
326 | #:use-module (gnu packages bootstrap)) | |
327 | ||
328 | (define-public x | |
329 | (package (inherit %bootstrap-guile) (version "42"))) | |
330 | EOF | |
331 | ||
332 | guix package --bootstrap -p "$profile" -r guile-bootstrap -u guile | |
333 | test ! -f "$profile/bin/guile" | |
334 | guix package --bootstrap -p "$profile" --roll-back | |
335 | test -f "$profile/bin/guile" | |
336 | rm "$profile-2-link" | |
337 | ||
847391fe DP |
338 | unset GUIX_PACKAGE_PATH |
339 | ||
fc8fdcf5 | 340 | |
847391fe | 341 | # Using 'GUIX_BUILD_OPTIONS'. |
847391fe | 342 | available="`guix package -A | sort`" |
442a6ff5 | 343 | GUIX_BUILD_OPTIONS="--dry-run --no-grafts" |
847391fe DP |
344 | export GUIX_BUILD_OPTIONS |
345 | ||
346 | # Make sure $GUIX_BUILD_OPTIONS is not simply appended to the command-line, | |
347 | # which would break 'guix package -A' and similar. | |
348 | available2="`guix package -A | sort`" | |
349 | test "$available2" = "$available" | |
350 | guix package -I | |
1b676447 | 351 | |
442a6ff5 LC |
352 | # Restore '--no-grafts', which makes sure we don't end up building stuff when |
353 | # '--dry-run' is passed. | |
354 | GUIX_BUILD_OPTIONS="--no-grafts" | |
1b676447 | 355 | |
5f1087c4 | 356 | # Applying a manifest file. |
1b676447 DT |
357 | cat > "$module_dir/manifest.scm"<<EOF |
358 | (use-package-modules bootstrap) | |
359 | ||
360 | (packages->manifest (list %bootstrap-guile)) | |
361 | EOF | |
362 | guix package --bootstrap -m "$module_dir/manifest.scm" | |
363 | guix package -I | grep guile | |
364 | test `guix package -I | wc -l` -eq 1 | |
811b21fb LC |
365 | guix package --rollback --bootstrap |
366 | ||
367 | # Applying a manifest file with inferior packages. | |
368 | cat > "$module_dir/manifest.scm"<<EOF | |
369 | (use-modules (guix inferior)) | |
370 | ||
371 | (define i | |
372 | (open-inferior "$abs_top_srcdir" #:command "scripts/guix")) | |
373 | ||
374 | (let ((guile (car (lookup-inferior-packages i "guile-bootstrap")))) | |
375 | (packages->manifest (list guile))) | |
376 | EOF | |
377 | guix package --bootstrap -m "$module_dir/manifest.scm" | |
378 | guix package -I | grep guile | |
379 | test `guix package -I | wc -l` -eq 1 | |
5f1087c4 LC |
380 | |
381 | # Error reporting. | |
382 | cat > "$module_dir/manifest.scm"<<EOF | |
383 | (use-package-modules bootstrap) | |
384 | (packages->manifest | |
385 | (list %bootstrap-guile | |
386 | wonderful-package-that-does-not-exist)) | |
387 | EOF | |
388 | if guix package --bootstrap -n -m "$module_dir/manifest.scm" \ | |
389 | 2> "$module_dir/stderr" | |
390 | then false | |
391 | else | |
392 | cat "$module_dir/stderr" | |
ae0307f7 | 393 | grep "manifest.scm:[1-3]:.*wonderful-package.*: unbound variable" \ |
5f1087c4 LC |
394 | "$module_dir/stderr" |
395 | fi |