guix package: '--delete-generations' deletes generations older than specified.
[jackhill/guix/guix.git] / tests / guix-package.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2013 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 profile="t-profile-$$"
32 rm -f "$profile"
33
34 trap 'rm "$profile" "$profile-"[0-9]* ; rm -rf t-home-'"$$" EXIT
35
36 # Use `-e' with a non-package expression.
37 if guix package --bootstrap -e +;
38 then false; else true; fi
39
40 guix package --bootstrap -p "$profile" -i guile-bootstrap
41 test -L "$profile" && test -L "$profile-1-link"
42 test -f "$profile/bin/guile"
43
44 # Installing the same package a second time does nothing.
45 guix package --bootstrap -p "$profile" -i guile-bootstrap
46 test -L "$profile" && test -L "$profile-1-link"
47 ! test -f "$profile-2-link"
48 test -f "$profile/bin/guile"
49
50 # No search path env. var. here.
51 guix package --search-paths -p "$profile"
52 test "`guix package --search-paths -p "$profile" | wc -l`" = 0
53
54 # Check whether we have network access.
55 if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
56 then
57 boot_make="(@@ (gnu packages base) gnu-make-boot0)"
58 boot_make_drv="`guix build -e "$boot_make" | grep -v -e -debug`"
59 guix package --bootstrap -p "$profile" -i "$boot_make_drv"
60 test -L "$profile-2-link"
61 test -f "$profile/bin/make" && test -f "$profile/bin/guile"
62
63
64 # Check whether `--list-installed' works.
65 # XXX: Change the tests when `--install' properly extracts the package
66 # name and version string.
67 installed="`guix package -p "$profile" --list-installed | cut -f1 | xargs echo | sort`"
68 case "x$installed" in
69 "guile-bootstrap make-boot0")
70 true;;
71 "make-boot0 guile-bootstrap")
72 true;;
73 "*")
74 false;;
75 esac
76
77 test "`guix package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap"
78
79 # Search.
80 test "`guix package -s "An example GNU package" | grep ^name:`" = \
81 "name: hello"
82 test -z "`guix package -s "n0t4r341p4ck4g3"`"
83
84 # List generations.
85 test "`guix package -p "$profile" -l | cut -f1 | grep guile | head -n1`" \
86 = " guile-bootstrap"
87
88 # Exit with 1 when a generation does not exist.
89 if guix package -p "$profile" --list-generations=42;
90 then false; else true; fi
91
92 # Remove a package.
93 guix package --bootstrap -p "$profile" -r "guile-bootstrap"
94 test -L "$profile-3-link"
95 test -f "$profile/bin/make" && ! test -f "$profile/bin/guile"
96
97 # Roll back.
98 guix package --roll-back -p "$profile"
99 test "`readlink_base "$profile"`" = "$profile-2-link"
100 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
101 guix package --roll-back -p "$profile"
102 test "`readlink_base "$profile"`" = "$profile-1-link"
103 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
104
105 # Move to the empty profile.
106 for i in `seq 1 3`
107 do
108 guix package --bootstrap --roll-back -p "$profile"
109 ! test -f "$profile/bin"
110 ! test -f "$profile/lib"
111 test "`readlink_base "$profile"`" = "$profile-0-link"
112 done
113
114 # Test that '--list-generations' does not output the zeroth generation.
115 test -z "`guix package -p "$profile" -l 0`"
116
117 # Reinstall after roll-back to the empty profile.
118 guix package --bootstrap -p "$profile" -e "$boot_make"
119 test "`readlink_base "$profile"`" = "$profile-1-link"
120 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
121
122 # Check that the first generation is the current one.
123 test "`guix package -p "$profile" -l 1 | cut -f3 | head -n1`" = "(current)"
124
125 # Roll-back to generation 0, and install---all at once.
126 guix package --bootstrap -p "$profile" --roll-back -i guile-bootstrap
127 test "`readlink_base "$profile"`" = "$profile-1-link"
128 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
129
130 # Install Make.
131 guix package --bootstrap -p "$profile" -e "$boot_make"
132 test "`readlink_base "$profile"`" = "$profile-2-link"
133 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
134 grep "`guix build -e "$boot_make"`" "$profile/manifest"
135
136 # Make a "hole" in the list of generations, and make sure we can
137 # roll back "over" it.
138 rm "$profile-1-link"
139 guix package --bootstrap -p "$profile" --roll-back
140 test "`readlink_base "$profile"`" = "$profile-0-link"
141
142 # Make sure LIBRARY_PATH gets listed by `--search-paths'.
143 guix package --bootstrap -p "$profile" -i guile-bootstrap -i gcc-bootstrap
144 guix package --search-paths -p "$profile" | grep LIBRARY_PATH
145
146 # Delete the third generation and check that it was actually deleted.
147 guix package -p "$profile" --delete-generations=3
148 test -z "`guix package -p "$profile" -l 3`"
149
150 # Exit with 1 when a generation does not exist.
151 if guix package -p "$profile" --delete-generations=42;
152 then false; else true; fi
153
154 # Exit with 0 when trying to delete the zeroth generation.
155 guix package -p "$profile" --delete-generations=0
156 fi
157
158 # Make sure the `:' syntax works.
159 guix package --bootstrap -i "binutils:lib" -p "$profile" -n
160
161 # Make sure nonexistent outputs are reported.
162 guix package --bootstrap -i "guile-bootstrap:out" -p "$profile" -n
163 if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile" -n;
164 then false; else true; fi
165 if guix package --bootstrap -i "guile-bootstrap:does-not-exist" -p "$profile";
166 then false; else true; fi
167
168 # Check whether `--list-available' returns something sensible.
169 guix package -p "$profile" -A 'gui.*e' | grep guile
170
171 # There's no generation older than 12 months, so the following command should
172 # have no effect.
173 generation="`readlink_base "$profile"`"
174 if guix package -p "$profile" --delete-generations=12m;
175 then false; else true; fi
176 test "`readlink_base "$profile"`" = "$generation"
177
178 #
179 # Try with the default profile.
180 #
181
182 XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
183 export XDG_CACHE_HOME
184 HOME="t-home-$$"
185 export HOME
186
187 mkdir -p "$HOME"
188
189 guix package --bootstrap -i guile-bootstrap
190 test -L "$HOME/.guix-profile"
191 test -f "$HOME/.guix-profile/bin/guile"
192
193 if guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null
194 then
195 guix package --bootstrap -e "$boot_make"
196 test -f "$HOME/.guix-profile/bin/make"
197 first_environment="`cd $HOME/.guix-profile ; pwd`"
198
199 guix package --bootstrap --roll-back
200 test -f "$HOME/.guix-profile/bin/guile"
201 ! test -f "$HOME/.guix-profile/bin/make"
202 test "`cd $HOME/.guix-profile ; pwd`" = "$first_environment"
203 fi
204
205 # Move to the empty profile.
206 default_profile="`readlink "$HOME/.guix-profile"`"
207 for i in `seq 1 3`
208 do
209 guix package --bootstrap --roll-back
210 ! test -f "$HOME/.guix-profile/bin"
211 ! test -f "$HOME/.guix-profile/lib"
212 test "`readlink "$default_profile"`" = "$default_profile-0-link"
213 done
214
215 # Extraneous argument.
216 if guix package install foo-bar;
217 then false; else true; fi