Commit | Line | Data |
---|---|---|
f535dcbe DT |
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 | ||
6493fd04 LC |
27 | if ! guile -c '((@@ (guix scripts environment) assert-container-features))' |
28 | then | |
29 | # User containers are not supported; skip this test. | |
30 | exit 77 | |
31 | fi | |
32 | ||
f535dcbe DT |
33 | tmpdir="t-guix-environment-$$" |
34 | trap 'rm -r "$tmpdir"' EXIT | |
35 | ||
36 | mkdir "$tmpdir" | |
37 | ||
38 | # Make sure the exit value is preserved. | |
39 | if guix environment --container --ad-hoc --bootstrap guile-bootstrap \ | |
40 | -- guile -c '(exit 42)' | |
41 | then | |
42 | false | |
43 | else | |
44 | test $? = 42 | |
45 | fi | |
46 | ||
c06f6db7 LC |
47 | # Make sure file-not-found errors in mounts are reported. |
48 | if guix environment --container --ad-hoc --bootstrap guile-bootstrap \ | |
49 | --expose=/does-not-exist -- guile -c 1 2> "$tmpdir/error" | |
50 | then | |
51 | false | |
52 | else | |
53 | grep "/does-not-exist" "$tmpdir/error" | |
54 | grep "[Nn]o such file" "$tmpdir/error" | |
55 | fi | |
56 | ||
f535dcbe DT |
57 | # Make sure that the right directories are mapped. |
58 | mount_test_code=" | |
59 | (use-modules (ice-9 rdelim) | |
60 | (ice-9 match) | |
61 | (srfi srfi-1)) | |
62 | ||
63 | (define mappings | |
64 | (filter-map (lambda (line) | |
65 | (match (string-split line #\space) | |
66 | ;; Empty line. | |
67 | ((\"\") #f) | |
1250034d LC |
68 | ;; Ignore the root file system. |
69 | ((_ \"/\" _ _ _ _) | |
f535dcbe | 70 | #f) |
1250034d LC |
71 | ;; Ignore these types of file systems, except if they |
72 | ;; correspond to a parent file system. | |
73 | ((_ mount (or \"tmpfs\" \"proc\" \"sysfs\" \"devtmpfs\" | |
74 | \"devpts\" \"cgroup\" \"mqueue\") _ _ _) | |
7cdec6a9 | 75 | (and (string-prefix? (getcwd) mount) |
1250034d | 76 | mount)) |
f535dcbe DT |
77 | ((_ mount _ _ _ _) |
78 | mount))) | |
79 | (string-split (call-with-input-file \"/proc/mounts\" read-string) | |
80 | #\newline))) | |
81 | ||
82 | (for-each (lambda (mount) | |
83 | (display mount) | |
84 | (newline)) | |
85 | mappings)" | |
86 | ||
87 | guix environment --container --ad-hoc --bootstrap guile-bootstrap \ | |
88 | -- guile -c "$mount_test_code" > $tmpdir/mounts | |
89 | ||
855038b2 | 90 | cat "$tmpdir/mounts" |
779aa003 | 91 | test `wc -l < $tmpdir/mounts` -eq 4 |
f535dcbe | 92 | |
c8855b99 LC |
93 | current_dir="`cd $PWD; pwd -P`" |
94 | grep -e "$current_dir$" $tmpdir/mounts # current directory | |
f535dcbe DT |
95 | grep $(guix build guile-bootstrap) $tmpdir/mounts |
96 | grep -e "$NIX_STORE_DIR/.*-bash" $tmpdir/mounts # bootstrap bash | |
97 | ||
98 | rm $tmpdir/mounts | |
82e64fc1 | 99 | |
07ec3492 MG |
100 | # Make sure 'GUIX_ENVIRONMENT' is linked to '~/.guix-profile' when requested |
101 | # within a container. | |
102 | ( | |
103 | linktest='(exit (string=? (getenv "GUIX_ENVIRONMENT") | |
104 | (readlink (string-append (getenv "HOME") "/.guix-profile"))))' | |
105 | ||
106 | cd "$tmpdir" \ | |
107 | && guix environment --bootstrap --container --link-profile \ | |
108 | --ad-hoc guile-bootstrap --pure \ | |
109 | -- guile -c "$linktest" | |
110 | ) | |
111 | ||
112 | # Check the exit code. | |
113 | ||
13bc8d5e DT |
114 | abnormal_exit_code=" |
115 | (use-modules (system foreign)) | |
116 | ;; Purposely make Guile crash with a segfault. :) | |
117 | (pointer->string (make-pointer 123) 123)" | |
118 | ||
82e64fc1 | 119 | if guix environment --bootstrap --container \ |
13bc8d5e | 120 | --ad-hoc guile-bootstrap -- guile -c "$abnormal_exit_code" |
82e64fc1 LC |
121 | then false; |
122 | else | |
123 | test $? -gt 127 | |
124 | fi |