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