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