1 ;;; files-x-tests.el --- tests for files-x.el.
3 ;; Copyright (C) 2016-2017 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 (defvar files-x-test--criteria1
"my-user@my-remote-host")
28 (defvar files-x-test--criteria2
29 (lambda (identification)
30 (string-match "another-user@my-remote-host" identification
)))
31 (defvar files-x-test--criteria3 nil
)
33 (defvar files-x-test--variables1
34 '((remote-shell-file-name .
"/bin/bash")
35 (remote-shell-command-switch .
"-c")
36 (remote-shell-interactive-switch .
"-i")
37 (remote-shell-login-switch .
"-l")))
38 (defvar files-x-test--variables2
39 '((remote-shell-file-name .
"/bin/ksh")))
40 (defvar files-x-test--variables3
41 '((remote-null-device .
"/dev/null")))
42 (defvar files-x-test--variables4
43 '((remote-null-device .
"null")))
45 (ert-deftest files-x-test-connection-local-set-class-variables
()
46 "Test setting connection-local class variables."
48 ;; Declare (CLASS VARIABLES) objects.
49 (let (connection-local-class-alist connection-local-criteria-alist
)
50 (connection-local-set-class-variables 'remote-bash files-x-test--variables1
)
53 (connection-local-get-class-variables 'remote-bash
)
54 files-x-test--variables1
))
56 (connection-local-set-class-variables 'remote-ksh files-x-test--variables2
)
59 (connection-local-get-class-variables 'remote-ksh
)
60 files-x-test--variables2
))
62 (connection-local-set-class-variables
63 'remote-nullfile files-x-test--variables3
)
66 (connection-local-get-class-variables 'remote-nullfile
)
67 files-x-test--variables3
))
69 ;; A redefinition overwrites existing values.
70 (connection-local-set-class-variables
71 'remote-nullfile files-x-test--variables4
)
74 (connection-local-get-class-variables 'remote-nullfile
)
75 files-x-test--variables4
))))
77 (ert-deftest files-x-test-connection-local-set-classes
()
78 "Test setting connection-local classes."
80 ;; Declare (CRITERIA CLASSES) objects.
81 (let (connection-local-class-alist connection-local-criteria-alist
)
82 (connection-local-set-class-variables 'remote-bash files-x-test--variables1
)
83 (connection-local-set-class-variables 'remote-ksh files-x-test--variables2
)
84 (connection-local-set-class-variables
85 'remote-nullfile files-x-test--variables3
)
87 (connection-local-set-classes
88 files-x-test--criteria1
'remote-bash
'remote-ksh
)
91 (connection-local-get-classes files-x-test--criteria1
)
92 '(remote-bash remote-ksh
)))
94 (connection-local-set-classes files-x-test--criteria2
'remote-ksh
)
97 (connection-local-get-classes files-x-test--criteria2
)
99 ;; A further call adds classes.
100 (connection-local-set-classes files-x-test--criteria2
'remote-nullfile
)
103 (connection-local-get-classes files-x-test--criteria2
)
104 '(remote-ksh remote-nullfile
)))
105 ;; Adding existing classes doesn't matter.
106 (connection-local-set-classes
107 files-x-test--criteria2
'remote-bash
'remote-nullfile
)
110 (connection-local-get-classes files-x-test--criteria2
)
111 '(remote-ksh remote-nullfile remote-bash
)))
113 ;; An empty variable list is accepted (but makes no sense).
114 (connection-local-set-classes files-x-test--criteria3
)
115 (should-not (connection-local-get-classes files-x-test--criteria3
))
117 ;; Using a nil criteria also works. Duplicate classes are trashed.
118 (connection-local-set-classes
119 files-x-test--criteria3
'remote-bash
'remote-ksh
'remote-ksh
'remote-bash
)
122 (connection-local-get-classes files-x-test--criteria3
)
123 '(remote-bash remote-ksh
)))
125 ;; A criteria other than nil, regexp or lambda function is wrong.
126 (should-error (connection-local-set-classes 'dummy
))))
128 (ert-deftest files-x-test-hack-connection-local-variables-apply
()
129 "Test setting connection-local variables."
131 (let (connection-local-class-alist connection-local-criteria-alist
)
133 (connection-local-set-class-variables 'remote-bash files-x-test--variables1
)
134 (connection-local-set-class-variables 'remote-ksh files-x-test--variables2
)
135 (connection-local-set-class-variables
136 'remote-nullfile files-x-test--variables3
)
138 (connection-local-set-classes
139 files-x-test--criteria1
'remote-bash
'remote-ksh
)
140 (connection-local-set-classes
141 files-x-test--criteria2
'remote-ksh
'remote-nullfile
)
143 ;; Apply the variables.
145 (let ((enable-connection-local-variables t
)
146 (default-directory "/sudo:my-user@my-remote-host:"))
147 (should-not connection-local-variables-alist
)
148 (should-not (local-variable-p 'remote-shell-file-name
))
149 (should-not (boundp 'remote-shell-file-name
))
150 (hack-connection-local-variables-apply)
151 ;; All connection-local variables are set. They apply in
152 ;; reverse order in `connection-local-variables-alist'. The
153 ;; settings from `remote-ksh' are not contained, because they
154 ;; declare same variables as in `remote-bash'.
156 (equal connection-local-variables-alist
157 (nreverse (copy-tree files-x-test--variables1
))))
158 ;; The variables exist also as local variables.
159 (should (local-variable-p 'remote-shell-file-name
))
160 ;; The proper variable value is set.
162 (string-equal (symbol-value 'remote-shell-file-name
) "/bin/bash"))))
164 ;; The second test case.
166 (let ((enable-connection-local-variables t
)
167 (default-directory "/ssh:another-user@my-remote-host:"))
168 (should-not connection-local-variables-alist
)
169 (should-not (local-variable-p 'remote-shell-file-name
))
170 (should-not (boundp 'remote-shell-file-name
))
171 (hack-connection-local-variables-apply)
172 ;; All connection-local variables are set. They apply in
173 ;; reverse order in `connection-local-variables-alist'.
175 (equal connection-local-variables-alist
177 (nreverse (copy-tree files-x-test--variables3
))
178 (nreverse (copy-tree files-x-test--variables2
)))))
179 ;; The variables exist also as local variables.
180 (should (local-variable-p 'remote-shell-file-name
))
181 ;; The proper variable value is set.
183 (string-equal (symbol-value 'remote-shell-file-name
) "/bin/ksh"))))
185 ;; The third test case. Both `files-x-test--criteria1' and
186 ;; `files-x-test--criteria3' apply, but there are no double
188 (connection-local-set-classes
189 files-x-test--criteria3
'remote-bash
'remote-ksh
)
191 (let ((enable-connection-local-variables t
)
192 (default-directory "/sudo:my-user@my-remote-host:"))
193 (should-not connection-local-variables-alist
)
194 (should-not (local-variable-p 'remote-shell-file-name
))
195 (should-not (boundp 'remote-shell-file-name
))
196 (hack-connection-local-variables-apply)
197 ;; All connection-local variables are set. They apply in
198 ;; reverse order in `connection-local-variables-alist'. The
199 ;; settings from `remote-ksh' are not contained, because they
200 ;; declare same variables as in `remote-bash'.
202 (equal connection-local-variables-alist
203 (nreverse (copy-tree files-x-test--variables1
))))
204 ;; The variables exist also as local variables.
205 (should (local-variable-p 'remote-shell-file-name
))
206 ;; The proper variable value is set.
208 (string-equal (symbol-value 'remote-shell-file-name
) "/bin/bash"))))
210 ;; When `enable-connection-local-variables' is nil, nothing happens.
212 (let ((enable-connection-local-variables nil
)
213 (default-directory "/ssh:another-user@my-remote-host:"))
214 (should-not connection-local-variables-alist
)
215 (should-not (local-variable-p 'remote-shell-file-name
))
216 (should-not (boundp 'remote-shell-file-name
))
217 (hack-connection-local-variables-apply)
218 (should-not connection-local-variables-alist
)
219 (should-not (local-variable-p 'remote-shell-file-name
))
220 (should-not (boundp 'remote-shell-file-name
))))))
222 (ert-deftest files-x-test-with-connection-local-classes
()
223 "Test setting connection-local variables."
225 (let (connection-local-class-alist connection-local-criteria-alist
)
226 (connection-local-set-class-variables 'remote-bash files-x-test--variables1
)
227 (connection-local-set-class-variables 'remote-ksh files-x-test--variables2
)
228 (connection-local-set-class-variables
229 'remote-nullfile files-x-test--variables3
)
230 (connection-local-set-classes
231 files-x-test--criteria3
'remote-ksh
'remote-nullfile
)
234 (let ((enable-connection-local-variables t
)
235 (default-directory "/sudo:my-user@my-remote-host:"))
236 (hack-connection-local-variables-apply)
238 ;; All connection-local variables are set. They apply in
239 ;; reverse order in `connection-local-variables-alist'.
241 (equal connection-local-variables-alist
243 (nreverse (copy-tree files-x-test--variables3
))
244 (nreverse (copy-tree files-x-test--variables2
)))))
245 ;; The variables exist also as local variables.
246 (should (local-variable-p 'remote-shell-file-name
))
247 (should (local-variable-p 'remote-null-device
))
248 ;; The proper variable values are set.
250 (string-equal (symbol-value 'remote-shell-file-name
) "/bin/ksh"))
252 (string-equal (symbol-value 'remote-null-device
) "/dev/null"))
254 ;; A candidate connection-local variable is not bound yet.
255 (should-not (local-variable-p 'remote-shell-command-switch
))
258 (with-connection-local-classes '(remote-bash remote-ksh
)
259 ;; All connection-local variables are set. They apply in
260 ;; reverse order in `connection-local-variables-alist'.
261 ;; This variable keeps only the variables to be set inside
264 (equal connection-local-variables-alist
265 (nreverse (copy-tree files-x-test--variables1
))))
266 ;; The variables exist also as local variables.
267 (should (local-variable-p 'remote-shell-file-name
))
268 (should (local-variable-p 'remote-shell-command-switch
))
269 ;; The proper variable values are set. The settings from
270 ;; `remote-bash' overwrite the same variables as in
273 (string-equal (symbol-value 'remote-shell-file-name
) "/bin/bash"))
275 (string-equal (symbol-value 'remote-shell-command-switch
) "-c")))
277 ;; Everything is rewound. The old variable values are reset.
279 (equal connection-local-variables-alist
281 (nreverse (copy-tree files-x-test--variables3
))
282 (nreverse (copy-tree files-x-test--variables2
)))))
283 ;; The variables exist also as local variables.
284 (should (local-variable-p 'remote-shell-file-name
))
285 (should (local-variable-p 'remote-null-device
))
286 ;; The proper variable values are set. The settings from
287 ;; `remote-ksh' are back.
289 (string-equal (symbol-value 'remote-shell-file-name
) "/bin/ksh"))
291 (string-equal (symbol-value 'remote-null-device
) "/dev/null"))
293 ;; The variable set temporarily is not unbound, again.
294 (should-not (local-variable-p 'remote-shell-command-switch
))))))
296 (provide 'files-x-tests
)
297 ;;; files-x-tests.el ends here