Merge branch 'master' into dbus-update
[jackhill/guix/guix.git] / tests / guix-environment-container.sh
1 # GNU Guix --- Functional package management for GNU
2 # Copyright © 2015 David Thompson <davet@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 environment'.
21 #
22
23 set -e
24
25 guix environment --version
26
27 tmpdir="t-guix-environment-$$"
28 trap 'rm -r "$tmpdir"' EXIT
29
30 mkdir "$tmpdir"
31
32 # Make sure the exit value is preserved.
33 if guix environment --container --ad-hoc --bootstrap guile-bootstrap \
34 -- guile -c '(exit 42)'
35 then
36 false
37 else
38 test $? = 42
39 fi
40
41 # Make sure that the right directories are mapped.
42 mount_test_code="
43 (use-modules (ice-9 rdelim)
44 (ice-9 match)
45 (srfi srfi-1))
46
47 (define mappings
48 (filter-map (lambda (line)
49 (match (string-split line #\space)
50 ;; Empty line.
51 ((\"\") #f)
52 ;; Ignore these types of file systems.
53 ((_ _ (or \"tmpfs\" \"proc\" \"sysfs\" \"devtmpfs\"
54 \"devpts\" \"cgroup\" \"mqueue\") _ _ _)
55 #f)
56 ((_ mount _ _ _ _)
57 mount)))
58 (string-split (call-with-input-file \"/proc/mounts\" read-string)
59 #\newline)))
60
61 (for-each (lambda (mount)
62 (display mount)
63 (newline))
64 mappings)"
65
66 guix environment --container --ad-hoc --bootstrap guile-bootstrap \
67 -- guile -c "$mount_test_code" > $tmpdir/mounts
68
69 cat "$tmpdir/mounts"
70 test `wc -l < $tmpdir/mounts` -eq 3
71
72 grep -e "$PWD$" $tmpdir/mounts # current directory
73 grep $(guix build guile-bootstrap) $tmpdir/mounts
74 grep -e "$NIX_STORE_DIR/.*-bash" $tmpdir/mounts # bootstrap bash
75
76 rm $tmpdir/mounts