serialization: Adjust the permissive UTF-8 decoder to Guile 2.0.12ish.
[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
e25234e3 31module_dir="t-guix-package-$$"
0afdc485
LC
32profile="t-profile-$$"
33rm -f "$profile"
34
c9323a4c 35trap 'rm -f "$profile" "$profile-"[0-9]* ; rm -rf "$module_dir" t-home-'"$$" EXIT
7a6548cb 36
5d4b411f
LC
37# Use `-e' with a non-package expression.
38if guix package --bootstrap -e +;
39then false; else true; fi
40
e49951eb 41guix package --bootstrap -p "$profile" -i guile-bootstrap
0afdc485
LC
42test -L "$profile" && test -L "$profile-1-link"
43test -f "$profile/bin/guile"
44
d2952326
LC
45# Make sure the profile is a GC root.
46guix gc --list-live | grep "`readlink "$profile-1-link"`"
47
1c67d639 48# Installing the same package a second time does nothing.
e49951eb 49guix package --bootstrap -p "$profile" -i guile-bootstrap
1c67d639
LC
50test -L "$profile" && test -L "$profile-1-link"
51! test -f "$profile-2-link"
52test -f "$profile/bin/guile"
0afdc485 53
5924080d
LC
54# No search path env. var. here.
55guix package --search-paths -p "$profile"
56test "`guix package --search-paths -p "$profile" | wc -l`" = 0
57
57b86237
LC
58# Exit with 1 when a generation does not exist.
59if guix package -p "$profile" --delete-generations=42;
60then false; else true; fi
61
62# Exit with 0 when trying to delete the zeroth generation.
63guix package -p "$profile" --delete-generations=0
0afdc485 64
6447738c
MW
65# Make sure multiple arguments to -i works.
66guix package --bootstrap -i guile gcc -p "$profile" -n
67
9518856b 68# Make sure the `:' syntax works.
ecb1b610 69guix package --bootstrap -i "glibc:debug" -p "$profile" -n
9518856b 70
aa92cf98 71# Make sure nonexistent outputs are reported.
e49951eb
MW
72guix package --bootstrap -i "guile-bootstrap:out" -p "$profile" -n
73if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile" -n;
aa92cf98 74then false; else true; fi
e49951eb 75if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile";
aa92cf98
LC
76then false; else true; fi
77
64fc89b6 78# Check whether `--list-available' returns something sensible.
03f4ef28 79guix package -p "$profile" -A 'gui.*e' | grep guile
64fc89b6 80
2aa6efb0 81# Check whether `--show' returns something sensible.
3ce9aa44 82guix package --show=guile | grep "^name: guile"
2aa6efb0 83
1b0a86dd 84# Ensure `--show' doesn't fail for packages with non-package inputs.
5e6feee6
EB
85guix package --show=texlive
86
1b0a86dd
LC
87# Search.
88LC_MESSAGES=C
89export LC_MESSAGES
90test "`guix package -s "An example GNU package" | grep ^name:`" = \
91 "name: hello"
92test -z "`guix package -s "n0t4r341p4ck4g3"`"
93
94# Make sure `--search' can display all the packages.
95guix package --search="" > /dev/null
96
d7ddb257
LC
97# There's no generation older than 12 months, so the following command should
98# have no effect.
99generation="`readlink_base "$profile"`"
100if guix package -p "$profile" --delete-generations=12m;
101then false; else true; fi
102test "`readlink_base "$profile"`" = "$generation"
103
d26eb84d
LC
104# The following command should not delete the current generation, even though
105# it matches the given pattern (see <http://bugs.gnu.org/19978>.) And since
106# there's nothing else to delete, it should just fail.
107guix package --list-generations -p "$profile"
108if guix package --bootstrap -p "$profile" --delete-generations=1..
109then false; else true; fi
110test "`readlink_base "$profile"`" = "$generation"
111
c9323a4c
LC
112# Make sure $profile is a GC root at this point.
113real_profile="`readlink -f "$profile"`"
114if guix gc -d "$real_profile"
115then false; else true; fi
116test -d "$real_profile"
117
118# Now, let's remove all the symlinks to $real_profile, and make sure
119# $real_profile is no longer a GC root.
120rm "$profile" "$profile"-[0-9]-link
121guix gc -d "$real_profile"
122[ ! -d "$real_profile" ]
123
67668155 124#
0ec1af59 125# Try with the default profile.
67668155 126#
0ec1af59
LC
127
128XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
129export XDG_CACHE_HOME
88371f0d 130HOME="$PWD/t-home-$$"
0ec1af59
LC
131export HOME
132
133mkdir -p "$HOME"
134
59c51be2
LC
135# Get the canonical directory name so that 'guix package' recognizes it.
136HOME="`cd $HOME; pwd -P`"
137
e49951eb 138guix package --bootstrap -i guile-bootstrap
0ec1af59
LC
139test -L "$HOME/.guix-profile"
140test -f "$HOME/.guix-profile/bin/guile"
24e262f0 141
d9307267
LC
142# Move to the empty profile.
143default_profile="`readlink "$HOME/.guix-profile"`"
144for i in `seq 1 3`
145do
d2952326
LC
146 # Make sure the current generation is a GC root.
147 profile_link="`readlink "$default_profile"`"
148 guix gc --list-live | grep "`readlink "$profile_link"`"
149
e49951eb 150 guix package --bootstrap --roll-back
d9307267
LC
151 ! test -f "$HOME/.guix-profile/bin"
152 ! test -f "$HOME/.guix-profile/lib"
153 test "`readlink "$default_profile"`" = "$default_profile-0-link"
154done
3b9c0020 155
88371f0d
LC
156# Check whether '-p ~/.guix-profile' makes any difference.
157# See <http://bugs.gnu.org/17939>.
158if test -e "$HOME/.guix-profile-0-link"; then false; fi
159if test -e "$HOME/.guix-profile-1-link"; then false; fi
160guix package --bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap
161if test -e "$HOME/.guix-profile-1-link"; then false; fi
162guix package --bootstrap --roll-back -p "$HOME/.guix-profile"
163if test -e "$HOME/.guix-profile-0-link"; then false; fi
164
3b9c0020 165# Extraneous argument.
e49951eb 166if guix package install foo-bar;
aa92cf98 167then false; else true; fi
1a43e4dc
LC
168
169# Make sure the "broken pipe" doesn't yield an error.
170# Note: 'pipefail' is a Bash-specific option.
171set -o pipefail || true
172guix package -A g | head -1 2> "$HOME/err1"
173guix package -I | head -1 2> "$HOME/err2"
174test "`cat "$HOME/err1" "$HOME/err2"`" = ""
300868ba
LC
175
176# Make sure '-L' extends the package module search path.
300868ba 177mkdir "$module_dir"
300868ba
LC
178
179cat > "$module_dir/foo.scm"<<EOF
180(define-module (foo)
181 #:use-module (guix packages)
182 #:use-module (gnu packages emacs))
183
184(define-public x
185 (package (inherit emacs)
186 (name "emacs-foo-bar")
187 (version "42")))
188EOF
189
190guix package -A emacs-foo-bar -L "$module_dir" | grep 42
191guix package -i emacs-foo-bar-42 -n -L "$module_dir"
8689901f
LC
192
193# Same thing using the 'GUIX_PACKAGE_PATH' environment variable.
194GUIX_PACKAGE_PATH="$module_dir"
195export GUIX_PACKAGE_PATH
196guix package -A emacs-foo-bar | grep 42
197guix package -i emacs-foo-bar-42 -n
ee06af5b
LC
198
199# Make sure patches that live under $GUIX_PACKAGE_PATH are found.
200cat > "$module_dir/emacs.patch"<<EOF
201This is a fake patch.
202EOF
203cat > "$module_dir/foo.scm"<<EOF
204(define-module (foo)
205 #:use-module (guix packages)
206 #:use-module (gnu packages)
207 #:use-module (gnu packages emacs))
208
209(define-public x
210 (package (inherit emacs)
211 (source (origin (inherit (package-source emacs))
212 (patches (list (search-patch "emacs.patch")))))
213 (name "emacs-foo-bar-patched")
214 (version "42")))
5763ad92
LC
215
216(define-public y
217 (package (inherit emacs)
218 (name "super-non-portable-emacs")
219 (supported-systems '("foobar64-hurd"))))
ee06af5b
LC
220EOF
221guix package -i emacs-foo-bar-patched -n
222
5763ad92
LC
223# This one should not show up in searches since it's no supported on the
224# current system.
225test "`guix package -A super-non-portable-emacs`" = ""
226test "`guix package -s super-non-portable-emacs | grep ^systems:`" = "systems: "
227
847391fe
DP
228unset GUIX_PACKAGE_PATH
229
230# Using 'GUIX_BUILD_OPTIONS'.
847391fe
DP
231available="`guix package -A | sort`"
232GUIX_BUILD_OPTIONS="--dry-run"
233export GUIX_BUILD_OPTIONS
234
235# Make sure $GUIX_BUILD_OPTIONS is not simply appended to the command-line,
236# which would break 'guix package -A' and similar.
237available2="`guix package -A | sort`"
238test "$available2" = "$available"
239guix package -I