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>
5 # This file is part of GNU Guix.
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.
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.
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/>.
21 # Test the `guix package' command-line utility.
24 guix package
--version
28 basename `readlink "$1"`
31 module_dir
="t-guix-package-$$"
32 profile
="t-profile-$$"
35 trap 'rm "$profile" "$profile-"[0-9]* ; rm -rf "$module_dir" t-home-'"$$" EXIT
37 # Use `-e' with a non-package expression.
38 if guix package
--bootstrap -e +;
39 then false
; else true
; fi
41 guix package
--bootstrap -p "$profile" -i guile-bootstrap
42 test -L "$profile" && test -L "$profile-1-link"
43 test -f "$profile/bin/guile"
45 # Make sure the profile is a GC root.
46 guix gc
--list-live |
grep "`readlink "$profile-1-link"`"
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"
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
58 # Check whether we have network access.
59 if guile
-c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev
/null
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"
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`"
73 "guile-bootstrap make-boot0")
75 "make-boot0 guile-bootstrap")
81 test "`guix package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap"
84 test "`guix package -p "$profile" -l | cut -f1 | grep guile | head -n1`" \
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
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"
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"
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"
112 # Move to the empty profile.
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"
121 # Test that '--list-generations' does not output the zeroth generation.
122 test -z "`guix package -p "$profile" -l 0`"
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"
129 # Check that the first generation is the current one.
130 test "`guix package -p "$profile" -l 1 | cut -f3 | head -n1`" = "(current)"
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"
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"
143 # Make a "hole" in the list of generations, and make sure we can
144 # roll back and switch "over" it.
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"
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
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`"
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
163 # Exit with 0 when trying to delete the zeroth generation.
164 guix package
-p "$profile" --delete-generations=0
167 # Make sure multiple arguments to -i works.
168 guix package
--bootstrap -i guile gcc
-p "$profile" -n
170 # Make sure the `:' syntax works.
171 guix package
--bootstrap -i "glibc:debug" -p "$profile" -n
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
180 # Check whether `--list-available' returns something sensible.
181 guix package
-p "$profile" -A 'gui.*e' |
grep guile
183 # Check whether `--show' returns something sensible.
184 guix package
--show=guile |
grep "^name: guile"
186 # Ensure `--show' doesn't fail for packages with non-package inputs.
187 guix package
--show=texlive
192 test "`guix package -s "An example GNU package
" | grep ^name:`" = \
194 test -z "`guix package -s "n0t4r341p4ck4g3
"`"
196 # Make sure `--search' can display all the packages.
197 guix package
--search="" > /dev
/null
199 # There's no generation older than 12 months, so the following command should
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"
207 # Try with the default profile.
210 XDG_CACHE_HOME
="${XDG_CACHE_HOME:-$HOME/.cache}"
211 export XDG_CACHE_HOME
212 HOME
="$PWD/t-home-$$"
217 # Get the canonical directory name so that 'guix package' recognizes it.
218 HOME
="`cd $HOME; pwd -P`"
220 guix package
--bootstrap -i guile-bootstrap
221 test -L "$HOME/.guix-profile"
222 test -f "$HOME/.guix-profile/bin/guile"
224 if guile
-c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev
/null
226 guix package
--bootstrap -e "$boot_make"
227 test -f "$HOME/.guix-profile/bin/make"
228 first_environment
="`cd $HOME/.guix-profile ; pwd`"
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"
236 # Move to the empty profile.
237 default_profile
="`readlink "$HOME/.guix-profile
"`"
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"`"
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"
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
259 # Extraneous argument.
260 if guix package
install foo-bar
;
261 then false
; else true
; fi
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
"`" = ""
270 # Make sure '-L' extends the package module search path.
273 cat > "$module_dir/foo.scm"<<EOF
275 #:use-module (guix packages)
276 #:use-module (gnu packages emacs))
279 (package (inherit emacs)
280 (name "emacs-foo-bar")
284 guix package
-A emacs-foo-bar
-L "$module_dir" |
grep 42
285 guix package
-i emacs-foo-bar-42
-n -L "$module_dir"
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
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.
297 cat > "$module_dir/foo.scm"<<EOF
299 #:use-module (guix packages)
300 #:use-module (gnu packages)
301 #:use-module (gnu packages emacs))
304 (package (inherit emacs)
305 (source (origin (inherit (package-source emacs))
306 (patches (list (search-patch "emacs.patch")))))
307 (name "emacs-foo-bar-patched")
310 guix package
-i emacs-foo-bar-patched
-n
312 unset GUIX_PACKAGE_PATH
314 # Using 'GUIX_BUILD_OPTIONS'.
315 available
="`guix package -A | sort`"
316 GUIX_BUILD_OPTIONS
="--dry-run"
317 export GUIX_BUILD_OPTIONS
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"