guix package: Avoid 'exit' calls in 'delete-matching-generations'.
[jackhill/guix/guix.git] / tests / guix-package.sh
CommitLineData
233e7676 1# GNU Guix --- Functional package management for GNU
ee06af5b 2# Copyright © 2012, 2013, 2014, 2015 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
b69c5c2c
LC
31# Return true if a typical shebang in the store would not exceed Linux's
32# default static limit.
33shebang_not_too_long ()
34{
35 test `echo $NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash | wc -c` \
36 -lt 128
37}
38
e25234e3 39module_dir="t-guix-package-$$"
0afdc485
LC
40profile="t-profile-$$"
41rm -f "$profile"
42
c9323a4c 43trap 'rm -f "$profile" "$profile-"[0-9]* ; rm -rf "$module_dir" t-home-'"$$" EXIT
7a6548cb 44
5d4b411f
LC
45# Use `-e' with a non-package expression.
46if guix package --bootstrap -e +;
47then false; else true; fi
48
e49951eb 49guix package --bootstrap -p "$profile" -i guile-bootstrap
0afdc485
LC
50test -L "$profile" && test -L "$profile-1-link"
51test -f "$profile/bin/guile"
52
d2952326
LC
53# Make sure the profile is a GC root.
54guix gc --list-live | grep "`readlink "$profile-1-link"`"
55
1c67d639 56# Installing the same package a second time does nothing.
e49951eb 57guix package --bootstrap -p "$profile" -i guile-bootstrap
1c67d639
LC
58test -L "$profile" && test -L "$profile-1-link"
59! test -f "$profile-2-link"
60test -f "$profile/bin/guile"
0afdc485 61
5924080d
LC
62# No search path env. var. here.
63guix package --search-paths -p "$profile"
64test "`guix package --search-paths -p "$profile" | wc -l`" = 0
65
b69c5c2c
LC
66# Check whether we have network access and an acceptable shebang length.
67if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null \
68 && shebang_not_too_long
ad1ebab3 69then
bdb36958 70 boot_make="(@@ (gnu packages commencement) gnu-make-boot0)"
81b66f85 71 boot_make_drv="`guix build -e "$boot_make" | grep -v -e -debug`"
5d4b411f 72 guix package --bootstrap -p "$profile" -i "$boot_make_drv"
ad1ebab3
LC
73 test -L "$profile-2-link"
74 test -f "$profile/bin/make" && test -f "$profile/bin/guile"
0afdc485 75
733b4130 76
ad1ebab3
LC
77 # Check whether `--list-installed' works.
78 # XXX: Change the tests when `--install' properly extracts the package
79 # name and version string.
e49951eb 80 installed="`guix package -p "$profile" --list-installed | cut -f1 | xargs echo | sort`"
ad1ebab3 81 case "x$installed" in
6c1cd80d
NK
82 "guile-bootstrap make-boot0")
83 true;;
84 "make-boot0 guile-bootstrap")
85 true;;
86 "*")
ad1ebab3
LC
87 false;;
88 esac
733b4130 89
e49951eb 90 test "`guix package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap"
733b4130 91
2cd09108
NK
92 # List generations.
93 test "`guix package -p "$profile" -l | cut -f1 | grep guile | head -n1`" \
94 = " guile-bootstrap"
95
0ab212b9
NK
96 # Exit with 1 when a generation does not exist.
97 if guix package -p "$profile" --list-generations=42;
98 then false; else true; fi
b3bb82f1
AK
99 if guix package -p "$profile" --switch-generation=99;
100 then false; else true; fi
0ab212b9 101
ad1ebab3 102 # Remove a package.
e49951eb 103 guix package --bootstrap -p "$profile" -r "guile-bootstrap"
ad1ebab3
LC
104 test -L "$profile-3-link"
105 test -f "$profile/bin/make" && ! test -f "$profile/bin/guile"
24e262f0
LC
106
107 # Roll back.
e49951eb 108 guix package --roll-back -p "$profile"
24e262f0
LC
109 test "`readlink_base "$profile"`" = "$profile-2-link"
110 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
e49951eb 111 guix package --roll-back -p "$profile"
24e262f0
LC
112 test "`readlink_base "$profile"`" = "$profile-1-link"
113 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
114
b3bb82f1
AK
115 # Switch to the rolled generation and switch back.
116 guix package -p "$profile" --switch-generation=2
117 test "`readlink_base "$profile"`" = "$profile-2-link"
118 guix package -p "$profile" --switch-generation=-1
119 test "`readlink_base "$profile"`" = "$profile-1-link"
120
d9307267
LC
121 # Move to the empty profile.
122 for i in `seq 1 3`
123 do
6c1cd80d
NK
124 guix package --bootstrap --roll-back -p "$profile"
125 ! test -f "$profile/bin"
126 ! test -f "$profile/lib"
127 test "`readlink_base "$profile"`" = "$profile-0-link"
d9307267 128 done
24e262f0 129
4b2bc804
NK
130 # Test that '--list-generations' does not output the zeroth generation.
131 test -z "`guix package -p "$profile" -l 0`"
132
82fe08ed 133 # Reinstall after roll-back to the empty profile.
5d4b411f 134 guix package --bootstrap -p "$profile" -e "$boot_make"
82fe08ed
LC
135 test "`readlink_base "$profile"`" = "$profile-1-link"
136 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
24e262f0 137
9ac9360d
NK
138 # Check that the first generation is the current one.
139 test "`guix package -p "$profile" -l 1 | cut -f3 | head -n1`" = "(current)"
140
82fe08ed 141 # Roll-back to generation 0, and install---all at once.
e49951eb 142 guix package --bootstrap -p "$profile" --roll-back -i guile-bootstrap
82fe08ed
LC
143 test "`readlink_base "$profile"`" = "$profile-1-link"
144 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
145
146 # Install Make.
5d4b411f 147 guix package --bootstrap -p "$profile" -e "$boot_make"
82fe08ed 148 test "`readlink_base "$profile"`" = "$profile-2-link"
24e262f0 149 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
741c70c6 150 grep "`guix build -e "$boot_make"`" "$profile/manifest"
9241172c
LC
151
152 # Make a "hole" in the list of generations, and make sure we can
b3bb82f1 153 # roll back and switch "over" it.
82fe08ed 154 rm "$profile-1-link"
e49951eb 155 guix package --bootstrap -p "$profile" --roll-back
82fe08ed 156 test "`readlink_base "$profile"`" = "$profile-0-link"
b3bb82f1
AK
157 guix package -p "$profile" --switch-generation=+1
158 test "`readlink_base "$profile"`" = "$profile-2-link"
5924080d
LC
159
160 # Make sure LIBRARY_PATH gets listed by `--search-paths'.
161 guix package --bootstrap -p "$profile" -i guile-bootstrap -i gcc-bootstrap
162 guix package --search-paths -p "$profile" | grep LIBRARY_PATH
b7884ca3 163
d26eb84d
LC
164 # Roll back so we can delete #3 below.
165 guix package -p "$profile" --switch-generation=2
166
b7884ca3
NK
167 # Delete the third generation and check that it was actually deleted.
168 guix package -p "$profile" --delete-generations=3
169 test -z "`guix package -p "$profile" -l 3`"
170
171 # Exit with 1 when a generation does not exist.
172 if guix package -p "$profile" --delete-generations=42;
173 then false; else true; fi
174
175 # Exit with 0 when trying to delete the zeroth generation.
176 guix package -p "$profile" --delete-generations=0
ad1ebab3 177fi
0afdc485 178
6447738c
MW
179# Make sure multiple arguments to -i works.
180guix package --bootstrap -i guile gcc -p "$profile" -n
181
9518856b 182# Make sure the `:' syntax works.
ecb1b610 183guix package --bootstrap -i "glibc:debug" -p "$profile" -n
9518856b 184
aa92cf98 185# Make sure nonexistent outputs are reported.
e49951eb
MW
186guix package --bootstrap -i "guile-bootstrap:out" -p "$profile" -n
187if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile" -n;
aa92cf98 188then false; else true; fi
e49951eb 189if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile";
aa92cf98
LC
190then false; else true; fi
191
64fc89b6 192# Check whether `--list-available' returns something sensible.
03f4ef28 193guix package -p "$profile" -A 'gui.*e' | grep guile
64fc89b6 194
2aa6efb0 195# Check whether `--show' returns something sensible.
3ce9aa44 196guix package --show=guile | grep "^name: guile"
2aa6efb0 197
1b0a86dd 198# Ensure `--show' doesn't fail for packages with non-package inputs.
5e6feee6
EB
199guix package --show=texlive
200
1b0a86dd
LC
201# Search.
202LC_MESSAGES=C
203export LC_MESSAGES
204test "`guix package -s "An example GNU package" | grep ^name:`" = \
205 "name: hello"
206test -z "`guix package -s "n0t4r341p4ck4g3"`"
207
208# Make sure `--search' can display all the packages.
209guix package --search="" > /dev/null
210
d7ddb257
LC
211# There's no generation older than 12 months, so the following command should
212# have no effect.
213generation="`readlink_base "$profile"`"
214if guix package -p "$profile" --delete-generations=12m;
215then false; else true; fi
216test "`readlink_base "$profile"`" = "$generation"
217
d26eb84d
LC
218# The following command should not delete the current generation, even though
219# it matches the given pattern (see <http://bugs.gnu.org/19978>.) And since
220# there's nothing else to delete, it should just fail.
221guix package --list-generations -p "$profile"
222if guix package --bootstrap -p "$profile" --delete-generations=1..
223then false; else true; fi
224test "`readlink_base "$profile"`" = "$generation"
225
c9323a4c
LC
226# Make sure $profile is a GC root at this point.
227real_profile="`readlink -f "$profile"`"
228if guix gc -d "$real_profile"
229then false; else true; fi
230test -d "$real_profile"
231
232# Now, let's remove all the symlinks to $real_profile, and make sure
233# $real_profile is no longer a GC root.
234rm "$profile" "$profile"-[0-9]-link
235guix gc -d "$real_profile"
236[ ! -d "$real_profile" ]
237
67668155 238#
0ec1af59 239# Try with the default profile.
67668155 240#
0ec1af59
LC
241
242XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
243export XDG_CACHE_HOME
88371f0d 244HOME="$PWD/t-home-$$"
0ec1af59
LC
245export HOME
246
247mkdir -p "$HOME"
248
59c51be2
LC
249# Get the canonical directory name so that 'guix package' recognizes it.
250HOME="`cd $HOME; pwd -P`"
251
e49951eb 252guix package --bootstrap -i guile-bootstrap
0ec1af59
LC
253test -L "$HOME/.guix-profile"
254test -f "$HOME/.guix-profile/bin/guile"
24e262f0 255
67668155
LC
256if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
257then
5d4b411f 258 guix package --bootstrap -e "$boot_make"
67668155
LC
259 test -f "$HOME/.guix-profile/bin/make"
260 first_environment="`cd $HOME/.guix-profile ; pwd`"
261
e49951eb 262 guix package --bootstrap --roll-back
67668155
LC
263 test -f "$HOME/.guix-profile/bin/guile"
264 ! test -f "$HOME/.guix-profile/bin/make"
265 test "`cd $HOME/.guix-profile ; pwd`" = "$first_environment"
266fi
267
d9307267
LC
268# Move to the empty profile.
269default_profile="`readlink "$HOME/.guix-profile"`"
270for i in `seq 1 3`
271do
d2952326
LC
272 # Make sure the current generation is a GC root.
273 profile_link="`readlink "$default_profile"`"
274 guix gc --list-live | grep "`readlink "$profile_link"`"
275
e49951eb 276 guix package --bootstrap --roll-back
d9307267
LC
277 ! test -f "$HOME/.guix-profile/bin"
278 ! test -f "$HOME/.guix-profile/lib"
279 test "`readlink "$default_profile"`" = "$default_profile-0-link"
280done
3b9c0020 281
88371f0d
LC
282# Check whether '-p ~/.guix-profile' makes any difference.
283# See <http://bugs.gnu.org/17939>.
284if test -e "$HOME/.guix-profile-0-link"; then false; fi
285if test -e "$HOME/.guix-profile-1-link"; then false; fi
286guix package --bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap
287if test -e "$HOME/.guix-profile-1-link"; then false; fi
288guix package --bootstrap --roll-back -p "$HOME/.guix-profile"
289if test -e "$HOME/.guix-profile-0-link"; then false; fi
290
3b9c0020 291# Extraneous argument.
e49951eb 292if guix package install foo-bar;
aa92cf98 293then false; else true; fi
1a43e4dc
LC
294
295# Make sure the "broken pipe" doesn't yield an error.
296# Note: 'pipefail' is a Bash-specific option.
297set -o pipefail || true
298guix package -A g | head -1 2> "$HOME/err1"
299guix package -I | head -1 2> "$HOME/err2"
300test "`cat "$HOME/err1" "$HOME/err2"`" = ""
300868ba
LC
301
302# Make sure '-L' extends the package module search path.
300868ba 303mkdir "$module_dir"
300868ba
LC
304
305cat > "$module_dir/foo.scm"<<EOF
306(define-module (foo)
307 #:use-module (guix packages)
308 #:use-module (gnu packages emacs))
309
310(define-public x
311 (package (inherit emacs)
312 (name "emacs-foo-bar")
313 (version "42")))
314EOF
315
316guix package -A emacs-foo-bar -L "$module_dir" | grep 42
317guix package -i emacs-foo-bar-42 -n -L "$module_dir"
8689901f
LC
318
319# Same thing using the 'GUIX_PACKAGE_PATH' environment variable.
320GUIX_PACKAGE_PATH="$module_dir"
321export GUIX_PACKAGE_PATH
322guix package -A emacs-foo-bar | grep 42
323guix package -i emacs-foo-bar-42 -n
ee06af5b
LC
324
325# Make sure patches that live under $GUIX_PACKAGE_PATH are found.
326cat > "$module_dir/emacs.patch"<<EOF
327This is a fake patch.
328EOF
329cat > "$module_dir/foo.scm"<<EOF
330(define-module (foo)
331 #:use-module (guix packages)
332 #:use-module (gnu packages)
333 #:use-module (gnu packages emacs))
334
335(define-public x
336 (package (inherit emacs)
337 (source (origin (inherit (package-source emacs))
338 (patches (list (search-patch "emacs.patch")))))
339 (name "emacs-foo-bar-patched")
340 (version "42")))
341EOF
342guix package -i emacs-foo-bar-patched -n
343
847391fe
DP
344unset GUIX_PACKAGE_PATH
345
346# Using 'GUIX_BUILD_OPTIONS'.
847391fe
DP
347available="`guix package -A | sort`"
348GUIX_BUILD_OPTIONS="--dry-run"
349export GUIX_BUILD_OPTIONS
350
351# Make sure $GUIX_BUILD_OPTIONS is not simply appended to the command-line,
352# which would break 'guix package -A' and similar.
353available2="`guix package -A | sort`"
354test "$available2" = "$available"
355guix package -I