ui: Improve reporting of missing closing parentheses.
[jackhill/guix/guix.git] / tests / guix-system.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
3 #
4 # This file is part of GNU Guix.
5 #
6 # GNU Guix is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or (at
9 # your option) any later version.
10 #
11 # GNU Guix is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19 #
20 # Test 'guix system', mostly error reporting.
21 #
22
23 set -e
24
25 guix system --version
26
27 tmpfile="t-guix-system-$$"
28 errorfile="t-guix-system-error-$$"
29
30 # Note: This directory is chosen outside $builddir so that relative file name
31 # canonicalization doesn't mess up with 'current-source-directory', used by
32 # 'local-file' ('load' forces 'relative' for
33 # %FILE-PORT-NAME-CANONICALIZATION.)
34 tmpdir="${TMPDIR:-/tmp}/t-guix-system-$$"
35 mkdir "$tmpdir"
36
37 trap 'rm -f "$tmpfile" "$errorfile" "$tmpdir"/*; rmdir "$tmpdir"' EXIT
38
39 # Reporting of syntax errors.
40
41 cat > "$tmpfile"<<EOF
42 ;; This is line 1, and the next one is line 2.
43 (operating-system)
44 ;; The 'T' is at column 3.
45 EOF
46
47 if guix system vm "$tmpfile" 2> "$errorfile"
48 then
49 # This must not succeed.
50 exit 1
51 else
52 grep "$tmpfile:2:3:.*missing.* initializers" "$errorfile"
53 fi
54
55
56 cat > "$tmpfile"<<EOF
57 ;; This is line 1, and the next one is line 2.
58 (operating-system
59 ;; This is line 3, and there is no closing paren!
60 EOF
61
62 if guix system vm "$tmpfile" 2> "$errorfile"
63 then
64 # This must not succeed.
65 exit 1
66 else
67 grep "$tmpfile:4:1: missing closing paren" "$errorfile"
68 fi
69
70
71 # Reporting of unbound variables.
72
73 cat > "$tmpfile" <<EOF
74 (use-modules (gnu)) ; 1
75 (use-service-modules networking) ; 2
76
77 (operating-system ; 4
78 (host-name "antelope") ; 5
79 (timezone "Europe/Paris") ; 6
80 (locale "en_US.UTF-8") ; 7
81
82 (bootloader (GRUB-config (device "/dev/sdX"))) ; 9
83 (file-systems (cons (file-system
84 (device "root")
85 (title 'label)
86 (mount-point "/")
87 (type "ext4"))
88 %base-file-systems)))
89 EOF
90
91 if guix system build "$tmpfile" -n 2> "$errorfile"
92 then false
93 else
94 if test "`guile -c '(display (effective-version))'`" = 2.2
95 then
96 # FIXME: With Guile 2.2.0 the error is reported on line 4.
97 # See <http://bugs.gnu.org/26107>.
98 grep "$tmpfile:[49]:.*[Uu]nbound variable.*GRUB-config" "$errorfile"
99 else
100 grep "$tmpfile:9:.*[Uu]nbound variable.*GRUB-config" "$errorfile"
101 fi
102 fi
103
104 OS_BASE='
105 (host-name "antelope")
106 (timezone "Europe/Paris")
107 (locale "en_US.UTF-8")
108
109 (bootloader (grub-configuration (device "/dev/sdX")))
110 (file-systems (cons (file-system
111 (device "root")
112 (title (string->symbol "label"))
113 (mount-point "/")
114 (type "ext4"))
115 %base-file-systems))
116 '
117
118 # Reporting of duplicate service identifiers.
119
120 cat > "$tmpfile" <<EOF
121 (use-modules (gnu))
122 (use-service-modules networking)
123
124 (operating-system
125 $OS_BASE
126 (services (cons* (dhcp-client-service)
127 (dhcp-client-service) ;twice!
128 %base-services)))
129 EOF
130
131 if guix system vm "$tmpfile" 2> "$errorfile"
132 then
133 # This must not succeed.
134 exit 1
135 else
136 grep "service 'networking'.*more than once" "$errorfile"
137 fi
138
139 # Reporting unmet shepherd requirements.
140
141 cat > "$tmpfile" <<EOF
142 (use-modules (gnu) (gnu services shepherd))
143 (use-service-modules networking)
144
145 (define buggy-service-type
146 (shepherd-service-type
147 'buggy
148 (lambda _
149 (shepherd-service
150 (provision '(buggy!))
151 (requirement '(does-not-exist))
152 (start #t)))))
153
154 (operating-system
155 $OS_BASE
156 (services (cons (service buggy-service-type #t)
157 %base-services)))
158 EOF
159
160 if guix system build "$tmpfile" 2> "$errorfile"
161 then
162 exit 1
163 else
164 grep "service 'buggy!'.*'does-not-exist'.*not provided" "$errorfile"
165 fi
166
167 # Reporting inconsistent user accounts.
168
169 make_user_config ()
170 {
171 cat > "$tmpfile" <<EOF
172 (use-modules (gnu))
173 (use-service-modules networking)
174
175 (operating-system
176 (host-name "antelope")
177 (timezone "Europe/Paris")
178 (locale "en_US.UTF-8")
179
180 (bootloader (grub-configuration (device "/dev/sdX")))
181 (file-systems (cons (file-system
182 (device "root")
183 (title 'label)
184 (mount-point "/")
185 (type "ext4"))
186 %base-file-systems))
187 (users (list (user-account
188 (name "dave")
189 (home-directory "/home/dave")
190 (group "$1")
191 (supplementary-groups '("$2"))))))
192 EOF
193 }
194
195 make_user_config "users" "wheel"
196 guix system build "$tmpfile" -n # succeeds
197
198 guix system build "$tmpfile" -d # succeeds
199 guix system build "$tmpfile" -d | grep '\.drv$'
200
201 guix system vm "$tmpfile" -d # succeeds
202 guix system vm "$tmpfile" -d | grep '\.drv$'
203
204 make_user_config "group-that-does-not-exist" "users"
205 if guix system build "$tmpfile" -n 2> "$errorfile"
206 then false
207 else grep "primary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
208
209 make_user_config "users" "group-that-does-not-exist"
210 if guix system build "$tmpfile" -n 2> "$errorfile"
211 then false
212 else grep "supplementary group.*group-that-does-not-exist.*undeclared" "$errorfile"; fi
213
214 # Try 'local-file' and relative file name resolution.
215
216 cat > "$tmpdir/config.scm"<<EOF
217 (use-modules (gnu))
218 (use-service-modules networking)
219
220 (operating-system
221 $OS_BASE
222 (services (cons (tor-service (local-file "my-torrc"))
223 %base-services)))
224 EOF
225
226 cat > "$tmpdir/my-torrc"<<EOF
227 # This is an example file.
228 EOF
229
230 # In both cases 'my-torrc' should be properly resolved.
231 guix system build "$tmpdir/config.scm" -n
232 (cd "$tmpdir"; guix system build "config.scm" -n)
233
234 # Searching.
235 guix system search tor | grep "^name: tor"
236 guix system search anonym network | grep "^name: tor"