tests: Remove 't-profile-alt-*-link' files.
[jackhill/guix/guix.git] / tests / guix-package-net.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2012, 2013, 2014, 2015, 2017 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. This test requires network
22 # access and is skipped when that is lacking.
23 #
24
25 guix package --version
26
27 readlink_base ()
28 {
29 basename `readlink "$1"`
30 }
31
32 # Return true if a typical shebang in the store would exceed Linux's default
33 # static limit.
34 shebang_too_long ()
35 {
36 test `echo $NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bootstrap-binaries-0/bin/bash | wc -c` \
37 -ge 128
38 }
39
40 if ! guile -c '(getaddrinfo "www.gnu.org" "80" AI_NUMERICSERV)' 2> /dev/null \
41 || shebang_too_long
42 then
43 # Skipping.
44 exit 77
45 fi
46
47
48 profile="t-profile-$$"
49 profile_alt="t-profile-alt-$$"
50 rm -f "$profile"
51
52 trap 'rm -f "$profile" "$profile_alt" "$profile-"[0-9]* "$profile_alt-"[0-9]* ; rm -rf t-home-'"$$" EXIT
53
54
55 guix package --bootstrap -p "$profile" -i guile-bootstrap
56 test -L "$profile" && test -L "$profile-1-link"
57 ! test -f "$profile-2-link"
58 test -f "$profile/bin/guile"
59
60 boot_make="(@@ (gnu packages commencement) gnu-make-boot0)"
61 boot_make_drv="`guix build -e "$boot_make" | grep -v -e -debug`"
62 guix package --bootstrap -p "$profile" -i "$boot_make_drv"
63 test -L "$profile-2-link"
64 test -f "$profile/bin/make" && test -f "$profile/bin/guile"
65
66 # Check whether `--list-installed' works.
67 # XXX: Change the tests when `--install' properly extracts the package
68 # name and version string.
69 installed="`guix package -p "$profile" --list-installed | cut -f1 | xargs echo | sort`"
70 case "x$installed" in
71 "guile-bootstrap make-boot0")
72 true;;
73 "make-boot0 guile-bootstrap")
74 true;;
75 "*")
76 false;;
77 esac
78
79 test "`guix package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap"
80
81 # List generations.
82 test "`guix package -p "$profile" -l | cut -f1 | grep guile | head -n1`" \
83 = " guile-bootstrap"
84
85 # Exit with 1 when a generation does not exist.
86 if guix package -p "$profile" --list-generations=42;
87 then false; else true; fi
88 if guix package -p "$profile" --switch-generation=99;
89 then false; else true; fi
90
91 # Remove a package.
92 guix package --bootstrap -p "$profile" -r "guile-bootstrap"
93 test -L "$profile-3-link"
94 test -f "$profile/bin/make" && ! test -f "$profile/bin/guile"
95
96 # Roll back.
97 guix package --roll-back -p "$profile"
98 test "`readlink_base "$profile"`" = "$profile-2-link"
99 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
100 guix package --roll-back -p "$profile"
101 test "`readlink_base "$profile"`" = "$profile-1-link"
102 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
103
104 # Switch to the rolled generation and switch back.
105 guix package -p "$profile" --switch-generation=2
106 test "`readlink_base "$profile"`" = "$profile-2-link"
107 guix package -p "$profile" --switch-generation=-1
108 test "`readlink_base "$profile"`" = "$profile-1-link"
109
110 # Move to the empty profile.
111 for i in `seq 1 3`
112 do
113 guix package --bootstrap --roll-back -p "$profile"
114 ! test -f "$profile/bin"
115 ! test -f "$profile/lib"
116 test "`readlink_base "$profile"`" = "$profile-0-link"
117 done
118
119 # Test that '--list-generations' does not output the zeroth generation.
120 test -z "`guix package -p "$profile" -l 0`"
121
122 # Reinstall after roll-back to the empty profile.
123 guix package --bootstrap -p "$profile" -e "$boot_make"
124 test "`readlink_base "$profile"`" = "$profile-1-link"
125 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
126
127 # Check that the first generation is the current one.
128 test "`guix package -p "$profile" -l 1 | cut -f3 | head -n1`" = "(current)"
129
130 # Roll-back to generation 0, and install---all at once.
131 guix package --bootstrap -p "$profile" --roll-back -i guile-bootstrap
132 test "`readlink_base "$profile"`" = "$profile-1-link"
133 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
134
135 # Install Make.
136 guix package --bootstrap -p "$profile" -e "$boot_make"
137 test "`readlink_base "$profile"`" = "$profile-2-link"
138 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
139 grep "`guix build -e "$boot_make"`" "$profile/manifest"
140
141 # Make a "hole" in the list of generations, and make sure we can
142 # roll back and switch "over" it.
143 rm "$profile-1-link"
144 guix package --bootstrap -p "$profile" --roll-back
145 test "`readlink_base "$profile"`" = "$profile-0-link"
146 guix package -p "$profile" --switch-generation=+1
147 test "`readlink_base "$profile"`" = "$profile-2-link"
148
149 # Make sure LIBRARY_PATH gets listed by `--search-paths'.
150 guix package --bootstrap -p "$profile" -i guile-bootstrap -i gcc-bootstrap
151 guix package -p "$profile" --search-paths | grep LIBRARY_PATH
152
153 # Roll back so we can delete #3 below.
154 guix package -p "$profile" --switch-generation=2
155
156 # Delete the third generation and check that it was actually deleted.
157 guix package -p "$profile" --delete-generations=3
158 test -z "`guix package -p "$profile" -l 3`"
159
160 # Search path of combined profiles. 'LIBRARY_PATH' should show up only in the
161 # combination, not in the individual profiles.
162 rm "$profile"
163 guix package --bootstrap -p "$profile" -i guile-bootstrap
164 guix package --bootstrap -p "$profile_alt" -i gcc-bootstrap
165 if guix package -p "$profile" --search-paths | grep LIBRARY_PATH
166 then false; fi
167 guix package -p "$profile" -p "$profile_alt" --search-paths \
168 | grep "LIBRARY_PATH.*$profile/lib.$profile_alt/lib"
169
170 #
171 # Try with the default profile.
172 #
173
174 XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
175 export XDG_CACHE_HOME
176 HOME="$PWD/t-home-$$"
177 export HOME
178
179 mkdir -p "$HOME"
180
181 # Get the canonical directory name so that 'guix package' recognizes it.
182 HOME="`cd $HOME; pwd -P`"
183
184 guix package --bootstrap -e "$boot_make"
185 test -f "$HOME/.guix-profile/bin/make"
186
187 guix package --bootstrap --roll-back
188 ! test -f "$HOME/.guix-profile/bin/make"