guix package: Inherit the transformed version number.
[jackhill/guix/guix.git] / tests / guix-package.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
3 # Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
4 #
5 # This file is part of GNU Guix.
6 #
7 # GNU Guix is free software; you can redistribute it and/or modify it
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 #
12 # GNU Guix is distributed in the hope that it will be useful, but
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
18 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20 #
21 # Test the `guix package' command-line utility.
22 #
23
24 guix package --version
25
26 readlink_base ()
27 {
28 basename `readlink "$1"`
29 }
30
31 module_dir="t-guix-package-$$"
32 profile="t-profile-$$"
33 tmpfile="t-guix-package-file-$$"
34 rm -f "$profile" "$tmpfile"
35
36 trap 'rm -f "$profile" "$profile-"[0-9]* "$tmpfile"; rm -rf "$module_dir" t-home-'"$$" EXIT
37
38 # Use `-e' with a non-package expression.
39 if guix package --bootstrap -e +;
40 then false; else true; fi
41
42 guix package --bootstrap -p "$profile" -i guile-bootstrap
43 test -L "$profile" && test -L "$profile-1-link"
44 test -f "$profile/bin/guile"
45
46 # Make sure the profile is a GC root.
47 guix gc --list-live | grep "`readlink "$profile-1-link"`"
48
49 # Installing the same package a second time does nothing.
50 guix package --bootstrap -p "$profile" -i guile-bootstrap
51 test -L "$profile" && test -L "$profile-1-link"
52 ! test -f "$profile-2-link"
53 test -f "$profile/bin/guile"
54
55 # No search path env. var. here.
56 guix package -p "$profile" --search-paths
57 guix package -p "$profile" --search-paths | grep '^export PATH='
58 test "`guix package -p "$profile" --search-paths | wc -l`" = 1 # $PATH
59 ( set -e; set -x; \
60 eval `guix package --search-paths=prefix -p "$PWD/$profile"`; \
61 test "`type -P guile`" = "$PWD/$profile/bin/guile" ; \
62 type -P rm )
63
64 # Exit with 1 when a generation does not exist.
65 if guix package -p "$profile" --delete-generations=42;
66 then false; else true; fi
67
68 # Exit with 0 when trying to delete the zeroth generation.
69 guix package -p "$profile" --delete-generations=0
70
71 # Make sure multiple arguments to -i works.
72 guix package --bootstrap -i guile gcc -p "$profile" -n
73
74 # Make sure the `:' syntax works.
75 guix package --bootstrap -i "glibc:debug" -p "$profile" -n
76
77 # Make sure nonexistent outputs are reported.
78 guix package --bootstrap -i "guile-bootstrap:out" -p "$profile" -n
79 if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile" -n;
80 then false; else true; fi
81 if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile";
82 then false; else true; fi
83
84 # Check whether `--list-available' returns something sensible.
85 guix package -p "$profile" -A 'gui.*e' | grep guile
86
87 # Check whether `--show' returns something sensible.
88 guix package --show=guile | grep "^name: guile"
89
90 # Ensure `--show' doesn't fail for packages with non-package inputs.
91 guix package --show=texlive
92
93 # Search.
94 LC_MESSAGES=C
95 export LC_MESSAGES
96 test "`guix package -s "An example GNU package" | grep ^name:`" = \
97 "name: hello"
98 test -z "`guix package -s "n0t4r341p4ck4g3"`"
99
100 # Search with one and then two regexps.
101 # First we get printed circuit boards *and* board games.
102 guix package -s '\<board\>' > "$tmpfile"
103 grep '^name: pcb' "$tmpfile"
104 grep '^name: gnubg' "$tmpfile"
105
106 # Second we get only board games.
107 guix package -s '\<board\>' -s game > "$tmpfile"
108 grep -v '^name: pcb' "$tmpfile" > /dev/null
109 grep '^name: gnubg' "$tmpfile"
110
111 rm -f "$tmpfile"
112
113 # Make sure `--search' can display all the packages.
114 guix package --search="" > /dev/null
115
116 # There's no generation older than 12 months, so the following command should
117 # have no effect.
118 generation="`readlink_base "$profile"`"
119 if guix package -p "$profile" --delete-generations=12m;
120 then false; else true; fi
121 test "`readlink_base "$profile"`" = "$generation"
122
123 # The following command should not delete the current generation, even though
124 # it matches the given pattern (see <http://bugs.gnu.org/19978>.) And since
125 # there's nothing else to delete, it should just fail.
126 guix package --list-generations -p "$profile"
127 if guix package --bootstrap -p "$profile" --delete-generations=1..
128 then false; else true; fi
129 test "`readlink_base "$profile"`" = "$generation"
130
131 # Make sure $profile is a GC root at this point.
132 real_profile="`readlink -f "$profile"`"
133 if guix gc -d "$real_profile"
134 then false; else true; fi
135 test -d "$real_profile"
136
137 # Now, let's remove all the symlinks to $real_profile, and make sure
138 # $real_profile is no longer a GC root.
139 rm "$profile" "$profile"-[0-9]-link
140 guix gc -d "$real_profile"
141 [ ! -d "$real_profile" ]
142
143 # Package transformations.
144
145 # Make sure we get the right version number when using '--with-source'.
146 mkdir "$module_dir"
147 emacs_tarball="$module_dir/emacs-42.5.9rc7.tar.gz"
148 touch "$emacs_tarball"
149 guix package -p "$profile" -i emacs --with-source="$emacs_tarball" -n \
150 2> "$tmpfile"
151 grep -E 'emacs[[:blank:]]+42\.5\.9rc7[[:blank:]]+.*-emacs-42.5.9rc7' \
152 "$tmpfile"
153 rm "$emacs_tarball" "$tmpfile"
154 rmdir "$module_dir"
155
156
157 #
158 # Try with the default profile.
159 #
160
161 XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
162 export XDG_CACHE_HOME
163 HOME="$PWD/t-home-$$"
164 export HOME
165
166 mkdir -p "$HOME"
167
168 # Get the canonical directory name so that 'guix package' recognizes it.
169 HOME="`cd $HOME; pwd -P`"
170
171 guix package --bootstrap -i guile-bootstrap
172 test -L "$HOME/.guix-profile"
173 test -f "$HOME/.guix-profile/bin/guile"
174
175 # Move to the empty profile.
176 default_profile="`readlink "$HOME/.guix-profile"`"
177 for i in `seq 1 3`
178 do
179 # Make sure the current generation is a GC root.
180 profile_link="`readlink "$default_profile"`"
181 guix gc --list-live | grep "`readlink "$profile_link"`"
182
183 guix package --bootstrap --roll-back
184 ! test -f "$HOME/.guix-profile/bin"
185 ! test -f "$HOME/.guix-profile/lib"
186 test "`readlink "$default_profile"`" = "$default_profile-0-link"
187 done
188
189 # Check whether '-p ~/.guix-profile' makes any difference.
190 # See <http://bugs.gnu.org/17939>.
191 if test -e "$HOME/.guix-profile-0-link"; then false; fi
192 if test -e "$HOME/.guix-profile-1-link"; then false; fi
193 guix package --bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap
194 if test -e "$HOME/.guix-profile-1-link"; then false; fi
195 guix package --bootstrap --roll-back -p "$HOME/.guix-profile"
196 if test -e "$HOME/.guix-profile-0-link"; then false; fi
197
198 # Extraneous argument.
199 if guix package install foo-bar;
200 then false; else true; fi
201
202 # Make sure the "broken pipe" doesn't yield an error.
203 # Note: 'pipefail' is a Bash-specific option.
204 set -o pipefail || true
205 guix package -A g | head -1 2> "$HOME/err1"
206 guix package -I | head -1 2> "$HOME/err2"
207 test "`cat "$HOME/err1" "$HOME/err2"`" = ""
208
209 # Make sure '-L' extends the package module search path.
210 mkdir "$module_dir"
211
212 cat > "$module_dir/foo.scm"<<EOF
213 (define-module (foo)
214 #:use-module (guix packages)
215 #:use-module (gnu packages emacs))
216
217 (define-public x
218 (package (inherit emacs)
219 (name "emacs-foo-bar")
220 (version "42")))
221 EOF
222
223 guix package -A emacs-foo-bar -L "$module_dir" | grep 42
224 guix package -i emacs-foo-bar@42 -n -L "$module_dir"
225
226 # Same thing using the 'GUIX_PACKAGE_PATH' environment variable.
227 GUIX_PACKAGE_PATH="$module_dir"
228 export GUIX_PACKAGE_PATH
229 guix package -A emacs-foo-bar | grep 42
230 guix package -i emacs-foo-bar@42 -n
231
232 # Make sure patches that live under $GUIX_PACKAGE_PATH are found.
233 cat > "$module_dir/emacs.patch"<<EOF
234 This is a fake patch.
235 EOF
236 cat > "$module_dir/foo.scm"<<EOF
237 (define-module (foo)
238 #:use-module (guix packages)
239 #:use-module (gnu packages)
240 #:use-module (gnu packages emacs))
241
242 (define-public x
243 (package (inherit emacs)
244 (source (origin (inherit (package-source emacs))
245 (patches (list (search-patch "emacs.patch")))))
246 (name "emacs-foo-bar-patched")
247 (version "42")))
248
249 (define-public y
250 (package (inherit emacs)
251 (name "super-non-portable-emacs")
252 (supported-systems '("foobar64-hurd"))))
253 EOF
254 guix package -i emacs-foo-bar-patched -n
255
256 # Same when -L is used.
257 ( unset GUIX_PACKAGE_PATH; \
258 guix package -L "$module_dir" -i emacs-foo-bar-patched -n )
259
260 # Make sure installing from a file works.
261 cat > "$module_dir/package.scm"<<EOF
262 (use-modules (gnu))
263 (use-package-modules bootstrap)
264
265 %bootstrap-guile
266 EOF
267 guix package --bootstrap --install-from-file="$module_dir/package.scm"
268
269 # This one should not show up in searches since it's no supported on the
270 # current system.
271 test "`guix package -A super-non-portable-emacs`" = ""
272 test "`guix package -s super-non-portable-emacs | grep ^systems:`" = "systems: "
273
274 unset GUIX_PACKAGE_PATH
275
276 # Using 'GUIX_BUILD_OPTIONS'.
277 available="`guix package -A | sort`"
278 GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
279 export GUIX_BUILD_OPTIONS
280
281 # Make sure $GUIX_BUILD_OPTIONS is not simply appended to the command-line,
282 # which would break 'guix package -A' and similar.
283 available2="`guix package -A | sort`"
284 test "$available2" = "$available"
285 guix package -I
286
287 # Restore '--no-grafts', which makes sure we don't end up building stuff when
288 # '--dry-run' is passed.
289 GUIX_BUILD_OPTIONS="--no-grafts"
290
291 # Applying a manifest file.
292 cat > "$module_dir/manifest.scm"<<EOF
293 (use-package-modules bootstrap)
294
295 (packages->manifest (list %bootstrap-guile))
296 EOF
297 guix package --bootstrap -m "$module_dir/manifest.scm"
298 guix package -I | grep guile
299 test `guix package -I | wc -l` -eq 1
300
301 # Error reporting.
302 cat > "$module_dir/manifest.scm"<<EOF
303 (use-package-modules bootstrap)
304 (packages->manifest
305 (list %bootstrap-guile
306 wonderful-package-that-does-not-exist))
307 EOF
308 if guix package --bootstrap -n -m "$module_dir/manifest.scm" \
309 2> "$module_dir/stderr"
310 then false
311 else
312 cat "$module_dir/stderr"
313 grep "manifest.scm:[1-3]:.*[Uu]nbound variable.*wonderful-package" \
314 "$module_dir/stderr"
315 fi