]> code.delx.au - gnu-emacs/blob - test/lisp/net/tramp-tests.el
Merge from origin/emacs-25
[gnu-emacs] / test / lisp / net / tramp-tests.el
1 ;;; tramp-tests.el --- Tests of remote file access
2
3 ;; Copyright (C) 2013-2016 Free Software Foundation, Inc.
4
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
6
7 ;; This program is free software: you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License as
9 ;; published by the Free Software Foundation, either version 3 of the
10 ;; License, or (at your option) any later version.
11 ;;
12 ;; This program 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 GNU
15 ;; General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see `http://www.gnu.org/licenses/'.
19
20 ;;; Commentary:
21
22 ;; The tests require a recent ert.el from Emacs 24.4.
23
24 ;; Some of the tests require access to a remote host files. Since
25 ;; this could be problematic, a mock-up connection method "mock" is
26 ;; used. Emulating a remote connection, it simply calls "sh -i".
27 ;; Tramp's file name handlers still run, so this test is sufficient
28 ;; except for connection establishing.
29
30 ;; If you want to test a real Tramp connection, set
31 ;; $REMOTE_TEMPORARY_FILE_DIRECTORY to a suitable value in order to
32 ;; overwrite the default value. If you want to skip tests accessing a
33 ;; remote host, set this environment variable to "/dev/null" or
34 ;; whatever is appropriate on your system.
35
36 ;; A whole test run can be performed calling the command `tramp-test-all'.
37
38 ;;; Code:
39
40 (require 'ert)
41 (require 'tramp)
42 (require 'vc)
43 (require 'vc-bzr)
44 (require 'vc-git)
45 (require 'vc-hg)
46
47 (autoload 'dired-uncache "dired")
48 (declare-function tramp-find-executable "tramp-sh")
49 (declare-function tramp-get-remote-path "tramp-sh")
50 (declare-function tramp-get-remote-stat "tramp-sh")
51 (declare-function tramp-get-remote-perl "tramp-sh")
52 (defvar tramp-copy-size-limit)
53 (defvar tramp-persistency-file-name)
54 (defvar tramp-remote-process-environment)
55
56 ;; There is no default value on w32 systems, which could work out of the box.
57 (defconst tramp-test-temporary-file-directory
58 (cond
59 ((getenv "REMOTE_TEMPORARY_FILE_DIRECTORY"))
60 ((eq system-type 'windows-nt) null-device)
61 (t (add-to-list
62 'tramp-methods
63 '("mock"
64 (tramp-login-program "sh")
65 (tramp-login-args (("-i")))
66 (tramp-remote-shell "/bin/sh")
67 (tramp-remote-shell-args ("-c"))
68 (tramp-connection-timeout 10)))
69 (format "/mock::%s" temporary-file-directory)))
70 "Temporary directory for Tramp tests.")
71
72 (setq password-cache-expiry nil
73 tramp-verbose 0
74 tramp-copy-size-limit nil
75 tramp-message-show-message nil
76 tramp-persistency-file-name nil)
77
78 ;; This shall happen on hydra only.
79 (when (getenv "NIX_STORE")
80 (add-to-list 'tramp-remote-path 'tramp-own-remote-path))
81
82 (defvar tramp--test-enabled-checked nil
83 "Cached result of `tramp--test-enabled'.
84 If the function did run, the value is a cons cell, the `cdr'
85 being the result.")
86
87 (defun tramp--test-enabled ()
88 "Whether remote file access is enabled."
89 (unless (consp tramp--test-enabled-checked)
90 (setq
91 tramp--test-enabled-checked
92 (cons
93 t (ignore-errors
94 (and
95 (file-remote-p tramp-test-temporary-file-directory)
96 (file-directory-p tramp-test-temporary-file-directory)
97 (file-writable-p tramp-test-temporary-file-directory))))))
98
99 (when (cdr tramp--test-enabled-checked)
100 ;; Cleanup connection.
101 (ignore-errors
102 (tramp-cleanup-connection
103 (tramp-dissect-file-name tramp-test-temporary-file-directory)
104 nil 'keep-password)))
105
106 ;; Return result.
107 (cdr tramp--test-enabled-checked))
108
109 (defun tramp--test-make-temp-name (&optional local)
110 "Create a temporary file name for test."
111 (expand-file-name
112 (make-temp-name "tramp-test")
113 (if local temporary-file-directory tramp-test-temporary-file-directory)))
114
115 (defmacro tramp--instrument-test-case (verbose &rest body)
116 "Run BODY with `tramp-verbose' equal VERBOSE.
117 Print the the content of the Tramp debug buffer, if BODY does not
118 eval properly in `should', `should-not' or `should-error'. BODY
119 shall not contain a timeout."
120 (declare (indent 1) (debug (natnump body)))
121 `(let ((tramp-verbose ,verbose)
122 (tramp-message-show-message t)
123 (tramp-debug-on-error t)
124 (debug-ignored-errors
125 (cons "^make-symbolic-link not supported$" debug-ignored-errors)))
126 (unwind-protect
127 (progn ,@body)
128 (when (> tramp-verbose 3)
129 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
130 (with-current-buffer (tramp-get-connection-buffer v)
131 (message "%s" (buffer-string)))
132 (with-current-buffer (tramp-get-debug-buffer v)
133 (message "%s" (buffer-string))))))))
134
135 (ert-deftest tramp-test00-availability ()
136 "Test availability of Tramp functions."
137 :expected-result (if (tramp--test-enabled) :passed :failed)
138 (message "Remote directory: `%s'" tramp-test-temporary-file-directory)
139 (should (ignore-errors
140 (and
141 (file-remote-p tramp-test-temporary-file-directory)
142 (file-directory-p tramp-test-temporary-file-directory)
143 (file-writable-p tramp-test-temporary-file-directory)))))
144
145 (ert-deftest tramp-test01-file-name-syntax ()
146 "Check remote file name syntax."
147 ;; Simple cases.
148 (should (tramp-tramp-file-p "/method::"))
149 (should (tramp-tramp-file-p "/host:"))
150 (should (tramp-tramp-file-p "/user@:"))
151 (should (tramp-tramp-file-p "/user@host:"))
152 (should (tramp-tramp-file-p "/method:host:"))
153 (should (tramp-tramp-file-p "/method:user@:"))
154 (should (tramp-tramp-file-p "/method:user@host:"))
155 (should (tramp-tramp-file-p "/method:user@email@host:"))
156
157 ;; Using a port.
158 (should (tramp-tramp-file-p "/host#1234:"))
159 (should (tramp-tramp-file-p "/user@host#1234:"))
160 (should (tramp-tramp-file-p "/method:host#1234:"))
161 (should (tramp-tramp-file-p "/method:user@host#1234:"))
162
163 ;; Using an IPv4 address.
164 (should (tramp-tramp-file-p "/1.2.3.4:"))
165 (should (tramp-tramp-file-p "/user@1.2.3.4:"))
166 (should (tramp-tramp-file-p "/method:1.2.3.4:"))
167 (should (tramp-tramp-file-p "/method:user@1.2.3.4:"))
168
169 ;; Using an IPv6 address.
170 (should (tramp-tramp-file-p "/[]:"))
171 (should (tramp-tramp-file-p "/[::1]:"))
172 (should (tramp-tramp-file-p "/user@[::1]:"))
173 (should (tramp-tramp-file-p "/method:[::1]:"))
174 (should (tramp-tramp-file-p "/method:user@[::1]:"))
175
176 ;; Local file name part.
177 (should (tramp-tramp-file-p "/host:/:"))
178 (should (tramp-tramp-file-p "/method:::"))
179 (should (tramp-tramp-file-p "/method::/path/to/file"))
180 (should (tramp-tramp-file-p "/method::file"))
181
182 ;; Multihop.
183 (should (tramp-tramp-file-p "/method1:|method2::"))
184 (should (tramp-tramp-file-p "/method1:host1|host2:"))
185 (should (tramp-tramp-file-p "/method1:host1|method2:host2:"))
186 (should (tramp-tramp-file-p "/method1:user1@host1|method2:user2@host2:"))
187 (should (tramp-tramp-file-p
188 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:"))
189
190 ;; No strings.
191 (should-not (tramp-tramp-file-p nil))
192 (should-not (tramp-tramp-file-p 'symbol))
193 ;; "/:" suppresses file name handlers.
194 (should-not (tramp-tramp-file-p "/::"))
195 (should-not (tramp-tramp-file-p "/:@:"))
196 (should-not (tramp-tramp-file-p "/:[]:"))
197 ;; Multihops require a method.
198 (should-not (tramp-tramp-file-p "/host1|host2:"))
199 ;; Methods or hostnames shall be at least two characters on MS Windows.
200 (when (memq system-type '(cygwin windows-nt))
201 (should-not (tramp-tramp-file-p "/c:/path/to/file"))
202 (should-not (tramp-tramp-file-p "/c::/path/to/file"))))
203
204 (ert-deftest tramp-test02-file-name-dissect ()
205 "Check remote file name components."
206 (let ((tramp-default-method "default-method")
207 (tramp-default-user "default-user")
208 (tramp-default-host "default-host"))
209 ;; Expand `tramp-default-user' and `tramp-default-host'.
210 (should (string-equal
211 (file-remote-p "/method::")
212 (format "/%s:%s@%s:" "method" "default-user" "default-host")))
213 (should (string-equal (file-remote-p "/method::" 'method) "method"))
214 (should (string-equal (file-remote-p "/method::" 'user) "default-user"))
215 (should (string-equal (file-remote-p "/method::" 'host) "default-host"))
216 (should (string-equal (file-remote-p "/method::" 'localname) ""))
217 (should (string-equal (file-remote-p "/method::" 'hop) nil))
218
219 ;; Expand `tramp-default-method' and `tramp-default-user'.
220 (should (string-equal
221 (file-remote-p "/host:")
222 (format "/%s:%s@%s:" "default-method" "default-user" "host")))
223 (should (string-equal (file-remote-p "/host:" 'method) "default-method"))
224 (should (string-equal (file-remote-p "/host:" 'user) "default-user"))
225 (should (string-equal (file-remote-p "/host:" 'host) "host"))
226 (should (string-equal (file-remote-p "/host:" 'localname) ""))
227 (should (string-equal (file-remote-p "/host:" 'hop) nil))
228
229 ;; Expand `tramp-default-method' and `tramp-default-host'.
230 (should (string-equal
231 (file-remote-p "/user@:")
232 (format "/%s:%s@%s:" "default-method""user" "default-host")))
233 (should (string-equal (file-remote-p "/user@:" 'method) "default-method"))
234 (should (string-equal (file-remote-p "/user@:" 'user) "user"))
235 (should (string-equal (file-remote-p "/user@:" 'host) "default-host"))
236 (should (string-equal (file-remote-p "/user@:" 'localname) ""))
237 (should (string-equal (file-remote-p "/user@:" 'hop) nil))
238
239 ;; Expand `tramp-default-method'.
240 (should (string-equal
241 (file-remote-p "/user@host:")
242 (format "/%s:%s@%s:" "default-method" "user" "host")))
243 (should (string-equal
244 (file-remote-p "/user@host:" 'method) "default-method"))
245 (should (string-equal (file-remote-p "/user@host:" 'user) "user"))
246 (should (string-equal (file-remote-p "/user@host:" 'host) "host"))
247 (should (string-equal (file-remote-p "/user@host:" 'localname) ""))
248 (should (string-equal (file-remote-p "/user@host:" 'hop) nil))
249
250 ;; Expand `tramp-default-user'.
251 (should (string-equal
252 (file-remote-p "/method:host:")
253 (format "/%s:%s@%s:" "method" "default-user" "host")))
254 (should (string-equal (file-remote-p "/method:host:" 'method) "method"))
255 (should (string-equal (file-remote-p "/method:host:" 'user) "default-user"))
256 (should (string-equal (file-remote-p "/method:host:" 'host) "host"))
257 (should (string-equal (file-remote-p "/method:host:" 'localname) ""))
258 (should (string-equal (file-remote-p "/method:host:" 'hop) nil))
259
260 ;; Expand `tramp-default-host'.
261 (should (string-equal
262 (file-remote-p "/method:user@:")
263 (format "/%s:%s@%s:" "method" "user" "default-host")))
264 (should (string-equal (file-remote-p "/method:user@:" 'method) "method"))
265 (should (string-equal (file-remote-p "/method:user@:" 'user) "user"))
266 (should (string-equal (file-remote-p "/method:user@:" 'host)
267 "default-host"))
268 (should (string-equal (file-remote-p "/method:user@:" 'localname) ""))
269 (should (string-equal (file-remote-p "/method:user@:" 'hop) nil))
270
271 ;; No expansion.
272 (should (string-equal
273 (file-remote-p "/method:user@host:")
274 (format "/%s:%s@%s:" "method" "user" "host")))
275 (should (string-equal
276 (file-remote-p "/method:user@host:" 'method) "method"))
277 (should (string-equal (file-remote-p "/method:user@host:" 'user) "user"))
278 (should (string-equal (file-remote-p "/method:user@host:" 'host) "host"))
279 (should (string-equal (file-remote-p "/method:user@host:" 'localname) ""))
280 (should (string-equal (file-remote-p "/method:user@host:" 'hop) nil))
281
282 ;; No expansion.
283 (should (string-equal
284 (file-remote-p "/method:user@email@host:")
285 (format "/%s:%s@%s:" "method" "user@email" "host")))
286 (should (string-equal
287 (file-remote-p "/method:user@email@host:" 'method) "method"))
288 (should (string-equal
289 (file-remote-p "/method:user@email@host:" 'user) "user@email"))
290 (should (string-equal
291 (file-remote-p "/method:user@email@host:" 'host) "host"))
292 (should (string-equal
293 (file-remote-p "/method:user@email@host:" 'localname) ""))
294 (should (string-equal
295 (file-remote-p "/method:user@email@host:" 'hop) nil))
296
297 ;; Expand `tramp-default-method' and `tramp-default-user'.
298 (should (string-equal
299 (file-remote-p "/host#1234:")
300 (format "/%s:%s@%s:" "default-method" "default-user" "host#1234")))
301 (should (string-equal
302 (file-remote-p "/host#1234:" 'method) "default-method"))
303 (should (string-equal (file-remote-p "/host#1234:" 'user) "default-user"))
304 (should (string-equal (file-remote-p "/host#1234:" 'host) "host#1234"))
305 (should (string-equal (file-remote-p "/host#1234:" 'localname) ""))
306 (should (string-equal (file-remote-p "/host#1234:" 'hop) nil))
307
308 ;; Expand `tramp-default-method'.
309 (should (string-equal
310 (file-remote-p "/user@host#1234:")
311 (format "/%s:%s@%s:" "default-method" "user" "host#1234")))
312 (should (string-equal
313 (file-remote-p "/user@host#1234:" 'method) "default-method"))
314 (should (string-equal (file-remote-p "/user@host#1234:" 'user) "user"))
315 (should (string-equal (file-remote-p "/user@host#1234:" 'host) "host#1234"))
316 (should (string-equal (file-remote-p "/user@host#1234:" 'localname) ""))
317 (should (string-equal (file-remote-p "/user@host#1234:" 'hop) nil))
318
319 ;; Expand `tramp-default-user'.
320 (should (string-equal
321 (file-remote-p "/method:host#1234:")
322 (format "/%s:%s@%s:" "method" "default-user" "host#1234")))
323 (should (string-equal
324 (file-remote-p "/method:host#1234:" 'method) "method"))
325 (should (string-equal
326 (file-remote-p "/method:host#1234:" 'user) "default-user"))
327 (should (string-equal
328 (file-remote-p "/method:host#1234:" 'host) "host#1234"))
329 (should (string-equal (file-remote-p "/method:host#1234:" 'localname) ""))
330 (should (string-equal (file-remote-p "/method:host#1234:" 'hop) nil))
331
332 ;; No expansion.
333 (should (string-equal
334 (file-remote-p "/method:user@host#1234:")
335 (format "/%s:%s@%s:" "method" "user" "host#1234")))
336 (should (string-equal
337 (file-remote-p "/method:user@host#1234:" 'method) "method"))
338 (should (string-equal
339 (file-remote-p "/method:user@host#1234:" 'user) "user"))
340 (should (string-equal
341 (file-remote-p "/method:user@host#1234:" 'host) "host#1234"))
342 (should (string-equal
343 (file-remote-p "/method:user@host#1234:" 'localname) ""))
344 (should (string-equal
345 (file-remote-p "/method:user@host#1234:" 'hop) nil))
346
347 ;; Expand `tramp-default-method' and `tramp-default-user'.
348 (should (string-equal
349 (file-remote-p "/1.2.3.4:")
350 (format "/%s:%s@%s:" "default-method" "default-user" "1.2.3.4")))
351 (should (string-equal (file-remote-p "/1.2.3.4:" 'method) "default-method"))
352 (should (string-equal (file-remote-p "/1.2.3.4:" 'user) "default-user"))
353 (should (string-equal (file-remote-p "/1.2.3.4:" 'host) "1.2.3.4"))
354 (should (string-equal (file-remote-p "/1.2.3.4:" 'localname) ""))
355 (should (string-equal (file-remote-p "/1.2.3.4:" 'hop) nil))
356
357 ;; Expand `tramp-default-method'.
358 (should (string-equal
359 (file-remote-p "/user@1.2.3.4:")
360 (format "/%s:%s@%s:" "default-method" "user" "1.2.3.4")))
361 (should (string-equal
362 (file-remote-p "/user@1.2.3.4:" 'method) "default-method"))
363 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'user) "user"))
364 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'host) "1.2.3.4"))
365 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'localname) ""))
366 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'hop) nil))
367
368 ;; Expand `tramp-default-user'.
369 (should (string-equal
370 (file-remote-p "/method:1.2.3.4:")
371 (format "/%s:%s@%s:" "method" "default-user" "1.2.3.4")))
372 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'method) "method"))
373 (should (string-equal
374 (file-remote-p "/method:1.2.3.4:" 'user) "default-user"))
375 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'host) "1.2.3.4"))
376 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'localname) ""))
377 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'hop) nil))
378
379 ;; No expansion.
380 (should (string-equal
381 (file-remote-p "/method:user@1.2.3.4:")
382 (format "/%s:%s@%s:" "method" "user" "1.2.3.4")))
383 (should (string-equal
384 (file-remote-p "/method:user@1.2.3.4:" 'method) "method"))
385 (should (string-equal (file-remote-p "/method:user@1.2.3.4:" 'user) "user"))
386 (should (string-equal
387 (file-remote-p "/method:user@1.2.3.4:" 'host) "1.2.3.4"))
388 (should (string-equal
389 (file-remote-p "/method:user@1.2.3.4:" 'localname) ""))
390 (should (string-equal
391 (file-remote-p "/method:user@1.2.3.4:" 'hop) nil))
392
393 ;; Expand `tramp-default-method', `tramp-default-user' and
394 ;; `tramp-default-host'.
395 (should (string-equal
396 (file-remote-p "/[]:")
397 (format
398 "/%s:%s@%s:" "default-method" "default-user" "default-host")))
399 (should (string-equal (file-remote-p "/[]:" 'method) "default-method"))
400 (should (string-equal (file-remote-p "/[]:" 'user) "default-user"))
401 (should (string-equal (file-remote-p "/[]:" 'host) "default-host"))
402 (should (string-equal (file-remote-p "/[]:" 'localname) ""))
403 (should (string-equal (file-remote-p "/[]:" 'hop) nil))
404
405 ;; Expand `tramp-default-method' and `tramp-default-user'.
406 (let ((tramp-default-host "::1"))
407 (should (string-equal
408 (file-remote-p "/[]:")
409 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
410 (should (string-equal (file-remote-p "/[]:" 'method) "default-method"))
411 (should (string-equal (file-remote-p "/[]:" 'user) "default-user"))
412 (should (string-equal (file-remote-p "/[]:" 'host) "::1"))
413 (should (string-equal (file-remote-p "/[]:" 'localname) ""))
414 (should (string-equal (file-remote-p "/[]:" 'hop) nil)))
415
416 ;; Expand `tramp-default-method' and `tramp-default-user'.
417 (should (string-equal
418 (file-remote-p "/[::1]:")
419 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
420 (should (string-equal (file-remote-p "/[::1]:" 'method) "default-method"))
421 (should (string-equal (file-remote-p "/[::1]:" 'user) "default-user"))
422 (should (string-equal (file-remote-p "/[::1]:" 'host) "::1"))
423 (should (string-equal (file-remote-p "/[::1]:" 'localname) ""))
424 (should (string-equal (file-remote-p "/[::1]:" 'hop) nil))
425
426 ;; Expand `tramp-default-method'.
427 (should (string-equal
428 (file-remote-p "/user@[::1]:")
429 (format "/%s:%s@%s:" "default-method" "user" "[::1]")))
430 (should (string-equal
431 (file-remote-p "/user@[::1]:" 'method) "default-method"))
432 (should (string-equal (file-remote-p "/user@[::1]:" 'user) "user"))
433 (should (string-equal (file-remote-p "/user@[::1]:" 'host) "::1"))
434 (should (string-equal (file-remote-p "/user@[::1]:" 'localname) ""))
435 (should (string-equal (file-remote-p "/user@[::1]:" 'hop) nil))
436
437 ;; Expand `tramp-default-user'.
438 (should (string-equal
439 (file-remote-p "/method:[::1]:")
440 (format "/%s:%s@%s:" "method" "default-user" "[::1]")))
441 (should (string-equal (file-remote-p "/method:[::1]:" 'method) "method"))
442 (should (string-equal
443 (file-remote-p "/method:[::1]:" 'user) "default-user"))
444 (should (string-equal (file-remote-p "/method:[::1]:" 'host) "::1"))
445 (should (string-equal (file-remote-p "/method:[::1]:" 'localname) ""))
446 (should (string-equal (file-remote-p "/method:[::1]:" 'hop) nil))
447
448 ;; No expansion.
449 (should (string-equal
450 (file-remote-p "/method:user@[::1]:")
451 (format "/%s:%s@%s:" "method" "user" "[::1]")))
452 (should (string-equal
453 (file-remote-p "/method:user@[::1]:" 'method) "method"))
454 (should (string-equal (file-remote-p "/method:user@[::1]:" 'user) "user"))
455 (should (string-equal (file-remote-p "/method:user@[::1]:" 'host) "::1"))
456 (should (string-equal
457 (file-remote-p "/method:user@[::1]:" 'localname) ""))
458 (should (string-equal (file-remote-p "/method:user@[::1]:" 'hop) nil))
459
460 ;; Local file name part.
461 (should (string-equal (file-remote-p "/host:/:" 'localname) "/:"))
462 (should (string-equal (file-remote-p "/method:::" 'localname) ":"))
463 (should (string-equal (file-remote-p "/method:: " 'localname) " "))
464 (should (string-equal (file-remote-p "/method::file" 'localname) "file"))
465 (should (string-equal
466 (file-remote-p "/method::/path/to/file" 'localname)
467 "/path/to/file"))
468
469 ;; Multihop.
470 (should
471 (string-equal
472 (file-remote-p "/method1:user1@host1|method2:user2@host2:/path/to/file")
473 (format "/%s:%s@%s|%s:%s@%s:"
474 "method1" "user1" "host1" "method2" "user2" "host2")))
475 (should
476 (string-equal
477 (file-remote-p
478 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'method)
479 "method2"))
480 (should
481 (string-equal
482 (file-remote-p
483 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'user)
484 "user2"))
485 (should
486 (string-equal
487 (file-remote-p
488 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'host)
489 "host2"))
490 (should
491 (string-equal
492 (file-remote-p
493 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'localname)
494 "/path/to/file"))
495 (should
496 (string-equal
497 (file-remote-p
498 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'hop)
499 (format "%s:%s@%s|"
500 "method1" "user1" "host1")))
501
502 (should
503 (string-equal
504 (file-remote-p
505 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file")
506 (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
507 "method1" "user1" "host1"
508 "method2" "user2" "host2"
509 "method3" "user3" "host3")))
510 (should
511 (string-equal
512 (file-remote-p
513 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
514 'method)
515 "method3"))
516 (should
517 (string-equal
518 (file-remote-p
519 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
520 'user)
521 "user3"))
522 (should
523 (string-equal
524 (file-remote-p
525 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
526 'host)
527 "host3"))
528 (should
529 (string-equal
530 (file-remote-p
531 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
532 'localname)
533 "/path/to/file"))
534 (should
535 (string-equal
536 (file-remote-p
537 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
538 'hop)
539 (format "%s:%s@%s|%s:%s@%s|"
540 "method1" "user1" "host1" "method2" "user2" "host2")))))
541
542 (ert-deftest tramp-test03-file-name-defaults ()
543 "Check default values for some methods."
544 ;; Default values in tramp-adb.el.
545 (should (string-equal (file-remote-p "/adb::" 'host) ""))
546 ;; Default values in tramp-ftp.el.
547 (should (string-equal (file-remote-p "/ftp.host:" 'method) "ftp"))
548 (dolist (u '("ftp" "anonymous"))
549 (should (string-equal (file-remote-p (format "/%s@:" u) 'method) "ftp")))
550 ;; Default values in tramp-gvfs.el.
551 (when (and (load "tramp-gvfs" 'noerror 'nomessage)
552 (symbol-value 'tramp-gvfs-enabled))
553 (should (string-equal (file-remote-p "/synce::" 'user) nil)))
554 ;; Default values in tramp-gw.el.
555 (dolist (m '("tunnel" "socks"))
556 (should
557 (string-equal (file-remote-p (format "/%s::" m) 'user) (user-login-name))))
558 ;; Default values in tramp-sh.el.
559 (dolist (h `("127.0.0.1" "[::1]" "localhost" "localhost6" ,(system-name)))
560 (should (string-equal (file-remote-p (format "/root@%s:" h) 'method) "su")))
561 (dolist (m '("su" "sudo" "ksu"))
562 (should (string-equal (file-remote-p (format "/%s::" m) 'user) "root")))
563 (dolist (m '("rcp" "remcp" "rsh" "telnet" "krlogin" "fcp"))
564 (should
565 (string-equal (file-remote-p (format "/%s::" m) 'user) (user-login-name))))
566 ;; Default values in tramp-smb.el.
567 (should (string-equal (file-remote-p "/user%domain@host:" 'method) "smb"))
568 (should (string-equal (file-remote-p "/smb::" 'user) nil)))
569
570 (ert-deftest tramp-test04-substitute-in-file-name ()
571 "Check `substitute-in-file-name'."
572 (should (string-equal (substitute-in-file-name "/method:host://foo") "/foo"))
573 (should
574 (string-equal
575 (substitute-in-file-name "/method:host:/path//foo") "/method:host:/foo"))
576 (should
577 (string-equal (substitute-in-file-name "/method:host:/path///foo") "/foo"))
578 (should
579 (string-equal
580 (substitute-in-file-name "/method:host:/path/~/foo") "/method:host:~/foo"))
581 (should
582 (string-equal (substitute-in-file-name "/method:host:/path//~/foo") "~/foo"))
583 (let (process-environment)
584 (should
585 (string-equal
586 (substitute-in-file-name "/method:host:/path/$FOO")
587 "/method:host:/path/$FOO"))
588 (setenv "FOO" "bla")
589 (should
590 (string-equal
591 (substitute-in-file-name "/method:host:/path/$FOO")
592 "/method:host:/path/bla"))
593 (should
594 (string-equal
595 (substitute-in-file-name "/method:host:/path/$$FOO")
596 "/method:host:/path/$FOO"))))
597
598 (ert-deftest tramp-test05-expand-file-name ()
599 "Check `expand-file-name'."
600 (should
601 (string-equal
602 (expand-file-name "/method:host:/path/./file") "/method:host:/path/file"))
603 (should
604 (string-equal
605 (expand-file-name "/method:host:/path/../file") "/method:host:/file")))
606
607 (ert-deftest tramp-test06-directory-file-name ()
608 "Check `directory-file-name'.
609 This checks also `file-name-as-directory', `file-name-directory',
610 `file-name-nondirectory' and `unhandled-file-name-directory'."
611 (should
612 (string-equal
613 (directory-file-name "/method:host:/path/to/file")
614 "/method:host:/path/to/file"))
615 (should
616 (string-equal
617 (directory-file-name "/method:host:/path/to/file/")
618 "/method:host:/path/to/file"))
619 (should
620 (string-equal
621 (file-name-as-directory "/method:host:/path/to/file")
622 "/method:host:/path/to/file/"))
623 (should
624 (string-equal
625 (file-name-as-directory "/method:host:/path/to/file/")
626 "/method:host:/path/to/file/"))
627 (should
628 (string-equal
629 (file-name-directory "/method:host:/path/to/file")
630 "/method:host:/path/to/"))
631 (should
632 (string-equal
633 (file-name-directory "/method:host:/path/to/file/")
634 "/method:host:/path/to/file/"))
635 (should
636 (string-equal (file-name-nondirectory "/method:host:/path/to/file") "file"))
637 (should
638 (string-equal (file-name-nondirectory "/method:host:/path/to/file/") ""))
639 (should-not
640 (unhandled-file-name-directory "/method:host:/path/to/file")))
641
642 (ert-deftest tramp-test07-file-exists-p ()
643 "Check `file-exist-p', `write-region' and `delete-file'."
644 (skip-unless (tramp--test-enabled))
645
646 (let ((tmp-name (tramp--test-make-temp-name)))
647 (should-not (file-exists-p tmp-name))
648 (write-region "foo" nil tmp-name)
649 (should (file-exists-p tmp-name))
650 (delete-file tmp-name)
651 (should-not (file-exists-p tmp-name))))
652
653 (ert-deftest tramp-test08-file-local-copy ()
654 "Check `file-local-copy'."
655 (skip-unless (tramp--test-enabled))
656
657 (let ((tmp-name1 (tramp--test-make-temp-name))
658 tmp-name2)
659 (unwind-protect
660 (progn
661 (write-region "foo" nil tmp-name1)
662 (should (setq tmp-name2 (file-local-copy tmp-name1)))
663 (with-temp-buffer
664 (insert-file-contents tmp-name2)
665 (should (string-equal (buffer-string) "foo")))
666 ;; Check also that a file transfer with compression works.
667 (let ((default-directory tramp-test-temporary-file-directory)
668 (tramp-copy-size-limit 4)
669 (tramp-inline-compress-start-size 2))
670 (delete-file tmp-name2)
671 (should (setq tmp-name2 (file-local-copy tmp-name1)))))
672
673 ;; Cleanup.
674 (ignore-errors
675 (delete-file tmp-name1)
676 (delete-file tmp-name2)))))
677
678 (ert-deftest tramp-test09-insert-file-contents ()
679 "Check `insert-file-contents'."
680 (skip-unless (tramp--test-enabled))
681
682 (let ((tmp-name (tramp--test-make-temp-name)))
683 (unwind-protect
684 (progn
685 (write-region "foo" nil tmp-name)
686 (with-temp-buffer
687 (insert-file-contents tmp-name)
688 (should (string-equal (buffer-string) "foo"))
689 (insert-file-contents tmp-name)
690 (should (string-equal (buffer-string) "foofoo"))
691 ;; Insert partly.
692 (insert-file-contents tmp-name nil 1 3)
693 (should (string-equal (buffer-string) "oofoofoo"))
694 ;; Replace.
695 (insert-file-contents tmp-name nil nil nil 'replace)
696 (should (string-equal (buffer-string) "foo"))))
697
698 ;; Cleanup.
699 (ignore-errors (delete-file tmp-name)))))
700
701 (ert-deftest tramp-test10-write-region ()
702 "Check `write-region'."
703 (skip-unless (tramp--test-enabled))
704
705 (let ((tmp-name (tramp--test-make-temp-name)))
706 (unwind-protect
707 (progn
708 (with-temp-buffer
709 (insert "foo")
710 (write-region nil nil tmp-name))
711 (with-temp-buffer
712 (insert-file-contents tmp-name)
713 (should (string-equal (buffer-string) "foo")))
714 ;; Append.
715 (with-temp-buffer
716 (insert "bla")
717 (write-region nil nil tmp-name 'append))
718 (with-temp-buffer
719 (insert-file-contents tmp-name)
720 (should (string-equal (buffer-string) "foobla")))
721 ;; Write string.
722 (write-region "foo" nil tmp-name)
723 (with-temp-buffer
724 (insert-file-contents tmp-name)
725 (should (string-equal (buffer-string) "foo")))
726 ;; Write partly.
727 (with-temp-buffer
728 (insert "123456789")
729 (write-region 3 5 tmp-name))
730 (with-temp-buffer
731 (insert-file-contents tmp-name)
732 (should (string-equal (buffer-string) "34"))))
733
734 ;; Cleanup.
735 (ignore-errors (delete-file tmp-name)))))
736
737 (ert-deftest tramp-test11-copy-file ()
738 "Check `copy-file'."
739 (skip-unless (tramp--test-enabled))
740
741 (let ((tmp-name1 (tramp--test-make-temp-name))
742 (tmp-name2 (tramp--test-make-temp-name))
743 (tmp-name3 (tramp--test-make-temp-name))
744 (tmp-name4 (tramp--test-make-temp-name 'local))
745 (tmp-name5 (tramp--test-make-temp-name 'local)))
746
747 ;; Copy on remote side.
748 (unwind-protect
749 (progn
750 (write-region "foo" nil tmp-name1)
751 (copy-file tmp-name1 tmp-name2)
752 (should (file-exists-p tmp-name2))
753 (with-temp-buffer
754 (insert-file-contents tmp-name2)
755 (should (string-equal (buffer-string) "foo")))
756 (should-error (copy-file tmp-name1 tmp-name2))
757 (copy-file tmp-name1 tmp-name2 'ok)
758 (make-directory tmp-name3)
759 (copy-file tmp-name1 tmp-name3)
760 (should
761 (file-exists-p
762 (expand-file-name (file-name-nondirectory tmp-name1) tmp-name3))))
763
764 ;; Cleanup.
765 (ignore-errors (delete-file tmp-name1))
766 (ignore-errors (delete-file tmp-name2))
767 (ignore-errors (delete-directory tmp-name3 'recursive)))
768
769 ;; Copy from remote side to local side.
770 (unwind-protect
771 (progn
772 (write-region "foo" nil tmp-name1)
773 (copy-file tmp-name1 tmp-name4)
774 (should (file-exists-p tmp-name4))
775 (with-temp-buffer
776 (insert-file-contents tmp-name4)
777 (should (string-equal (buffer-string) "foo")))
778 (should-error (copy-file tmp-name1 tmp-name4))
779 (copy-file tmp-name1 tmp-name4 'ok)
780 (make-directory tmp-name5)
781 (copy-file tmp-name1 tmp-name5)
782 (should
783 (file-exists-p
784 (expand-file-name (file-name-nondirectory tmp-name1) tmp-name5))))
785
786 ;; Cleanup.
787 (ignore-errors (delete-file tmp-name1))
788 (ignore-errors (delete-file tmp-name4))
789 (ignore-errors (delete-directory tmp-name5 'recursive)))
790
791 ;; Copy from local side to remote side.
792 (unwind-protect
793 (progn
794 (write-region "foo" nil tmp-name4 nil 'nomessage)
795 (copy-file tmp-name4 tmp-name1)
796 (should (file-exists-p tmp-name1))
797 (with-temp-buffer
798 (insert-file-contents tmp-name1)
799 (should (string-equal (buffer-string) "foo")))
800 (should-error (copy-file tmp-name4 tmp-name1))
801 (copy-file tmp-name4 tmp-name1 'ok)
802 (make-directory tmp-name3)
803 (copy-file tmp-name4 tmp-name3)
804 (should
805 (file-exists-p
806 (expand-file-name (file-name-nondirectory tmp-name4) tmp-name3))))
807
808 ;; Cleanup.
809 (ignore-errors (delete-file tmp-name1))
810 (ignore-errors (delete-file tmp-name4))
811 (ignore-errors (delete-directory tmp-name3 'recursive)))))
812
813 (ert-deftest tramp-test12-rename-file ()
814 "Check `rename-file'."
815 (skip-unless (tramp--test-enabled))
816
817 (let ((tmp-name1 (tramp--test-make-temp-name))
818 (tmp-name2 (tramp--test-make-temp-name))
819 (tmp-name3 (tramp--test-make-temp-name))
820 (tmp-name4 (tramp--test-make-temp-name 'local))
821 (tmp-name5 (tramp--test-make-temp-name 'local)))
822
823 ;; Rename on remote side.
824 (unwind-protect
825 (progn
826 (write-region "foo" nil tmp-name1)
827 (rename-file tmp-name1 tmp-name2)
828 (should-not (file-exists-p tmp-name1))
829 (should (file-exists-p tmp-name2))
830 (with-temp-buffer
831 (insert-file-contents tmp-name2)
832 (should (string-equal (buffer-string) "foo")))
833 (write-region "foo" nil tmp-name1)
834 (should-error (rename-file tmp-name1 tmp-name2))
835 (rename-file tmp-name1 tmp-name2 'ok)
836 (should-not (file-exists-p tmp-name1))
837 (write-region "foo" nil tmp-name1)
838 (make-directory tmp-name3)
839 (rename-file tmp-name1 tmp-name3)
840 (should-not (file-exists-p tmp-name1))
841 (should
842 (file-exists-p
843 (expand-file-name (file-name-nondirectory tmp-name1) tmp-name3))))
844
845 ;; Cleanup.
846 (ignore-errors (delete-file tmp-name1))
847 (ignore-errors (delete-file tmp-name2))
848 (ignore-errors (delete-directory tmp-name3 'recursive)))
849
850 ;; Rename from remote side to local side.
851 (unwind-protect
852 (progn
853 (write-region "foo" nil tmp-name1)
854 (rename-file tmp-name1 tmp-name4)
855 (should-not (file-exists-p tmp-name1))
856 (should (file-exists-p tmp-name4))
857 (with-temp-buffer
858 (insert-file-contents tmp-name4)
859 (should (string-equal (buffer-string) "foo")))
860 (write-region "foo" nil tmp-name1)
861 (should-error (rename-file tmp-name1 tmp-name4))
862 (rename-file tmp-name1 tmp-name4 'ok)
863 (should-not (file-exists-p tmp-name1))
864 (write-region "foo" nil tmp-name1)
865 (make-directory tmp-name5)
866 (rename-file tmp-name1 tmp-name5)
867 (should-not (file-exists-p tmp-name1))
868 (should
869 (file-exists-p
870 (expand-file-name (file-name-nondirectory tmp-name1) tmp-name5))))
871
872 ;; Cleanup.
873 (ignore-errors (delete-file tmp-name1))
874 (ignore-errors (delete-file tmp-name4))
875 (ignore-errors (delete-directory tmp-name5 'recursive)))
876
877 ;; Rename from local side to remote side.
878 (unwind-protect
879 (progn
880 (write-region "foo" nil tmp-name4 nil 'nomessage)
881 (rename-file tmp-name4 tmp-name1)
882 (should-not (file-exists-p tmp-name4))
883 (should (file-exists-p tmp-name1))
884 (with-temp-buffer
885 (insert-file-contents tmp-name1)
886 (should (string-equal (buffer-string) "foo")))
887 (write-region "foo" nil tmp-name4 nil 'nomessage)
888 (should-error (rename-file tmp-name4 tmp-name1))
889 (rename-file tmp-name4 tmp-name1 'ok)
890 (should-not (file-exists-p tmp-name4))
891 (write-region "foo" nil tmp-name4 nil 'nomessage)
892 (make-directory tmp-name3)
893 (rename-file tmp-name4 tmp-name3)
894 (should-not (file-exists-p tmp-name4))
895 (should
896 (file-exists-p
897 (expand-file-name (file-name-nondirectory tmp-name4) tmp-name3))))
898
899 ;; Cleanup.
900 (ignore-errors (delete-file tmp-name1))
901 (ignore-errors (delete-file tmp-name4))
902 (ignore-errors (delete-directory tmp-name3 'recursive)))))
903
904 (ert-deftest tramp-test13-make-directory ()
905 "Check `make-directory'.
906 This tests also `file-directory-p' and `file-accessible-directory-p'."
907 (skip-unless (tramp--test-enabled))
908
909 (let* ((tmp-name1 (tramp--test-make-temp-name))
910 (tmp-name2 (expand-file-name "foo/bar" tmp-name1)))
911 (unwind-protect
912 (progn
913 (make-directory tmp-name1)
914 (should (file-directory-p tmp-name1))
915 (should (file-accessible-directory-p tmp-name1))
916 (should-error (make-directory tmp-name2) :type 'file-error)
917 (make-directory tmp-name2 'parents)
918 (should (file-directory-p tmp-name2))
919 (should (file-accessible-directory-p tmp-name2)))
920
921 ;; Cleanup.
922 (ignore-errors (delete-directory tmp-name1 'recursive)))))
923
924 (ert-deftest tramp-test14-delete-directory ()
925 "Check `delete-directory'."
926 (skip-unless (tramp--test-enabled))
927
928 (let ((tmp-name (tramp--test-make-temp-name)))
929 ;; Delete empty directory.
930 (make-directory tmp-name)
931 (should (file-directory-p tmp-name))
932 (delete-directory tmp-name)
933 (should-not (file-directory-p tmp-name))
934 ;; Delete non-empty directory.
935 (make-directory tmp-name)
936 (write-region "foo" nil (expand-file-name "bla" tmp-name))
937 (should-error (delete-directory tmp-name) :type 'file-error)
938 (delete-directory tmp-name 'recursive)
939 (should-not (file-directory-p tmp-name))))
940
941 (ert-deftest tramp-test15-copy-directory ()
942 "Check `copy-directory'."
943 (skip-unless (tramp--test-enabled))
944 (skip-unless
945 (not
946 (eq
947 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
948 'tramp-smb-file-name-handler)))
949
950 (let* ((tmp-name1 (tramp--test-make-temp-name))
951 (tmp-name2 (tramp--test-make-temp-name))
952 (tmp-name3 (expand-file-name
953 (file-name-nondirectory tmp-name1) tmp-name2))
954 (tmp-name4 (expand-file-name "foo" tmp-name1))
955 (tmp-name5 (expand-file-name "foo" tmp-name2))
956 (tmp-name6 (expand-file-name "foo" tmp-name3)))
957 (unwind-protect
958 (progn
959 ;; Copy empty directory.
960 (make-directory tmp-name1)
961 (write-region "foo" nil tmp-name4)
962 (should (file-directory-p tmp-name1))
963 (should (file-exists-p tmp-name4))
964 (copy-directory tmp-name1 tmp-name2)
965 (should (file-directory-p tmp-name2))
966 (should (file-exists-p tmp-name5))
967 ;; Target directory does exist already.
968 (copy-directory tmp-name1 tmp-name2)
969 (should (file-directory-p tmp-name3))
970 (should (file-exists-p tmp-name6)))
971
972 ;; Cleanup.
973 (ignore-errors
974 (delete-directory tmp-name1 'recursive)
975 (delete-directory tmp-name2 'recursive)))))
976
977 (ert-deftest tramp-test16-directory-files ()
978 "Check `directory-files'."
979 (skip-unless (tramp--test-enabled))
980
981 (let* ((tmp-name1 (tramp--test-make-temp-name))
982 (tmp-name2 (expand-file-name "bla" tmp-name1))
983 (tmp-name3 (expand-file-name "foo" tmp-name1)))
984 (unwind-protect
985 (progn
986 (make-directory tmp-name1)
987 (write-region "foo" nil tmp-name2)
988 (write-region "bla" nil tmp-name3)
989 (should (file-directory-p tmp-name1))
990 (should (file-exists-p tmp-name2))
991 (should (file-exists-p tmp-name3))
992 (should (equal (directory-files tmp-name1) '("." ".." "bla" "foo")))
993 (should (equal (directory-files tmp-name1 'full)
994 `(,(concat tmp-name1 "/.")
995 ,(concat tmp-name1 "/..")
996 ,tmp-name2 ,tmp-name3)))
997 (should (equal (directory-files
998 tmp-name1 nil directory-files-no-dot-files-regexp)
999 '("bla" "foo")))
1000 (should (equal (directory-files
1001 tmp-name1 'full directory-files-no-dot-files-regexp)
1002 `(,tmp-name2 ,tmp-name3))))
1003
1004 ;; Cleanup.
1005 (ignore-errors (delete-directory tmp-name1 'recursive)))))
1006
1007 (ert-deftest tramp-test17-insert-directory ()
1008 "Check `insert-directory'."
1009 (skip-unless (tramp--test-enabled))
1010
1011 (let* ((tmp-name1 (tramp--test-make-temp-name))
1012 (tmp-name2 (expand-file-name "foo" tmp-name1))
1013 ;; We test for the summary line. Keyword "total" could be localized.
1014 (process-environment
1015 (append '("LANG=C" "LANGUAGE=C" "LC_ALL=C") process-environment)))
1016 (unwind-protect
1017 (progn
1018 (make-directory tmp-name1)
1019 (write-region "foo" nil tmp-name2)
1020 (should (file-directory-p tmp-name1))
1021 (should (file-exists-p tmp-name2))
1022 (with-temp-buffer
1023 (insert-directory tmp-name1 nil)
1024 (goto-char (point-min))
1025 (should (looking-at-p (regexp-quote tmp-name1))))
1026 (with-temp-buffer
1027 (insert-directory tmp-name1 "-al")
1028 (goto-char (point-min))
1029 (should (looking-at-p (format "^.+ %s$" (regexp-quote tmp-name1)))))
1030 (with-temp-buffer
1031 (insert-directory (file-name-as-directory tmp-name1) "-al")
1032 (goto-char (point-min))
1033 (should
1034 (looking-at-p (format "^.+ %s/$" (regexp-quote tmp-name1)))))
1035 (with-temp-buffer
1036 (insert-directory
1037 (file-name-as-directory tmp-name1) "-al" nil 'full-directory-p)
1038 (goto-char (point-min))
1039 (should
1040 (looking-at-p
1041 (concat
1042 ;; There might be a summary line.
1043 "\\(total.+[[:digit:]]+\n\\)?"
1044 ;; We don't know in which order ".", ".." and "foo" appear.
1045 "\\(.+ \\(\\.?\\.\\|foo\\)\n\\)\\{3\\}")))))
1046
1047 ;; Cleanup.
1048 (ignore-errors (delete-directory tmp-name1 'recursive)))))
1049
1050 (ert-deftest tramp-test18-file-attributes ()
1051 "Check `file-attributes'.
1052 This tests also `file-readable-p' and `file-regular-p'."
1053 (skip-unless (tramp--test-enabled))
1054
1055 ;; We must use `file-truename' for the temporary directory, because
1056 ;; it could be located on a symlinked directory. This would let the
1057 ;; test fail.
1058 (let* ((tramp-test-temporary-file-directory
1059 (file-truename tramp-test-temporary-file-directory))
1060 (tmp-name1 (tramp--test-make-temp-name))
1061 (tmp-name2 (tramp--test-make-temp-name))
1062 ;; File name with "//".
1063 (tmp-name3
1064 (format
1065 "%s%s"
1066 (file-remote-p tmp-name1)
1067 (replace-regexp-in-string
1068 "/" "//" (file-remote-p tmp-name1 'localname))))
1069 attr)
1070 (unwind-protect
1071 (progn
1072 (write-region "foo" nil tmp-name1)
1073 (should (file-exists-p tmp-name1))
1074 (setq attr (file-attributes tmp-name1))
1075 (should (consp attr))
1076 (should (file-exists-p tmp-name1))
1077 (should (file-readable-p tmp-name1))
1078 (should (file-regular-p tmp-name1))
1079 ;; We do not test inodes and device numbers.
1080 (should (null (car attr)))
1081 (should (numberp (nth 1 attr))) ;; Link.
1082 (should (numberp (nth 2 attr))) ;; Uid.
1083 (should (numberp (nth 3 attr))) ;; Gid.
1084 ;; Last access time.
1085 (should (stringp (current-time-string (nth 4 attr))))
1086 ;; Last modification time.
1087 (should (stringp (current-time-string (nth 5 attr))))
1088 ;; Last status change time.
1089 (should (stringp (current-time-string (nth 6 attr))))
1090 (should (numberp (nth 7 attr))) ;; Size.
1091 (should (stringp (nth 8 attr))) ;; Modes.
1092
1093 (setq attr (file-attributes tmp-name1 'string))
1094 (should (stringp (nth 2 attr))) ;; Uid.
1095 (should (stringp (nth 3 attr))) ;; Gid.
1096
1097 (condition-case err
1098 (progn
1099 (make-symbolic-link tmp-name1 tmp-name2)
1100 (should (file-exists-p tmp-name2))
1101 (should (file-symlink-p tmp-name2))
1102 (setq attr (file-attributes tmp-name2))
1103 (should (string-equal
1104 (car attr)
1105 (file-remote-p (file-truename tmp-name1) 'localname)))
1106 (delete-file tmp-name2))
1107 (file-error
1108 (should (string-equal (error-message-string err)
1109 "make-symbolic-link not supported"))))
1110
1111 ;; Check, that "//" in symlinks are handled properly.
1112 (with-temp-buffer
1113 (let ((default-directory tramp-test-temporary-file-directory))
1114 (shell-command
1115 (format
1116 "ln -s %s %s"
1117 (tramp-file-name-localname (tramp-dissect-file-name tmp-name3))
1118 (tramp-file-name-localname (tramp-dissect-file-name tmp-name2)))
1119 t)))
1120 (when (file-symlink-p tmp-name2)
1121 (setq attr (file-attributes tmp-name2))
1122 (should
1123 (string-equal
1124 (car attr)
1125 (tramp-file-name-localname (tramp-dissect-file-name tmp-name3))))
1126 (delete-file tmp-name2))
1127
1128 (delete-file tmp-name1)
1129 (make-directory tmp-name1)
1130 (should (file-exists-p tmp-name1))
1131 (should (file-readable-p tmp-name1))
1132 (should-not (file-regular-p tmp-name1))
1133 (setq attr (file-attributes tmp-name1))
1134 (should (eq (car attr) t)))
1135
1136 ;; Cleanup.
1137 (ignore-errors (delete-directory tmp-name1))
1138 (ignore-errors (delete-file tmp-name1))
1139 (ignore-errors (delete-file tmp-name2)))))
1140
1141 (ert-deftest tramp-test19-directory-files-and-attributes ()
1142 "Check `directory-files-and-attributes'."
1143 (skip-unless (tramp--test-enabled))
1144
1145 ;; `directory-files-and-attributes' contains also values for "../".
1146 ;; Ensure that this doesn't change during tests, for
1147 ;; example due to handling temporary files.
1148 (let* ((tmp-name1 (tramp--test-make-temp-name))
1149 (tmp-name2 (expand-file-name "bla" tmp-name1))
1150 attr)
1151 (unwind-protect
1152 (progn
1153 (make-directory tmp-name1)
1154 (should (file-directory-p tmp-name1))
1155 (make-directory tmp-name2)
1156 (should (file-directory-p tmp-name2))
1157 (write-region "foo" nil (expand-file-name "foo" tmp-name2))
1158 (write-region "bar" nil (expand-file-name "bar" tmp-name2))
1159 (write-region "boz" nil (expand-file-name "boz" tmp-name2))
1160 (setq attr (directory-files-and-attributes tmp-name2))
1161 (should (consp attr))
1162 ;; Dumb remote shells without perl(1) or stat(1) are not
1163 ;; able to return the date correctly. They say "don't know".
1164 (dolist (elt attr)
1165 (unless
1166 (equal
1167 (nth 5
1168 (file-attributes (expand-file-name (car elt) tmp-name2)))
1169 '(0 0))
1170 (should
1171 (equal (file-attributes (expand-file-name (car elt) tmp-name2))
1172 (cdr elt)))))
1173 (setq attr (directory-files-and-attributes tmp-name2 'full))
1174 (dolist (elt attr)
1175 (unless (equal (nth 5 (file-attributes (car elt))) '(0 0))
1176 (should
1177 (equal (file-attributes (car elt)) (cdr elt)))))
1178 (setq attr (directory-files-and-attributes tmp-name2 nil "^b"))
1179 (should (equal (mapcar 'car attr) '("bar" "boz"))))
1180
1181 ;; Cleanup.
1182 (ignore-errors (delete-directory tmp-name1 'recursive)))))
1183
1184 (ert-deftest tramp-test20-file-modes ()
1185 "Check `file-modes'.
1186 This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
1187 (skip-unless (tramp--test-enabled))
1188 (skip-unless
1189 (not
1190 (memq
1191 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1192 '(tramp-adb-file-name-handler
1193 tramp-gvfs-file-name-handler
1194 tramp-smb-file-name-handler))))
1195
1196 (let ((tmp-name (tramp--test-make-temp-name)))
1197 (unwind-protect
1198 (progn
1199 (write-region "foo" nil tmp-name)
1200 (should (file-exists-p tmp-name))
1201 (set-file-modes tmp-name #o777)
1202 (should (= (file-modes tmp-name) #o777))
1203 (should (file-executable-p tmp-name))
1204 (should (file-writable-p tmp-name))
1205 (set-file-modes tmp-name #o444)
1206 (should (= (file-modes tmp-name) #o444))
1207 (should-not (file-executable-p tmp-name))
1208 ;; A file is always writable for user "root".
1209 (unless (zerop (nth 2 (file-attributes tmp-name)))
1210 (should-not (file-writable-p tmp-name))))
1211
1212 ;; Cleanup.
1213 (ignore-errors (delete-file tmp-name)))))
1214
1215 (ert-deftest tramp-test21-file-links ()
1216 "Check `file-symlink-p'.
1217 This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1218 (skip-unless (tramp--test-enabled))
1219
1220 ;; We must use `file-truename' for the temporary directory, because
1221 ;; it could be located on a symlinked directory. This would let the
1222 ;; test fail.
1223 (let* ((tramp-test-temporary-file-directory
1224 (file-truename tramp-test-temporary-file-directory))
1225 (tmp-name1 (tramp--test-make-temp-name))
1226 (tmp-name2 (tramp--test-make-temp-name))
1227 (tmp-name3 (tramp--test-make-temp-name 'local)))
1228
1229 ;; Check `make-symbolic-link'.
1230 (unwind-protect
1231 (progn
1232 (write-region "foo" nil tmp-name1)
1233 (should (file-exists-p tmp-name1))
1234 ;; Method "smb" supports `make-symbolic-link' only if the
1235 ;; remote host has CIFS capabilities. tramp-adb.el and
1236 ;; tramp-gvfs.el do not support symbolic links at all.
1237 (condition-case err
1238 (make-symbolic-link tmp-name1 tmp-name2)
1239 (file-error
1240 (skip-unless
1241 (not (string-equal (error-message-string err)
1242 "make-symbolic-link not supported")))))
1243 (should (file-symlink-p tmp-name2))
1244 (should-error (make-symbolic-link tmp-name1 tmp-name2))
1245 (make-symbolic-link tmp-name1 tmp-name2 'ok-if-already-exists)
1246 (should (file-symlink-p tmp-name2))
1247 ;; `tmp-name3' is a local file name.
1248 (should-error (make-symbolic-link tmp-name1 tmp-name3)))
1249
1250 ;; Cleanup.
1251 (ignore-errors
1252 (delete-file tmp-name1)
1253 (delete-file tmp-name2)))
1254
1255 ;; Check `add-name-to-file'.
1256 (unwind-protect
1257 (progn
1258 (write-region "foo" nil tmp-name1)
1259 (should (file-exists-p tmp-name1))
1260 (add-name-to-file tmp-name1 tmp-name2)
1261 (should-not (file-symlink-p tmp-name2))
1262 (should-error (add-name-to-file tmp-name1 tmp-name2))
1263 (add-name-to-file tmp-name1 tmp-name2 'ok-if-already-exists)
1264 (should-not (file-symlink-p tmp-name2))
1265 ;; `tmp-name3' is a local file name.
1266 (should-error (add-name-to-file tmp-name1 tmp-name3)))
1267
1268 ;; Cleanup.
1269 (ignore-errors
1270 (delete-file tmp-name1)
1271 (delete-file tmp-name2)))
1272
1273 ;; Check `file-truename'.
1274 (unwind-protect
1275 (progn
1276 (write-region "foo" nil tmp-name1)
1277 (should (file-exists-p tmp-name1))
1278 (make-symbolic-link tmp-name1 tmp-name2)
1279 (should (file-symlink-p tmp-name2))
1280 (should-not (string-equal tmp-name2 (file-truename tmp-name2)))
1281 (should
1282 (string-equal (file-truename tmp-name1) (file-truename tmp-name2)))
1283 (should (file-equal-p tmp-name1 tmp-name2)))
1284 (ignore-errors
1285 (delete-file tmp-name1)
1286 (delete-file tmp-name2)))
1287
1288 ;; `file-truename' shall preserve trailing link of directories.
1289 (unless (file-symlink-p tramp-test-temporary-file-directory)
1290 (let* ((dir1 (directory-file-name tramp-test-temporary-file-directory))
1291 (dir2 (file-name-as-directory dir1)))
1292 (should (string-equal (file-truename dir1) (expand-file-name dir1)))
1293 (should (string-equal (file-truename dir2) (expand-file-name dir2)))))))
1294
1295 (ert-deftest tramp-test22-file-times ()
1296 "Check `set-file-times' and `file-newer-than-file-p'."
1297 (skip-unless (tramp--test-enabled))
1298 (skip-unless
1299 (not
1300 (memq
1301 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1302 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler))))
1303
1304 (let ((tmp-name1 (tramp--test-make-temp-name))
1305 (tmp-name2 (tramp--test-make-temp-name))
1306 (tmp-name3 (tramp--test-make-temp-name)))
1307 (unwind-protect
1308 (progn
1309 (write-region "foo" nil tmp-name1)
1310 (should (file-exists-p tmp-name1))
1311 (should (consp (nth 5 (file-attributes tmp-name1))))
1312 ;; '(0 0) means don't know, and will be replaced by
1313 ;; `current-time'. Therefore, we use '(0 1).
1314 ;; We skip the test, if the remote handler is not able to
1315 ;; set the correct time.
1316 (skip-unless (set-file-times tmp-name1 '(0 1)))
1317 ;; Dumb remote shells without perl(1) or stat(1) are not
1318 ;; able to return the date correctly. They say "don't know".
1319 (unless (equal (nth 5 (file-attributes tmp-name1)) '(0 0))
1320 (should (equal (nth 5 (file-attributes tmp-name1)) '(0 1)))
1321 (write-region "bla" nil tmp-name2)
1322 (should (file-exists-p tmp-name2))
1323 (should (file-newer-than-file-p tmp-name2 tmp-name1))
1324 ;; `tmp-name3' does not exist.
1325 (should (file-newer-than-file-p tmp-name2 tmp-name3))
1326 (should-not (file-newer-than-file-p tmp-name3 tmp-name1))))
1327
1328 ;; Cleanup.
1329 (ignore-errors
1330 (delete-file tmp-name1)
1331 (delete-file tmp-name2)))))
1332
1333 (ert-deftest tramp-test23-visited-file-modtime ()
1334 "Check `set-visited-file-modtime' and `verify-visited-file-modtime'."
1335 (skip-unless (tramp--test-enabled))
1336
1337 (let ((tmp-name (tramp--test-make-temp-name)))
1338 (unwind-protect
1339 (progn
1340 (write-region "foo" nil tmp-name)
1341 (should (file-exists-p tmp-name))
1342 (with-temp-buffer
1343 (insert-file-contents tmp-name)
1344 (should (verify-visited-file-modtime))
1345 (set-visited-file-modtime '(0 1))
1346 (should (verify-visited-file-modtime))
1347 (should (equal (visited-file-modtime) '(0 1 0 0)))))
1348
1349 ;; Cleanup.
1350 (ignore-errors (delete-file tmp-name)))))
1351
1352 (ert-deftest tramp-test24-file-name-completion ()
1353 "Check `file-name-completion' and `file-name-all-completions'."
1354 (skip-unless (tramp--test-enabled))
1355
1356 (let ((tmp-name (tramp--test-make-temp-name)))
1357 (unwind-protect
1358 (progn
1359 (make-directory tmp-name)
1360 (should (file-directory-p tmp-name))
1361 (write-region "foo" nil (expand-file-name "foo" tmp-name))
1362 (write-region "bar" nil (expand-file-name "bold" tmp-name))
1363 (make-directory (expand-file-name "boz" tmp-name))
1364 (should (equal (file-name-completion "fo" tmp-name) "foo"))
1365 (should (equal (file-name-completion "b" tmp-name) "bo"))
1366 (should
1367 (equal (file-name-completion "b" tmp-name 'file-directory-p) "boz/"))
1368 (should (equal (file-name-all-completions "fo" tmp-name) '("foo")))
1369 (should
1370 (equal (sort (file-name-all-completions "b" tmp-name) 'string-lessp)
1371 '("bold" "boz/"))))
1372
1373 ;; Cleanup.
1374 (ignore-errors (delete-directory tmp-name 'recursive)))))
1375
1376 (ert-deftest tramp-test25-load ()
1377 "Check `load'."
1378 (skip-unless (tramp--test-enabled))
1379
1380 (let ((tmp-name (tramp--test-make-temp-name)))
1381 (unwind-protect
1382 (progn
1383 (load tmp-name 'noerror 'nomessage)
1384 (should-not (featurep 'tramp-test-load))
1385 (write-region "(provide 'tramp-test-load)" nil tmp-name)
1386 ;; `load' in lread.c does not pass `must-suffix'. Why?
1387 ;(should-error (load tmp-name nil 'nomessage 'nosuffix 'must-suffix))
1388 (load tmp-name nil 'nomessage 'nosuffix)
1389 (should (featurep 'tramp-test-load)))
1390
1391 ;; Cleanup.
1392 (ignore-errors
1393 (and (featurep 'tramp-test-load) (unload-feature 'tramp-test-load))
1394 (delete-file tmp-name)))))
1395
1396 (ert-deftest tramp-test26-process-file ()
1397 "Check `process-file'."
1398 :tags '(:expensive-test)
1399 (skip-unless (tramp--test-enabled))
1400 (skip-unless
1401 (not
1402 (memq
1403 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1404 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler))))
1405
1406 (let* ((tmp-name (tramp--test-make-temp-name))
1407 (fnnd (file-name-nondirectory tmp-name))
1408 (default-directory tramp-test-temporary-file-directory)
1409 kill-buffer-query-functions)
1410 (unwind-protect
1411 (progn
1412 ;; We cannot use "/bin/true" and "/bin/false"; those paths
1413 ;; do not exist on hydra.
1414 (should (zerop (process-file "true")))
1415 (should-not (zerop (process-file "false")))
1416 (should-not (zerop (process-file "binary-does-not-exist")))
1417 (with-temp-buffer
1418 (write-region "foo" nil tmp-name)
1419 (should (file-exists-p tmp-name))
1420 (should (zerop (process-file "ls" nil t nil fnnd)))
1421 ;; `ls' could produce colorized output.
1422 (goto-char (point-min))
1423 (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
1424 (replace-match "" nil nil))
1425 (should (string-equal (format "%s\n" fnnd) (buffer-string)))
1426 (should-not (get-buffer-window (current-buffer) t))
1427
1428 ;; Second run. The output must be appended.
1429 (goto-char (point-max))
1430 (should (zerop (process-file "ls" nil t t fnnd)))
1431 ;; `ls' could produce colorized output.
1432 (goto-char (point-min))
1433 (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
1434 (replace-match "" nil nil))
1435 (should
1436 (string-equal (format "%s\n%s\n" fnnd fnnd) (buffer-string)))
1437 ;; A non-nil DISPLAY must not raise the buffer.
1438 (should-not (get-buffer-window (current-buffer) t))))
1439
1440 ;; Cleanup.
1441 (ignore-errors (delete-file tmp-name)))))
1442
1443 (ert-deftest tramp-test27-start-file-process ()
1444 "Check `start-file-process'."
1445 :tags '(:expensive-test)
1446 (skip-unless (tramp--test-enabled))
1447 (skip-unless
1448 (not
1449 (memq
1450 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1451 '(tramp-adb-file-name-handler
1452 tramp-gvfs-file-name-handler
1453 tramp-smb-file-name-handler))))
1454
1455 (let ((default-directory tramp-test-temporary-file-directory)
1456 (tmp-name (tramp--test-make-temp-name))
1457 kill-buffer-query-functions proc)
1458 (unwind-protect
1459 (with-temp-buffer
1460 (setq proc (start-file-process "test1" (current-buffer) "cat"))
1461 (should (processp proc))
1462 (should (equal (process-status proc) 'run))
1463 (process-send-string proc "foo")
1464 (process-send-eof proc)
1465 ;; Read output.
1466 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
1467 (while (< (- (point-max) (point-min)) (length "foo"))
1468 (accept-process-output proc 1)))
1469 (should (string-equal (buffer-string) "foo")))
1470
1471 ;; Cleanup.
1472 (ignore-errors (delete-process proc)))
1473
1474 (unwind-protect
1475 (with-temp-buffer
1476 (write-region "foo" nil tmp-name)
1477 (should (file-exists-p tmp-name))
1478 (setq proc
1479 (start-file-process
1480 "test2" (current-buffer)
1481 "cat" (file-name-nondirectory tmp-name)))
1482 (should (processp proc))
1483 ;; Read output.
1484 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
1485 (while (< (- (point-max) (point-min)) (length "foo"))
1486 (accept-process-output proc 1)))
1487 (should (string-equal (buffer-string) "foo")))
1488
1489 ;; Cleanup.
1490 (ignore-errors
1491 (delete-process proc)
1492 (delete-file tmp-name)))
1493
1494 (unwind-protect
1495 (with-temp-buffer
1496 (setq proc (start-file-process "test3" (current-buffer) "cat"))
1497 (should (processp proc))
1498 (should (equal (process-status proc) 'run))
1499 (set-process-filter
1500 proc
1501 (lambda (p s) (with-current-buffer (process-buffer p) (insert s))))
1502 (process-send-string proc "foo")
1503 (process-send-eof proc)
1504 ;; Read output.
1505 (with-timeout (10 (ert-fail "`start-file-process' timed out"))
1506 (while (< (- (point-max) (point-min)) (length "foo"))
1507 (accept-process-output proc 1)))
1508 (should (string-equal (buffer-string) "foo")))
1509
1510 ;; Cleanup.
1511 (ignore-errors (delete-process proc)))))
1512
1513 (ert-deftest tramp-test28-shell-command ()
1514 "Check `shell-command'."
1515 :tags '(:expensive-test)
1516 (skip-unless (tramp--test-enabled))
1517 (skip-unless
1518 (not
1519 (memq
1520 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1521 '(tramp-adb-file-name-handler
1522 tramp-gvfs-file-name-handler
1523 tramp-smb-file-name-handler))))
1524
1525 (let ((tmp-name (tramp--test-make-temp-name))
1526 (default-directory tramp-test-temporary-file-directory)
1527 kill-buffer-query-functions)
1528 (unwind-protect
1529 (with-temp-buffer
1530 (write-region "foo" nil tmp-name)
1531 (should (file-exists-p tmp-name))
1532 (shell-command
1533 (format "ls %s" (file-name-nondirectory tmp-name)) (current-buffer))
1534 ;; `ls' could produce colorized output.
1535 (goto-char (point-min))
1536 (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
1537 (replace-match "" nil nil))
1538 (should
1539 (string-equal
1540 (format "%s\n" (file-name-nondirectory tmp-name)) (buffer-string))))
1541
1542 ;; Cleanup.
1543 (ignore-errors (delete-file tmp-name)))
1544
1545 (unwind-protect
1546 (with-temp-buffer
1547 (write-region "foo" nil tmp-name)
1548 (should (file-exists-p tmp-name))
1549 (async-shell-command
1550 (format "ls %s" (file-name-nondirectory tmp-name)) (current-buffer))
1551 (set-process-sentinel (get-buffer-process (current-buffer)) nil)
1552 ;; Read output.
1553 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
1554 (while (< (- (point-max) (point-min))
1555 (1+ (length (file-name-nondirectory tmp-name))))
1556 (accept-process-output (get-buffer-process (current-buffer)) 1)))
1557 ;; `ls' could produce colorized output.
1558 (goto-char (point-min))
1559 (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
1560 (replace-match "" nil nil))
1561 ;; There might be a nasty "Process *Async Shell* finished" message.
1562 (goto-char (point-min))
1563 (forward-line)
1564 (narrow-to-region (point-min) (point))
1565 (should
1566 (string-equal
1567 (format "%s\n" (file-name-nondirectory tmp-name)) (buffer-string))))
1568
1569 ;; Cleanup.
1570 (ignore-errors (delete-file tmp-name)))
1571
1572 (unwind-protect
1573 (with-temp-buffer
1574 (write-region "foo" nil tmp-name)
1575 (should (file-exists-p tmp-name))
1576 (async-shell-command "read line; ls $line" (current-buffer))
1577 (set-process-sentinel (get-buffer-process (current-buffer)) nil)
1578 (process-send-string
1579 (get-buffer-process (current-buffer))
1580 (format "%s\n" (file-name-nondirectory tmp-name)))
1581 ;; Read output.
1582 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
1583 (while (< (- (point-max) (point-min))
1584 (1+ (length (file-name-nondirectory tmp-name))))
1585 (accept-process-output (get-buffer-process (current-buffer)) 1)))
1586 ;; `ls' could produce colorized output.
1587 (goto-char (point-min))
1588 (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
1589 (replace-match "" nil nil))
1590 ;; There might be a nasty "Process *Async Shell* finished" message.
1591 (goto-char (point-min))
1592 (forward-line)
1593 (narrow-to-region (point-min) (point))
1594 (should
1595 (string-equal
1596 (format "%s\n" (file-name-nondirectory tmp-name)) (buffer-string))))
1597
1598 ;; Cleanup.
1599 (ignore-errors (delete-file tmp-name)))))
1600
1601 (ert-deftest tramp-test29-vc-registered ()
1602 "Check `vc-registered'."
1603 :tags '(:expensive-test)
1604 (skip-unless (tramp--test-enabled))
1605 (skip-unless
1606 (eq
1607 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1608 'tramp-sh-file-name-handler))
1609
1610 (let* ((default-directory tramp-test-temporary-file-directory)
1611 (tmp-name1 (tramp--test-make-temp-name))
1612 (tmp-name2 (expand-file-name "foo" tmp-name1))
1613 (tramp-remote-process-environment tramp-remote-process-environment)
1614 (vc-handled-backends
1615 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
1616 (cond
1617 ((tramp-find-executable v vc-git-program (tramp-get-remote-path v))
1618 '(Git))
1619 ((tramp-find-executable v vc-hg-program (tramp-get-remote-path v))
1620 '(Hg))
1621 ((tramp-find-executable v vc-bzr-program (tramp-get-remote-path v))
1622 (setq tramp-remote-process-environment
1623 (cons (format "BZR_HOME=%s"
1624 (file-remote-p tmp-name1 'localname))
1625 tramp-remote-process-environment))
1626 ;; We must force a reconnect, in order to activate $BZR_HOME.
1627 (tramp-cleanup-connection
1628 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1629 nil 'keep-password)
1630 '(Bzr))
1631 (t nil)))))
1632 (skip-unless vc-handled-backends)
1633 (message "%s" vc-handled-backends)
1634
1635 (unwind-protect
1636 (progn
1637 (make-directory tmp-name1)
1638 (write-region "foo" nil tmp-name2)
1639 (should (file-directory-p tmp-name1))
1640 (should (file-exists-p tmp-name2))
1641 (should-not (vc-registered tmp-name1))
1642 (should-not (vc-registered tmp-name2))
1643
1644 (let ((default-directory tmp-name1))
1645 ;; Create empty repository, and register the file.
1646 ;; Sometimes, creation of repository fails (bzr!); we skip
1647 ;; the test then.
1648 (condition-case nil
1649 (vc-create-repo (car vc-handled-backends))
1650 (error (skip-unless nil)))
1651 ;; The structure of VC-FILESET is not documented. Let's
1652 ;; hope it won't change.
1653 (condition-case nil
1654 (vc-register
1655 (list (car vc-handled-backends)
1656 (list (file-name-nondirectory tmp-name2))))
1657 ;; `vc-register' has changed its arguments in Emacs 25.1.
1658 (error
1659 (vc-register
1660 nil (list (car vc-handled-backends)
1661 (list (file-name-nondirectory tmp-name2))))))
1662 ;; vc-git uses an own process sentinel, Tramp's sentinel
1663 ;; for flushing the cache isn't used.
1664 (dired-uncache (concat (file-remote-p default-directory) "/"))
1665 (should (vc-registered (file-name-nondirectory tmp-name2)))))
1666
1667 ;; Cleanup.
1668 (ignore-errors (delete-directory tmp-name1 'recursive)))))
1669
1670 (ert-deftest tramp-test30-make-auto-save-file-name ()
1671 "Check `make-auto-save-file-name'."
1672 (skip-unless (tramp--test-enabled))
1673
1674 (let ((tmp-name1 (tramp--test-make-temp-name))
1675 (tmp-name2 (tramp--test-make-temp-name)))
1676
1677 (unwind-protect
1678 (progn
1679 ;; Use default `auto-save-file-name-transforms' mechanism.
1680 (let (tramp-auto-save-directory)
1681 (with-temp-buffer
1682 (setq buffer-file-name tmp-name1)
1683 (should
1684 (string-equal
1685 (make-auto-save-file-name)
1686 ;; This is taken from original `make-auto-save-file-name'.
1687 (expand-file-name
1688 (format
1689 "#%s#"
1690 (subst-char-in-string
1691 ?/ ?! (replace-regexp-in-string "!" "!!" tmp-name1)))
1692 temporary-file-directory)))))
1693
1694 ;; No mapping.
1695 (let (tramp-auto-save-directory auto-save-file-name-transforms)
1696 (with-temp-buffer
1697 (setq buffer-file-name tmp-name1)
1698 (should
1699 (string-equal
1700 (make-auto-save-file-name)
1701 (expand-file-name
1702 (format "#%s#" (file-name-nondirectory tmp-name1))
1703 tramp-test-temporary-file-directory)))))
1704
1705 ;; Use default `tramp-auto-save-directory' mechanism.
1706 (let ((tramp-auto-save-directory tmp-name2))
1707 (with-temp-buffer
1708 (setq buffer-file-name tmp-name1)
1709 (should
1710 (string-equal
1711 (make-auto-save-file-name)
1712 ;; This is taken from Tramp.
1713 (expand-file-name
1714 (format
1715 "#%s#"
1716 (tramp-subst-strs-in-string
1717 '(("_" . "|")
1718 ("/" . "_a")
1719 (":" . "_b")
1720 ("|" . "__")
1721 ("[" . "_l")
1722 ("]" . "_r"))
1723 tmp-name1))
1724 tmp-name2)))
1725 (should (file-directory-p tmp-name2))))
1726
1727 ;; Relative file names shall work, too.
1728 (let ((tramp-auto-save-directory "."))
1729 (with-temp-buffer
1730 (setq buffer-file-name tmp-name1
1731 default-directory tmp-name2)
1732 (should
1733 (string-equal
1734 (make-auto-save-file-name)
1735 ;; This is taken from Tramp.
1736 (expand-file-name
1737 (format
1738 "#%s#"
1739 (tramp-subst-strs-in-string
1740 '(("_" . "|")
1741 ("/" . "_a")
1742 (":" . "_b")
1743 ("|" . "__")
1744 ("[" . "_l")
1745 ("]" . "_r"))
1746 tmp-name1))
1747 tmp-name2)))
1748 (should (file-directory-p tmp-name2)))))
1749
1750 ;; Cleanup.
1751 (ignore-errors (delete-file tmp-name1))
1752 (ignore-errors (delete-directory tmp-name2 'recursive)))))
1753
1754 (defun tramp--test-adb-p ()
1755 "Check, whether the remote host runs Android.
1756 This requires restrictions of file name syntax."
1757 (tramp-adb-file-name-p tramp-test-temporary-file-directory))
1758
1759 (defun tramp--test-ftp-p ()
1760 "Check, whether an FTP-like method is used.
1761 This does not support globbing characters in file names (yet)."
1762 ;; Globbing characters are ??, ?* and ?\[.
1763 (and (eq (tramp-find-foreign-file-name-handler
1764 tramp-test-temporary-file-directory)
1765 'tramp-sh-file-name-handler)
1766 (string-match
1767 "ftp$" (file-remote-p tramp-test-temporary-file-directory 'method))))
1768
1769 (defun tramp--test-gvfs-p ()
1770 "Check, whether the remote host runs a GVFS based method.
1771 This requires restrictions of file name syntax."
1772 (tramp-gvfs-file-name-p tramp-test-temporary-file-directory))
1773
1774 (defun tramp--test-smb-or-windows-nt-p ()
1775 "Check, whether the locale or remote host runs MS Windows.
1776 This requires restrictions of file name syntax."
1777 (or (eq system-type 'windows-nt)
1778 (tramp-smb-file-name-p tramp-test-temporary-file-directory)))
1779
1780 (defun tramp--test-hpux-p ()
1781 "Check, whether the remote host runs HP-UX.
1782 Several special characters do not work properly there."
1783 ;; We must refill the cache. `file-truename' does it.
1784 (with-parsed-tramp-file-name
1785 (file-truename tramp-test-temporary-file-directory) nil
1786 (string-match "^HP-UX" (tramp-get-connection-property v "uname" ""))))
1787
1788 (defun tramp--test-check-files (&rest files)
1789 "Run a simple but comprehensive test over every file in FILES."
1790 ;; We must use `file-truename' for the temporary directory, because
1791 ;; it could be located on a symlinked directory. This would let the
1792 ;; test fail.
1793 (let* ((tramp-test-temporary-file-directory
1794 (file-truename tramp-test-temporary-file-directory))
1795 (tmp-name1 (tramp--test-make-temp-name))
1796 (tmp-name2 (tramp--test-make-temp-name 'local))
1797 (files (delq nil files)))
1798 (unwind-protect
1799 (progn
1800 (make-directory tmp-name1)
1801 (make-directory tmp-name2)
1802 (dolist (elt files)
1803 (let* ((file1 (expand-file-name elt tmp-name1))
1804 (file2 (expand-file-name elt tmp-name2))
1805 (file3 (expand-file-name (concat elt "foo") tmp-name1)))
1806 (write-region elt nil file1)
1807 (should (file-exists-p file1))
1808
1809 ;; Check file contents.
1810 (with-temp-buffer
1811 (insert-file-contents file1)
1812 (should (string-equal (buffer-string) elt)))
1813
1814 ;; Copy file both directions.
1815 (copy-file file1 tmp-name2)
1816 (should (file-exists-p file2))
1817 (delete-file file1)
1818 (should-not (file-exists-p file1))
1819 (copy-file file2 tmp-name1)
1820 (should (file-exists-p file1))
1821
1822 ;; Method "smb" supports `make-symbolic-link' only if the
1823 ;; remote host has CIFS capabilities. tramp-adb.el and
1824 ;; tramp-gvfs.el do not support symbolic links at all.
1825 (condition-case err
1826 (progn
1827 (make-symbolic-link file1 file3)
1828 (should (file-symlink-p file3))
1829 (should
1830 (string-equal
1831 (expand-file-name file1) (file-truename file3)))
1832 (should
1833 (string-equal
1834 (car (file-attributes file3))
1835 (file-remote-p (file-truename file1) 'localname)))
1836 ;; Check file contents.
1837 (with-temp-buffer
1838 (insert-file-contents file3)
1839 (should (string-equal (buffer-string) elt)))
1840 (delete-file file3))
1841 (file-error
1842 (should (string-equal (error-message-string err)
1843 "make-symbolic-link not supported"))))))
1844
1845 ;; Check file names.
1846 (should (equal (directory-files
1847 tmp-name1 nil directory-files-no-dot-files-regexp)
1848 (sort (copy-sequence files) 'string-lessp)))
1849 (should (equal (directory-files
1850 tmp-name2 nil directory-files-no-dot-files-regexp)
1851 (sort (copy-sequence files) 'string-lessp)))
1852
1853 ;; `substitute-in-file-name' could return different values.
1854 ;; For `adb', there could be strange file permissions
1855 ;; preventing overwriting a file. We don't care in this
1856 ;; testcase.
1857 (dolist (elt files)
1858 (let ((file1
1859 (substitute-in-file-name (expand-file-name elt tmp-name1)))
1860 (file2
1861 (substitute-in-file-name (expand-file-name elt tmp-name2))))
1862 (ignore-errors (write-region elt nil file1))
1863 (should (file-exists-p file1))
1864 (ignore-errors (write-region elt nil file2 nil 'nomessage))
1865 (should (file-exists-p file2))))
1866
1867 (should (equal (directory-files
1868 tmp-name1 nil directory-files-no-dot-files-regexp)
1869 (directory-files
1870 tmp-name2 nil directory-files-no-dot-files-regexp)))
1871
1872 ;; Check directory creation. We use a subdirectory "foo"
1873 ;; in order to avoid conflicts with previous file name tests.
1874 (dolist (elt files)
1875 (let* ((elt1 (concat elt "foo"))
1876 (file1 (expand-file-name (concat "foo/" elt) tmp-name1))
1877 (file2 (expand-file-name elt file1))
1878 (file3 (expand-file-name elt1 file1)))
1879 (make-directory file1 'parents)
1880 (should (file-directory-p file1))
1881 (write-region elt nil file2)
1882 (should (file-exists-p file2))
1883 (should
1884 (equal
1885 (directory-files file1 nil directory-files-no-dot-files-regexp)
1886 `(,elt)))
1887 (should
1888 (equal
1889 (caar (directory-files-and-attributes
1890 file1 nil directory-files-no-dot-files-regexp))
1891 elt))
1892
1893 ;; Check symlink in `directory-files-and-attributes'.
1894 (condition-case err
1895 (progn
1896 (make-symbolic-link file2 file3)
1897 (should (file-symlink-p file3))
1898 (should
1899 (string-equal
1900 (caar (directory-files-and-attributes
1901 file1 nil (regexp-quote elt1)))
1902 elt1))
1903 (should
1904 (string-equal
1905 (cadr (car (directory-files-and-attributes
1906 file1 nil (regexp-quote elt1))))
1907 (file-remote-p (file-truename file2) 'localname)))
1908 (delete-file file3)
1909 (should-not (file-exists-p file3)))
1910 (file-error
1911 (should (string-equal (error-message-string err)
1912 "make-symbolic-link not supported"))))
1913
1914 (delete-file file2)
1915 (should-not (file-exists-p file2))
1916 (delete-directory file1)
1917 (should-not (file-exists-p file1)))))
1918
1919 ;; Cleanup.
1920 (ignore-errors (delete-directory tmp-name1 'recursive))
1921 (ignore-errors (delete-directory tmp-name2 'recursive)))))
1922
1923 (defun tramp--test-special-characters ()
1924 "Perform the test in `tramp-test31-special-characters*'."
1925 ;; Newlines, slashes and backslashes in file names are not
1926 ;; supported. So we don't test. And we don't test the tab
1927 ;; character on Windows or Cygwin, because the backslash is
1928 ;; interpreted as a path separator, preventing "\t" from being
1929 ;; expanded to <TAB>.
1930 (tramp--test-check-files
1931 (if (or (tramp--test-gvfs-p) (tramp--test-smb-or-windows-nt-p))
1932 "foo bar baz"
1933 (if (or (tramp--test-adb-p) (eq system-type 'cygwin))
1934 " foo bar baz "
1935 " foo\tbar baz\t"))
1936 "$foo$bar$$baz$"
1937 "-foo-bar-baz-"
1938 "%foo%bar%baz%"
1939 "&foo&bar&baz&"
1940 (unless (or (tramp--test-ftp-p)
1941 (tramp--test-gvfs-p)
1942 (tramp--test-smb-or-windows-nt-p))
1943 "?foo?bar?baz?")
1944 (unless (or (tramp--test-ftp-p)
1945 (tramp--test-gvfs-p)
1946 (tramp--test-smb-or-windows-nt-p))
1947 "*foo*bar*baz*")
1948 (if (or (tramp--test-gvfs-p) (tramp--test-smb-or-windows-nt-p))
1949 "'foo'bar'baz'"
1950 "'foo\"bar'baz\"")
1951 "#foo~bar#baz~"
1952 (if (or (tramp--test-gvfs-p) (tramp--test-smb-or-windows-nt-p))
1953 "!foo!bar!baz!"
1954 "!foo|bar!baz|")
1955 (if (or (tramp--test-gvfs-p) (tramp--test-smb-or-windows-nt-p))
1956 ";foo;bar;baz;"
1957 ":foo;bar:baz;")
1958 (unless (or (tramp--test-gvfs-p) (tramp--test-smb-or-windows-nt-p))
1959 "<foo>bar<baz>")
1960 "(foo)bar(baz)"
1961 (unless (or (tramp--test-ftp-p) (tramp--test-gvfs-p)) "[foo]bar[baz]")
1962 "{foo}bar{baz}"))
1963
1964 ;; These tests are inspired by Bug#17238.
1965 (ert-deftest tramp-test31-special-characters ()
1966 "Check special characters in file names."
1967 (skip-unless (tramp--test-enabled))
1968
1969 (tramp--test-special-characters))
1970
1971 (ert-deftest tramp-test31-special-characters-with-stat ()
1972 "Check special characters in file names.
1973 Use the `stat' command."
1974 :tags '(:expensive-test)
1975 (skip-unless (tramp--test-enabled))
1976 (skip-unless
1977 (eq
1978 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1979 'tramp-sh-file-name-handler))
1980 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
1981 (skip-unless (tramp-get-remote-stat v)))
1982
1983 (let ((tramp-connection-properties
1984 (append
1985 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory))
1986 "perl" nil))
1987 tramp-connection-properties)))
1988 (tramp--test-special-characters)))
1989
1990 (ert-deftest tramp-test31-special-characters-with-perl ()
1991 "Check special characters in file names.
1992 Use the `perl' command."
1993 :tags '(:expensive-test)
1994 (skip-unless (tramp--test-enabled))
1995 (skip-unless
1996 (eq
1997 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1998 'tramp-sh-file-name-handler))
1999 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
2000 (skip-unless (tramp-get-remote-perl v)))
2001
2002 (let ((tramp-connection-properties
2003 (append
2004 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory))
2005 "stat" nil)
2006 ;; See `tramp-sh-handle-file-truename'.
2007 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory))
2008 "readlink" nil))
2009 tramp-connection-properties)))
2010 (tramp--test-special-characters)))
2011
2012 (ert-deftest tramp-test31-special-characters-with-ls ()
2013 "Check special characters in file names.
2014 Use the `ls' command."
2015 :tags '(:expensive-test)
2016 (skip-unless (tramp--test-enabled))
2017 (skip-unless
2018 (eq
2019 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
2020 'tramp-sh-file-name-handler))
2021
2022 (let ((tramp-connection-properties
2023 (append
2024 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory))
2025 "perl" nil)
2026 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory))
2027 "stat" nil)
2028 ;; See `tramp-sh-handle-file-truename'.
2029 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory))
2030 "readlink" nil))
2031 tramp-connection-properties)))
2032 (tramp--test-special-characters)))
2033
2034 (defun tramp--test-utf8 ()
2035 "Perform the test in `tramp-test32-utf8*'."
2036 (let ((coding-system-for-read 'utf-8)
2037 (coding-system-for-write 'utf-8)
2038 (file-name-coding-system 'utf-8))
2039 (tramp--test-check-files
2040 (unless (tramp--test-hpux-p) "Γυρίστε το Γαλαξία με Ώτο Στοπ")
2041 (unless (tramp--test-hpux-p)
2042 "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت")
2043 "银河系漫游指南系列"
2044 "Автостопом по гала́ктике")))
2045
2046 (ert-deftest tramp-test32-utf8 ()
2047 "Check UTF8 encoding in file names and file contents."
2048 (skip-unless (tramp--test-enabled))
2049
2050 (tramp--test-utf8))
2051
2052 (ert-deftest tramp-test32-utf8-with-stat ()
2053 "Check UTF8 encoding in file names and file contents.
2054 Use the `stat' command."
2055 :tags '(:expensive-test)
2056 (skip-unless (tramp--test-enabled))
2057 (skip-unless
2058 (eq
2059 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
2060 'tramp-sh-file-name-handler))
2061 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
2062 (skip-unless (tramp-get-remote-stat v)))
2063
2064 (let ((tramp-connection-properties
2065 (append
2066 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory))
2067 "perl" nil))
2068 tramp-connection-properties)))
2069 (tramp--test-utf8)))
2070
2071 (ert-deftest tramp-test32-utf8-with-perl ()
2072 "Check UTF8 encoding in file names and file contents.
2073 Use the `perl' command."
2074 :tags '(:expensive-test)
2075 (skip-unless (tramp--test-enabled))
2076 (skip-unless
2077 (eq
2078 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
2079 'tramp-sh-file-name-handler))
2080 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
2081 (skip-unless (tramp-get-remote-perl v)))
2082
2083 (let ((tramp-connection-properties
2084 (append
2085 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory))
2086 "stat" nil)
2087 ;; See `tramp-sh-handle-file-truename'.
2088 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory))
2089 "readlink" nil))
2090 tramp-connection-properties)))
2091 (tramp--test-utf8)))
2092
2093 (ert-deftest tramp-test32-utf8-with-ls ()
2094 "Check UTF8 encoding in file names and file contents.
2095 Use the `ls' command."
2096 :tags '(:expensive-test)
2097 (skip-unless (tramp--test-enabled))
2098 (skip-unless
2099 (eq
2100 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
2101 'tramp-sh-file-name-handler))
2102
2103 (let ((tramp-connection-properties
2104 (append
2105 `((,(regexp-quote (file-remote-p tramp-test-temporary-file-directory))
2106 "perl" nil)
2107 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory))
2108 "stat" nil)
2109 ;; See `tramp-sh-handle-file-truename'.
2110 (,(regexp-quote (file-remote-p tramp-test-temporary-file-directory))
2111 "readlink" nil))
2112 tramp-connection-properties)))
2113 (tramp--test-utf8)))
2114
2115 ;; This test is inspired by Bug#16928.
2116 (ert-deftest tramp-test33-asynchronous-requests ()
2117 "Check parallel asynchronous requests.
2118 Such requests could arrive from timers, process filters and
2119 process sentinels. They shall not disturb each other."
2120 ;; Mark as failed until bug has been fixed.
2121 :expected-result :failed
2122 :tags '(:expensive-test)
2123 (skip-unless (tramp--test-enabled))
2124 (skip-unless
2125 (eq
2126 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
2127 'tramp-sh-file-name-handler))
2128
2129 ;; Keep instrumentation verbosity 0 until Tramp bug is fixed. This
2130 ;; has the side effect, that this test fails instead to abort. Good
2131 ;; for hydra.
2132 (tramp--instrument-test-case 0
2133 (let* ((tmp-name (tramp--test-make-temp-name))
2134 (default-directory tmp-name)
2135 (remote-file-name-inhibit-cache t)
2136 timer buffers kill-buffer-query-functions)
2137
2138 (unwind-protect
2139 (progn
2140 (make-directory tmp-name)
2141
2142 ;; Setup a timer in order to raise an ordinary command again
2143 ;; and again. `vc-registered' is well suited, because there
2144 ;; are many checks.
2145 (setq
2146 timer
2147 (run-at-time
2148 0 1
2149 (lambda ()
2150 (when buffers
2151 (vc-registered
2152 (buffer-name (nth (random (length buffers)) buffers)))))))
2153
2154 ;; Create temporary buffers. The number of buffers
2155 ;; corresponds to the number of processes; it could be
2156 ;; increased in order to make pressure on Tramp.
2157 (dotimes (i 5)
2158 (add-to-list 'buffers (generate-new-buffer "*temp*")))
2159
2160 ;; Open asynchronous processes. Set process sentinel.
2161 (dolist (buf buffers)
2162 (async-shell-command "read line; touch $line; echo $line" buf)
2163 (set-process-sentinel
2164 (get-buffer-process buf)
2165 (lambda (proc _state)
2166 (delete-file (buffer-name (process-buffer proc))))))
2167
2168 ;; Send a string. Use a random order of the buffers. Mix
2169 ;; with regular operation.
2170 (let ((buffers (copy-sequence buffers))
2171 buf)
2172 (while buffers
2173 (setq buf (nth (random (length buffers)) buffers))
2174 (process-send-string
2175 (get-buffer-process buf) (format "'%s'\n" buf))
2176 (file-attributes (buffer-name buf))
2177 (setq buffers (delq buf buffers))))
2178
2179 ;; Wait until the whole output has been read.
2180 (with-timeout ((* 10 (length buffers))
2181 (ert-fail "`async-shell-command' timed out"))
2182 (let ((buffers (copy-sequence buffers))
2183 buf)
2184 (while buffers
2185 (setq buf (nth (random (length buffers)) buffers))
2186 (if (ignore-errors
2187 (memq (process-status (get-buffer-process buf))
2188 '(run open)))
2189 (accept-process-output (get-buffer-process buf) 0.1)
2190 (setq buffers (delq buf buffers))))))
2191
2192 ;; Check.
2193 (dolist (buf buffers)
2194 (with-current-buffer buf
2195 (should
2196 (string-equal (format "'%s'\n" buf) (buffer-string)))))
2197 (should-not
2198 (directory-files tmp-name nil directory-files-no-dot-files-regexp)))
2199
2200 ;; Cleanup.
2201 (ignore-errors (cancel-timer timer))
2202 (ignore-errors (delete-directory tmp-name 'recursive))
2203 (dolist (buf buffers)
2204 (ignore-errors (kill-buffer buf)))))))
2205
2206 (ert-deftest tramp-test34-recursive-load ()
2207 "Check that Tramp does not fail due to recursive load."
2208 (skip-unless (tramp--test-enabled))
2209
2210 (dolist (code
2211 (list
2212 (format
2213 "(expand-file-name %S)"
2214 tramp-test-temporary-file-directory)
2215 (format
2216 "(let ((default-directory %S)) (expand-file-name %S))"
2217 tramp-test-temporary-file-directory
2218 temporary-file-directory)))
2219 (should-not
2220 (string-match
2221 "Recursive load"
2222 (shell-command-to-string
2223 (format
2224 "%s -batch -Q -L %s --eval %s"
2225 (expand-file-name invocation-name invocation-directory)
2226 (mapconcat 'shell-quote-argument load-path " -L ")
2227 (shell-quote-argument code)))))))
2228
2229 (ert-deftest tramp-test35-unload ()
2230 "Check that Tramp and its subpackages unload completely.
2231 Since it unloads Tramp, it shall be the last test to run."
2232 ;; Mark as failed until all symbols are unbound.
2233 :expected-result (if (featurep 'tramp) :failed :passed)
2234 :tags '(:expensive-test)
2235 (when (featurep 'tramp)
2236 (unload-feature 'tramp 'force)
2237 ;; No Tramp feature must be left.
2238 (should-not (featurep 'tramp))
2239 (should-not (all-completions "tramp" (delq 'tramp-tests features)))
2240 ;; `file-name-handler-alist' must be clean.
2241 (should-not (all-completions "tramp" (mapcar 'cdr file-name-handler-alist)))
2242 ;; There shouldn't be left a bound symbol. We do not regard our
2243 ;; test symbols, and the Tramp unload hooks.
2244 (mapatoms
2245 (lambda (x)
2246 (and (or (boundp x) (functionp x))
2247 (string-match "^tramp" (symbol-name x))
2248 (not (string-match "^tramp--?test" (symbol-name x)))
2249 (not (string-match "unload-hook$" (symbol-name x)))
2250 (ert-fail (format "`%s' still bound" x)))))
2251 ;; There shouldn't be left a hook function containing a Tramp
2252 ;; function. We do not regard the Tramp unload hooks.
2253 (mapatoms
2254 (lambda (x)
2255 (and (boundp x)
2256 (string-match "-hooks?$" (symbol-name x))
2257 (not (string-match "unload-hook$" (symbol-name x)))
2258 (consp (symbol-value x))
2259 (ignore-errors (all-completions "tramp" (symbol-value x)))
2260 (ert-fail (format "Hook `%s' still contains Tramp function" x)))))))
2261
2262 ;; TODO:
2263
2264 ;; * dired-compress-file
2265 ;; * dired-uncache
2266 ;; * file-acl
2267 ;; * file-ownership-preserved-p
2268 ;; * file-selinux-context
2269 ;; * find-backup-file-name
2270 ;; * set-file-acl
2271 ;; * set-file-selinux-context
2272
2273 ;; * Work on skipped tests. Make a comment, when it is impossible.
2274 ;; * Fix `tramp-test15-copy-directory' for `smb'. Using tar in a pipe
2275 ;; doesn't work well when an interactive password must be provided.
2276 ;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?).
2277 ;; * Fix Bug#16928. Set expected error of `tramp-test33-asynchronous-requests'.
2278 ;; * Fix `tramp-test35-unload' (Not all symbols are unbound). Set
2279 ;; expected error.
2280
2281 (defun tramp-test-all (&optional interactive)
2282 "Run all tests for \\[tramp]."
2283 (interactive "p")
2284 (funcall
2285 (if interactive 'ert-run-tests-interactively 'ert-run-tests-batch) "^tramp"))
2286
2287 (provide 'tramp-tests)
2288 ;;; tramp-tests.el ends here