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 -f "$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"
206 # Make sure $profile is a GC root at this point.
207 real_profile
="`readlink -f "$profile"`"
208 if guix gc
-d "$real_profile"
209 then false
; else true
; fi
210 test -d "$real_profile"
212 # Now, let's remove all the symlinks to $real_profile, and make sure
213 # $real_profile is no longer a GC root.
214 rm "$profile" "$profile"-[0-9]-link
215 guix gc
-d "$real_profile"
216 [ ! -d "$real_profile" ]
219 # Try with the default profile.
222 XDG_CACHE_HOME
="${XDG_CACHE_HOME:-$HOME/.cache}"
223 export XDG_CACHE_HOME
224 HOME
="$PWD/t-home-$$"
229 # Get the canonical directory name so that 'guix package' recognizes it.
230 HOME
="`cd $HOME; pwd -P`"
232 guix package
--bootstrap -i guile-bootstrap
233 test -L "$HOME/.guix-profile"
234 test -f "$HOME/.guix-profile/bin/guile"
236 if guile
-c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev
/null
238 guix package
--bootstrap -e "$boot_make"
239 test -f "$HOME/.guix-profile/bin/make"
240 first_environment
="`cd $HOME/.guix-profile ; pwd`"
242 guix package
--bootstrap --roll-back
243 test -f "$HOME/.guix-profile/bin/guile"
244 ! test -f "$HOME/.guix-profile/bin/make"
245 test "`cd $HOME/.guix-profile ; pwd`" = "$first_environment"
248 # Move to the empty profile.
249 default_profile
="`readlink "$HOME/.guix-profile
"`"
252 # Make sure the current generation is a GC root.
253 profile_link
="`readlink "$default_profile"`"
254 guix gc
--list-live |
grep "`readlink "$profile_link"`"
256 guix package
--bootstrap --roll-back
257 ! test -f "$HOME/.guix-profile/bin"
258 ! test -f "$HOME/.guix-profile/lib"
259 test "`readlink "$default_profile"`" = "$default_profile-0-link"
262 # Check whether '-p ~/.guix-profile' makes any difference.
263 # See <http://bugs.gnu.org/17939>.
264 if test -e "$HOME/.guix-profile-0-link"; then false
; fi
265 if test -e "$HOME/.guix-profile-1-link"; then false
; fi
266 guix package
--bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap
267 if test -e "$HOME/.guix-profile-1-link"; then false
; fi
268 guix package
--bootstrap --roll-back -p "$HOME/.guix-profile"
269 if test -e "$HOME/.guix-profile-0-link"; then false
; fi
271 # Extraneous argument.
272 if guix package
install foo-bar
;
273 then false
; else true
; fi
275 # Make sure the "broken pipe" doesn't yield an error.
276 # Note: 'pipefail' is a Bash-specific option.
277 set -o pipefail || true
278 guix package
-A g |
head -1 2> "$HOME/err1"
279 guix package
-I |
head -1 2> "$HOME/err2"
280 test "`cat "$HOME/err1
" "$HOME/err2
"`" = ""
282 # Make sure '-L' extends the package module search path.
285 cat > "$module_dir/foo.scm"<<EOF
287 #:use-module (guix packages)
288 #:use-module (gnu packages emacs))
291 (package (inherit emacs)
292 (name "emacs-foo-bar")
296 guix package
-A emacs-foo-bar
-L "$module_dir" |
grep 42
297 guix package
-i emacs-foo-bar-42
-n -L "$module_dir"
299 # Same thing using the 'GUIX_PACKAGE_PATH' environment variable.
300 GUIX_PACKAGE_PATH
="$module_dir"
301 export GUIX_PACKAGE_PATH
302 guix package
-A emacs-foo-bar |
grep 42
303 guix package
-i emacs-foo-bar-42
-n
305 # Make sure patches that live under $GUIX_PACKAGE_PATH are found.
306 cat > "$module_dir/emacs.patch"<<EOF
307 This is a fake patch.
309 cat > "$module_dir/foo.scm"<<EOF
311 #:use-module (guix packages)
312 #:use-module (gnu packages)
313 #:use-module (gnu packages emacs))
316 (package (inherit emacs)
317 (source (origin (inherit (package-source emacs))
318 (patches (list (search-patch "emacs.patch")))))
319 (name "emacs-foo-bar-patched")
322 guix package
-i emacs-foo-bar-patched
-n
324 unset GUIX_PACKAGE_PATH
326 # Using 'GUIX_BUILD_OPTIONS'.
327 available
="`guix package -A | sort`"
328 GUIX_BUILD_OPTIONS
="--dry-run"
329 export GUIX_BUILD_OPTIONS
331 # Make sure $GUIX_BUILD_OPTIONS is not simply appended to the command-line,
332 # which would break 'guix package -A' and similar.
333 available2
="`guix package -A | sort`"
334 test "$available2" = "$available"