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