tests: Move 'guix package' tests that require networking to a separate file.
[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 -f "$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 # Exit with 1 when a generation does not exist.
59 if guix package -p "$profile" --delete-generations=42;
60 then false; else true; fi
61
62 # Exit with 0 when trying to delete the zeroth generation.
63 guix package -p "$profile" --delete-generations=0
64
65 # Make sure multiple arguments to -i works.
66 guix package --bootstrap -i guile gcc -p "$profile" -n
67
68 # Make sure the `:' syntax works.
69 guix package --bootstrap -i "glibc:debug" -p "$profile" -n
70
71 # Make sure nonexistent outputs are reported.
72 guix package --bootstrap -i "guile-bootstrap:out" -p "$profile" -n
73 if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile" -n;
74 then false; else true; fi
75 if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile";
76 then false; else true; fi
77
78 # Check whether `--list-available' returns something sensible.
79 guix package -p "$profile" -A 'gui.*e' | grep guile
80
81 # Check whether `--show' returns something sensible.
82 guix package --show=guile | grep "^name: guile"
83
84 # Ensure `--show' doesn't fail for packages with non-package inputs.
85 guix package --show=texlive
86
87 # Search.
88 LC_MESSAGES=C
89 export LC_MESSAGES
90 test "`guix package -s "An example GNU package" | grep ^name:`" = \
91 "name: hello"
92 test -z "`guix package -s "n0t4r341p4ck4g3"`"
93
94 # Make sure `--search' can display all the packages.
95 guix package --search="" > /dev/null
96
97 # There's no generation older than 12 months, so the following command should
98 # have no effect.
99 generation="`readlink_base "$profile"`"
100 if guix package -p "$profile" --delete-generations=12m;
101 then false; else true; fi
102 test "`readlink_base "$profile"`" = "$generation"
103
104 # The following command should not delete the current generation, even though
105 # it matches the given pattern (see <http://bugs.gnu.org/19978>.) And since
106 # there's nothing else to delete, it should just fail.
107 guix package --list-generations -p "$profile"
108 if guix package --bootstrap -p "$profile" --delete-generations=1..
109 then false; else true; fi
110 test "`readlink_base "$profile"`" = "$generation"
111
112 # Make sure $profile is a GC root at this point.
113 real_profile="`readlink -f "$profile"`"
114 if guix gc -d "$real_profile"
115 then false; else true; fi
116 test -d "$real_profile"
117
118 # Now, let's remove all the symlinks to $real_profile, and make sure
119 # $real_profile is no longer a GC root.
120 rm "$profile" "$profile"-[0-9]-link
121 guix gc -d "$real_profile"
122 [ ! -d "$real_profile" ]
123
124 #
125 # Try with the default profile.
126 #
127
128 XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
129 export XDG_CACHE_HOME
130 HOME="$PWD/t-home-$$"
131 export HOME
132
133 mkdir -p "$HOME"
134
135 # Get the canonical directory name so that 'guix package' recognizes it.
136 HOME="`cd $HOME; pwd -P`"
137
138 guix package --bootstrap -i guile-bootstrap
139 test -L "$HOME/.guix-profile"
140 test -f "$HOME/.guix-profile/bin/guile"
141
142 # Move to the empty profile.
143 default_profile="`readlink "$HOME/.guix-profile"`"
144 for i in `seq 1 3`
145 do
146 # Make sure the current generation is a GC root.
147 profile_link="`readlink "$default_profile"`"
148 guix gc --list-live | grep "`readlink "$profile_link"`"
149
150 guix package --bootstrap --roll-back
151 ! test -f "$HOME/.guix-profile/bin"
152 ! test -f "$HOME/.guix-profile/lib"
153 test "`readlink "$default_profile"`" = "$default_profile-0-link"
154 done
155
156 # Check whether '-p ~/.guix-profile' makes any difference.
157 # See <http://bugs.gnu.org/17939>.
158 if test -e "$HOME/.guix-profile-0-link"; then false; fi
159 if test -e "$HOME/.guix-profile-1-link"; then false; fi
160 guix package --bootstrap -p "$HOME/.guix-profile" -i guile-bootstrap
161 if test -e "$HOME/.guix-profile-1-link"; then false; fi
162 guix package --bootstrap --roll-back -p "$HOME/.guix-profile"
163 if test -e "$HOME/.guix-profile-0-link"; then false; fi
164
165 # Extraneous argument.
166 if guix package install foo-bar;
167 then false; else true; fi
168
169 # Make sure the "broken pipe" doesn't yield an error.
170 # Note: 'pipefail' is a Bash-specific option.
171 set -o pipefail || true
172 guix package -A g | head -1 2> "$HOME/err1"
173 guix package -I | head -1 2> "$HOME/err2"
174 test "`cat "$HOME/err1" "$HOME/err2"`" = ""
175
176 # Make sure '-L' extends the package module search path.
177 mkdir "$module_dir"
178
179 cat > "$module_dir/foo.scm"<<EOF
180 (define-module (foo)
181 #:use-module (guix packages)
182 #:use-module (gnu packages emacs))
183
184 (define-public x
185 (package (inherit emacs)
186 (name "emacs-foo-bar")
187 (version "42")))
188 EOF
189
190 guix package -A emacs-foo-bar -L "$module_dir" | grep 42
191 guix package -i emacs-foo-bar-42 -n -L "$module_dir"
192
193 # Same thing using the 'GUIX_PACKAGE_PATH' environment variable.
194 GUIX_PACKAGE_PATH="$module_dir"
195 export GUIX_PACKAGE_PATH
196 guix package -A emacs-foo-bar | grep 42
197 guix package -i emacs-foo-bar-42 -n
198
199 # Make sure patches that live under $GUIX_PACKAGE_PATH are found.
200 cat > "$module_dir/emacs.patch"<<EOF
201 This is a fake patch.
202 EOF
203 cat > "$module_dir/foo.scm"<<EOF
204 (define-module (foo)
205 #:use-module (guix packages)
206 #:use-module (gnu packages)
207 #:use-module (gnu packages emacs))
208
209 (define-public x
210 (package (inherit emacs)
211 (source (origin (inherit (package-source emacs))
212 (patches (list (search-patch "emacs.patch")))))
213 (name "emacs-foo-bar-patched")
214 (version "42")))
215 EOF
216 guix package -i emacs-foo-bar-patched -n
217
218 unset GUIX_PACKAGE_PATH
219
220 # Using 'GUIX_BUILD_OPTIONS'.
221 available="`guix package -A | sort`"
222 GUIX_BUILD_OPTIONS="--dry-run"
223 export GUIX_BUILD_OPTIONS
224
225 # Make sure $GUIX_BUILD_OPTIONS is not simply appended to the command-line,
226 # which would break 'guix package -A' and similar.
227 available2="`guix package -A | sort`"
228 test "$available2" = "$available"
229 guix package -I