tests: Move 'guix package' tests that require networking to a separate file.
[jackhill/guix/guix.git] / tests / guix-package-net.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. 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 profile="t-profile-$$"
41 rm -f "$profile"
42
43 trap 'rm -f "$profile" "$profile-"[0-9]* ; rm -rf t-home-'"$$" EXIT
44
45
46 guix package --bootstrap -p "$profile" -i guile-bootstrap
47 test -L "$profile" && test -L "$profile-1-link"
48 ! test -f "$profile-2-link"
49 test -f "$profile/bin/guile"
50
51 boot_make="(@@ (gnu packages commencement) gnu-make-boot0)"
52 boot_make_drv="`guix build -e "$boot_make" | grep -v -e -debug`"
53 guix package --bootstrap -p "$profile" -i "$boot_make_drv"
54 test -L "$profile-2-link"
55 test -f "$profile/bin/make" && test -f "$profile/bin/guile"
56
57 # Check whether `--list-installed' works.
58 # XXX: Change the tests when `--install' properly extracts the package
59 # name and version string.
60 installed="`guix package -p "$profile" --list-installed | cut -f1 | xargs echo | sort`"
61 case "x$installed" in
62 "guile-bootstrap make-boot0")
63 true;;
64 "make-boot0 guile-bootstrap")
65 true;;
66 "*")
67 false;;
68 esac
69
70 test "`guix package -p "$profile" -I 'g.*e' | cut -f1`" = "guile-bootstrap"
71
72 # List generations.
73 test "`guix package -p "$profile" -l | cut -f1 | grep guile | head -n1`" \
74 = " guile-bootstrap"
75
76 # Exit with 1 when a generation does not exist.
77 if guix package -p "$profile" --list-generations=42;
78 then false; else true; fi
79 if guix package -p "$profile" --switch-generation=99;
80 then false; else true; fi
81
82 # Remove a package.
83 guix package --bootstrap -p "$profile" -r "guile-bootstrap"
84 test -L "$profile-3-link"
85 test -f "$profile/bin/make" && ! test -f "$profile/bin/guile"
86
87 # Roll back.
88 guix package --roll-back -p "$profile"
89 test "`readlink_base "$profile"`" = "$profile-2-link"
90 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
91 guix package --roll-back -p "$profile"
92 test "`readlink_base "$profile"`" = "$profile-1-link"
93 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
94
95 # Switch to the rolled generation and switch back.
96 guix package -p "$profile" --switch-generation=2
97 test "`readlink_base "$profile"`" = "$profile-2-link"
98 guix package -p "$profile" --switch-generation=-1
99 test "`readlink_base "$profile"`" = "$profile-1-link"
100
101 # Move to the empty profile.
102 for i in `seq 1 3`
103 do
104 guix package --bootstrap --roll-back -p "$profile"
105 ! test -f "$profile/bin"
106 ! test -f "$profile/lib"
107 test "`readlink_base "$profile"`" = "$profile-0-link"
108 done
109
110 # Test that '--list-generations' does not output the zeroth generation.
111 test -z "`guix package -p "$profile" -l 0`"
112
113 # Reinstall after roll-back to the empty profile.
114 guix package --bootstrap -p "$profile" -e "$boot_make"
115 test "`readlink_base "$profile"`" = "$profile-1-link"
116 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
117
118 # Check that the first generation is the current one.
119 test "`guix package -p "$profile" -l 1 | cut -f3 | head -n1`" = "(current)"
120
121 # Roll-back to generation 0, and install---all at once.
122 guix package --bootstrap -p "$profile" --roll-back -i guile-bootstrap
123 test "`readlink_base "$profile"`" = "$profile-1-link"
124 test -x "$profile/bin/guile" && ! test -x "$profile/bin/make"
125
126 # Install Make.
127 guix package --bootstrap -p "$profile" -e "$boot_make"
128 test "`readlink_base "$profile"`" = "$profile-2-link"
129 test -x "$profile/bin/guile" && test -x "$profile/bin/make"
130 grep "`guix build -e "$boot_make"`" "$profile/manifest"
131
132 # Make a "hole" in the list of generations, and make sure we can
133 # roll back and switch "over" it.
134 rm "$profile-1-link"
135 guix package --bootstrap -p "$profile" --roll-back
136 test "`readlink_base "$profile"`" = "$profile-0-link"
137 guix package -p "$profile" --switch-generation=+1
138 test "`readlink_base "$profile"`" = "$profile-2-link"
139
140 # Make sure LIBRARY_PATH gets listed by `--search-paths'.
141 guix package --bootstrap -p "$profile" -i guile-bootstrap -i gcc-bootstrap
142 guix package --search-paths -p "$profile" | grep LIBRARY_PATH
143
144 # Roll back so we can delete #3 below.
145 guix package -p "$profile" --switch-generation=2
146
147 # Delete the third generation and check that it was actually deleted.
148 guix package -p "$profile" --delete-generations=3
149 test -z "`guix package -p "$profile" -l 3`"
150
151
152 #
153 # Try with the default profile.
154 #
155
156 XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
157 export XDG_CACHE_HOME
158 HOME="$PWD/t-home-$$"
159 export HOME
160
161 mkdir -p "$HOME"
162
163 # Get the canonical directory name so that 'guix package' recognizes it.
164 HOME="`cd $HOME; pwd -P`"
165
166 guix package --bootstrap -e "$boot_make"
167 test -f "$HOME/.guix-profile/bin/make"
168
169 guix package --bootstrap --roll-back
170 ! test -f "$HOME/.guix-profile/bin/make"