Merge from emacs-24; up to 2014-06-03T06:51:18Z!eliz@gnu.org
[bpt/emacs.git] / test / automated / tramp-tests.el
1 ;;; tramp-tests.el --- Tests of remote file access
2
3 ;; Copyright (C) 2013-2014 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 (declare-function tramp-find-executable "tramp-sh")
48 (declare-function tramp-get-remote-path "tramp-sh")
49 (defvar tramp-copy-size-limit)
50 (defvar tramp-remote-process-environment)
51
52 ;; There is no default value on w32 systems, which could work out of the box.
53 (defconst tramp-test-temporary-file-directory
54 (cond
55 ((getenv "REMOTE_TEMPORARY_FILE_DIRECTORY"))
56 ((eq system-type 'windows-nt) null-device)
57 (t (add-to-list
58 'tramp-methods
59 '("mock"
60 (tramp-login-program "sh")
61 (tramp-login-args (("-i")))
62 (tramp-remote-shell "/bin/sh")
63 (tramp-remote-shell-args ("-c"))
64 (tramp-connection-timeout 10)))
65 (format "/mock::%s" temporary-file-directory)))
66 "Temporary directory for Tramp tests.")
67
68 (setq password-cache-expiry nil
69 tramp-verbose 0
70 tramp-copy-size-limit nil
71 tramp-message-show-message nil)
72
73 ;; This shall happen on hydra only.
74 (when (getenv "NIX_STORE")
75 (add-to-list 'tramp-remote-path 'tramp-own-remote-path))
76
77 (defvar tramp--test-enabled-checked nil
78 "Cached result of `tramp--test-enabled'.
79 If the function did run, the value is a cons cell, the `cdr'
80 being the result.")
81
82 (defun tramp--test-enabled ()
83 "Whether remote file access is enabled."
84 (unless (consp tramp--test-enabled-checked)
85 (setq
86 tramp--test-enabled-checked
87 (cons
88 t (ignore-errors
89 (and
90 (file-remote-p tramp-test-temporary-file-directory)
91 (file-directory-p tramp-test-temporary-file-directory)
92 (file-writable-p tramp-test-temporary-file-directory))))))
93
94 (when (cdr tramp--test-enabled-checked)
95 ;; Cleanup connection.
96 (tramp-cleanup-connection
97 (tramp-dissect-file-name tramp-test-temporary-file-directory)
98 nil 'keep-password))
99
100 ;; Return result.
101 (cdr tramp--test-enabled-checked))
102
103 (defun tramp--test-make-temp-name (&optional local)
104 "Create a temporary file name for test."
105 (expand-file-name
106 (make-temp-name "tramp-test")
107 (if local temporary-file-directory tramp-test-temporary-file-directory)))
108
109 (defmacro tramp--instrument-test-case (verbose &rest body)
110 "Run BODY with `tramp-verbose' equal VERBOSE.
111 Print the the content of the Tramp debug buffer, if BODY does not
112 eval properly in `should', `should-not' or `should-error'."
113 (declare (indent 1) (debug (natnump body)))
114 `(let ((tramp-verbose ,verbose)
115 (tramp-message-show-message t)
116 (tramp-debug-on-error t))
117 (condition-case err
118 ;; In general, we cannot use a timeout here: this would
119 ;; prevent traces when the test runs into an error.
120 ; (with-timeout (10 (ert-fail "`tramp--instrument-test-case' timed out"))
121 (progn
122 ,@body)
123 (ert-test-skipped
124 (signal (car err) (cdr err)))
125 ((error quit)
126 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
127 (with-current-buffer (tramp-get-connection-buffer v)
128 (message "%s" (buffer-string)))
129 (with-current-buffer (tramp-get-debug-buffer v)
130 (message "%s" (buffer-string))))
131 (message "%s" err)
132 (signal (car err) (cdr err))))))
133
134 (ert-deftest tramp-test00-availability ()
135 "Test availability of Tramp functions."
136 :expected-result (if (tramp--test-enabled) :passed :failed)
137 (message "Remote directory: `%s'" tramp-test-temporary-file-directory)
138 (should (ignore-errors
139 (and
140 (file-remote-p tramp-test-temporary-file-directory)
141 (file-directory-p tramp-test-temporary-file-directory)
142 (file-writable-p tramp-test-temporary-file-directory)))))
143
144 (ert-deftest tramp-test01-file-name-syntax ()
145 "Check remote file name syntax."
146 ;; Simple cases.
147 (should (tramp-tramp-file-p "/method::"))
148 (should (tramp-tramp-file-p "/host:"))
149 (should (tramp-tramp-file-p "/user@:"))
150 (should (tramp-tramp-file-p "/user@host:"))
151 (should (tramp-tramp-file-p "/method:host:"))
152 (should (tramp-tramp-file-p "/method:user@:"))
153 (should (tramp-tramp-file-p "/method:user@host:"))
154 (should (tramp-tramp-file-p "/method:user@email@host:"))
155
156 ;; Using a port.
157 (should (tramp-tramp-file-p "/host#1234:"))
158 (should (tramp-tramp-file-p "/user@host#1234:"))
159 (should (tramp-tramp-file-p "/method:host#1234:"))
160 (should (tramp-tramp-file-p "/method:user@host#1234:"))
161
162 ;; Using an IPv4 address.
163 (should (tramp-tramp-file-p "/1.2.3.4:"))
164 (should (tramp-tramp-file-p "/user@1.2.3.4:"))
165 (should (tramp-tramp-file-p "/method:1.2.3.4:"))
166 (should (tramp-tramp-file-p "/method:user@1.2.3.4:"))
167
168 ;; Using an IPv6 address.
169 (should (tramp-tramp-file-p "/[]:"))
170 (should (tramp-tramp-file-p "/[::1]:"))
171 (should (tramp-tramp-file-p "/user@[::1]:"))
172 (should (tramp-tramp-file-p "/method:[::1]:"))
173 (should (tramp-tramp-file-p "/method:user@[::1]:"))
174
175 ;; Local file name part.
176 (should (tramp-tramp-file-p "/host:/:"))
177 (should (tramp-tramp-file-p "/method:::"))
178 (should (tramp-tramp-file-p "/method::/path/to/file"))
179 (should (tramp-tramp-file-p "/method::file"))
180
181 ;; Multihop.
182 (should (tramp-tramp-file-p "/method1:|method2::"))
183 (should (tramp-tramp-file-p "/method1:host1|host2:"))
184 (should (tramp-tramp-file-p "/method1:host1|method2:host2:"))
185 (should (tramp-tramp-file-p "/method1:user1@host1|method2:user2@host2:"))
186 (should (tramp-tramp-file-p
187 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:"))
188
189 ;; No strings.
190 (should-not (tramp-tramp-file-p nil))
191 (should-not (tramp-tramp-file-p 'symbol))
192 ;; "/:" suppresses file name handlers.
193 (should-not (tramp-tramp-file-p "/::"))
194 (should-not (tramp-tramp-file-p "/:@:"))
195 (should-not (tramp-tramp-file-p "/:[]:"))
196 ;; Multihops require a method.
197 (should-not (tramp-tramp-file-p "/host1|host2:"))
198 ;; Methods or hostnames shall be at least two characters on MS Windows.
199 (when (memq system-type '(cygwin windows-nt))
200 (should-not (tramp-tramp-file-p "/c:/path/to/file"))
201 (should-not (tramp-tramp-file-p "/c::/path/to/file"))))
202
203 (ert-deftest tramp-test02-file-name-dissect ()
204 "Check remote file name components."
205 (let ((tramp-default-method "default-method")
206 (tramp-default-user "default-user")
207 (tramp-default-host "default-host"))
208 ;; Expand `tramp-default-user' and `tramp-default-host'.
209 (should (string-equal
210 (file-remote-p "/method::")
211 (format "/%s:%s@%s:" "method" "default-user" "default-host")))
212 (should (string-equal (file-remote-p "/method::" 'method) "method"))
213 (should (string-equal (file-remote-p "/method::" 'user) "default-user"))
214 (should (string-equal (file-remote-p "/method::" 'host) "default-host"))
215 (should (string-equal (file-remote-p "/method::" 'localname) ""))
216
217 ;; Expand `tramp-default-method' and `tramp-default-user'.
218 (should (string-equal
219 (file-remote-p "/host:")
220 (format "/%s:%s@%s:" "default-method" "default-user" "host")))
221 (should (string-equal (file-remote-p "/host:" 'method) "default-method"))
222 (should (string-equal (file-remote-p "/host:" 'user) "default-user"))
223 (should (string-equal (file-remote-p "/host:" 'host) "host"))
224 (should (string-equal (file-remote-p "/host:" 'localname) ""))
225
226 ;; Expand `tramp-default-method' and `tramp-default-host'.
227 (should (string-equal
228 (file-remote-p "/user@:")
229 (format "/%s:%s@%s:" "default-method""user" "default-host")))
230 (should (string-equal (file-remote-p "/user@:" 'method) "default-method"))
231 (should (string-equal (file-remote-p "/user@:" 'user) "user"))
232 (should (string-equal (file-remote-p "/user@:" 'host) "default-host"))
233 (should (string-equal (file-remote-p "/user@:" 'localname) ""))
234
235 ;; Expand `tramp-default-method'.
236 (should (string-equal
237 (file-remote-p "/user@host:")
238 (format "/%s:%s@%s:" "default-method" "user" "host")))
239 (should (string-equal
240 (file-remote-p "/user@host:" 'method) "default-method"))
241 (should (string-equal (file-remote-p "/user@host:" 'user) "user"))
242 (should (string-equal (file-remote-p "/user@host:" 'host) "host"))
243 (should (string-equal (file-remote-p "/user@host:" 'localname) ""))
244
245 ;; Expand `tramp-default-user'.
246 (should (string-equal
247 (file-remote-p "/method:host:")
248 (format "/%s:%s@%s:" "method" "default-user" "host")))
249 (should (string-equal (file-remote-p "/method:host:" 'method) "method"))
250 (should (string-equal (file-remote-p "/method:host:" 'user) "default-user"))
251 (should (string-equal (file-remote-p "/method:host:" 'host) "host"))
252 (should (string-equal (file-remote-p "/method:host:" 'localname) ""))
253
254 ;; Expand `tramp-default-host'.
255 (should (string-equal
256 (file-remote-p "/method:user@:")
257 (format "/%s:%s@%s:" "method" "user" "default-host")))
258 (should (string-equal (file-remote-p "/method:user@:" 'method) "method"))
259 (should (string-equal (file-remote-p "/method:user@:" 'user) "user"))
260 (should (string-equal (file-remote-p "/method:user@:" 'host)
261 "default-host"))
262 (should (string-equal (file-remote-p "/method:user@:" 'localname) ""))
263
264 ;; No expansion.
265 (should (string-equal
266 (file-remote-p "/method:user@host:")
267 (format "/%s:%s@%s:" "method" "user" "host")))
268 (should (string-equal
269 (file-remote-p "/method:user@host:" 'method) "method"))
270 (should (string-equal (file-remote-p "/method:user@host:" 'user) "user"))
271 (should (string-equal (file-remote-p "/method:user@host:" 'host) "host"))
272 (should (string-equal (file-remote-p "/method:user@host:" 'localname) ""))
273
274 ;; No expansion.
275 (should (string-equal
276 (file-remote-p "/method:user@email@host:")
277 (format "/%s:%s@%s:" "method" "user@email" "host")))
278 (should (string-equal
279 (file-remote-p "/method:user@email@host:" 'method) "method"))
280 (should (string-equal
281 (file-remote-p "/method:user@email@host:" 'user) "user@email"))
282 (should (string-equal
283 (file-remote-p "/method:user@email@host:" 'host) "host"))
284 (should (string-equal
285 (file-remote-p "/method:user@email@host:" 'localname) ""))
286
287 ;; Expand `tramp-default-method' and `tramp-default-user'.
288 (should (string-equal
289 (file-remote-p "/host#1234:")
290 (format "/%s:%s@%s:" "default-method" "default-user" "host#1234")))
291 (should (string-equal
292 (file-remote-p "/host#1234:" 'method) "default-method"))
293 (should (string-equal (file-remote-p "/host#1234:" 'user) "default-user"))
294 (should (string-equal (file-remote-p "/host#1234:" 'host) "host#1234"))
295 (should (string-equal (file-remote-p "/host#1234:" 'localname) ""))
296
297 ;; Expand `tramp-default-method'.
298 (should (string-equal
299 (file-remote-p "/user@host#1234:")
300 (format "/%s:%s@%s:" "default-method" "user" "host#1234")))
301 (should (string-equal
302 (file-remote-p "/user@host#1234:" 'method) "default-method"))
303 (should (string-equal (file-remote-p "/user@host#1234:" 'user) "user"))
304 (should (string-equal (file-remote-p "/user@host#1234:" 'host) "host#1234"))
305 (should (string-equal (file-remote-p "/user@host#1234:" 'localname) ""))
306
307 ;; Expand `tramp-default-user'.
308 (should (string-equal
309 (file-remote-p "/method:host#1234:")
310 (format "/%s:%s@%s:" "method" "default-user" "host#1234")))
311 (should (string-equal
312 (file-remote-p "/method:host#1234:" 'method) "method"))
313 (should (string-equal
314 (file-remote-p "/method:host#1234:" 'user) "default-user"))
315 (should (string-equal
316 (file-remote-p "/method:host#1234:" 'host) "host#1234"))
317 (should (string-equal (file-remote-p "/method:host#1234:" 'localname) ""))
318
319 ;; No expansion.
320 (should (string-equal
321 (file-remote-p "/method:user@host#1234:")
322 (format "/%s:%s@%s:" "method" "user" "host#1234")))
323 (should (string-equal
324 (file-remote-p "/method:user@host#1234:" 'method) "method"))
325 (should (string-equal
326 (file-remote-p "/method:user@host#1234:" 'user) "user"))
327 (should (string-equal
328 (file-remote-p "/method:user@host#1234:" 'host) "host#1234"))
329 (should (string-equal
330 (file-remote-p "/method:user@host#1234:" 'localname) ""))
331
332 ;; Expand `tramp-default-method' and `tramp-default-user'.
333 (should (string-equal
334 (file-remote-p "/1.2.3.4:")
335 (format "/%s:%s@%s:" "default-method" "default-user" "1.2.3.4")))
336 (should (string-equal (file-remote-p "/1.2.3.4:" 'method) "default-method"))
337 (should (string-equal (file-remote-p "/1.2.3.4:" 'user) "default-user"))
338 (should (string-equal (file-remote-p "/1.2.3.4:" 'host) "1.2.3.4"))
339 (should (string-equal (file-remote-p "/1.2.3.4:" 'localname) ""))
340
341 ;; Expand `tramp-default-method'.
342 (should (string-equal
343 (file-remote-p "/user@1.2.3.4:")
344 (format "/%s:%s@%s:" "default-method" "user" "1.2.3.4")))
345 (should (string-equal
346 (file-remote-p "/user@1.2.3.4:" 'method) "default-method"))
347 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'user) "user"))
348 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'host) "1.2.3.4"))
349 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'localname) ""))
350
351 ;; Expand `tramp-default-user'.
352 (should (string-equal
353 (file-remote-p "/method:1.2.3.4:")
354 (format "/%s:%s@%s:" "method" "default-user" "1.2.3.4")))
355 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'method) "method"))
356 (should (string-equal
357 (file-remote-p "/method:1.2.3.4:" 'user) "default-user"))
358 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'host) "1.2.3.4"))
359 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'localname) ""))
360
361 ;; No expansion.
362 (should (string-equal
363 (file-remote-p "/method:user@1.2.3.4:")
364 (format "/%s:%s@%s:" "method" "user" "1.2.3.4")))
365 (should (string-equal
366 (file-remote-p "/method:user@1.2.3.4:" 'method) "method"))
367 (should (string-equal (file-remote-p "/method:user@1.2.3.4:" 'user) "user"))
368 (should (string-equal
369 (file-remote-p "/method:user@1.2.3.4:" 'host) "1.2.3.4"))
370 (should (string-equal
371 (file-remote-p "/method:user@1.2.3.4:" 'localname) ""))
372
373 ;; Expand `tramp-default-method', `tramp-default-user' and
374 ;; `tramp-default-host'.
375 (should (string-equal
376 (file-remote-p "/[]:")
377 (format
378 "/%s:%s@%s:" "default-method" "default-user" "default-host")))
379 (should (string-equal (file-remote-p "/[]:" 'method) "default-method"))
380 (should (string-equal (file-remote-p "/[]:" 'user) "default-user"))
381 (should (string-equal (file-remote-p "/[]:" 'host) "default-host"))
382 (should (string-equal (file-remote-p "/[]:" 'localname) ""))
383
384 ;; Expand `tramp-default-method' and `tramp-default-user'.
385 (let ((tramp-default-host "::1"))
386 (should (string-equal
387 (file-remote-p "/[]:")
388 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
389 (should (string-equal (file-remote-p "/[]:" 'method) "default-method"))
390 (should (string-equal (file-remote-p "/[]:" 'user) "default-user"))
391 (should (string-equal (file-remote-p "/[]:" 'host) "::1"))
392 (should (string-equal (file-remote-p "/[]:" 'localname) "")))
393
394 ;; Expand `tramp-default-method' and `tramp-default-user'.
395 (should (string-equal
396 (file-remote-p "/[::1]:")
397 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
398 (should (string-equal (file-remote-p "/[::1]:" 'method) "default-method"))
399 (should (string-equal (file-remote-p "/[::1]:" 'user) "default-user"))
400 (should (string-equal (file-remote-p "/[::1]:" 'host) "::1"))
401 (should (string-equal (file-remote-p "/[::1]:" 'localname) ""))
402
403 ;; Expand `tramp-default-method'.
404 (should (string-equal
405 (file-remote-p "/user@[::1]:")
406 (format "/%s:%s@%s:" "default-method" "user" "[::1]")))
407 (should (string-equal
408 (file-remote-p "/user@[::1]:" 'method) "default-method"))
409 (should (string-equal (file-remote-p "/user@[::1]:" 'user) "user"))
410 (should (string-equal (file-remote-p "/user@[::1]:" 'host) "::1"))
411 (should (string-equal (file-remote-p "/user@[::1]:" 'localname) ""))
412
413 ;; Expand `tramp-default-user'.
414 (should (string-equal
415 (file-remote-p "/method:[::1]:")
416 (format "/%s:%s@%s:" "method" "default-user" "[::1]")))
417 (should (string-equal (file-remote-p "/method:[::1]:" 'method) "method"))
418 (should (string-equal
419 (file-remote-p "/method:[::1]:" 'user) "default-user"))
420 (should (string-equal (file-remote-p "/method:[::1]:" 'host) "::1"))
421 (should (string-equal (file-remote-p "/method:[::1]:" 'localname) ""))
422
423 ;; No expansion.
424 (should (string-equal
425 (file-remote-p "/method:user@[::1]:")
426 (format "/%s:%s@%s:" "method" "user" "[::1]")))
427 (should (string-equal
428 (file-remote-p "/method:user@[::1]:" 'method) "method"))
429 (should (string-equal (file-remote-p "/method:user@[::1]:" 'user) "user"))
430 (should (string-equal (file-remote-p "/method:user@[::1]:" 'host) "::1"))
431 (should (string-equal
432 (file-remote-p "/method:user@[::1]:" 'localname) ""))
433
434 ;; Local file name part.
435 (should (string-equal (file-remote-p "/host:/:" 'localname) "/:"))
436 (should (string-equal (file-remote-p "/method:::" 'localname) ":"))
437 (should (string-equal (file-remote-p "/method:: " 'localname) " "))
438 (should (string-equal (file-remote-p "/method::file" 'localname) "file"))
439 (should (string-equal
440 (file-remote-p "/method::/path/to/file" 'localname)
441 "/path/to/file"))
442
443 ;; Multihop.
444 (should
445 (string-equal
446 (file-remote-p "/method1:user1@host1|method2:user2@host2:/path/to/file")
447 (format "/%s:%s@%s:" "method2" "user2" "host2")))
448 (should
449 (string-equal
450 (file-remote-p
451 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'method)
452 "method2"))
453 (should
454 (string-equal
455 (file-remote-p
456 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'user)
457 "user2"))
458 (should
459 (string-equal
460 (file-remote-p
461 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'host)
462 "host2"))
463 (should
464 (string-equal
465 (file-remote-p
466 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'localname)
467 "/path/to/file"))
468
469 (should
470 (string-equal
471 (file-remote-p
472 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file")
473 (format "/%s:%s@%s:" "method3" "user3" "host3")))
474 (should
475 (string-equal
476 (file-remote-p
477 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
478 'method)
479 "method3"))
480 (should
481 (string-equal
482 (file-remote-p
483 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
484 'user)
485 "user3"))
486 (should
487 (string-equal
488 (file-remote-p
489 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
490 'host)
491 "host3"))
492 (should
493 (string-equal
494 (file-remote-p
495 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
496 'localname)
497 "/path/to/file"))))
498
499 (ert-deftest tramp-test03-file-name-defaults ()
500 "Check default values for some methods."
501 ;; Default values in tramp-adb.el.
502 (should (string-equal (file-remote-p "/adb::" 'host) ""))
503 ;; Default values in tramp-ftp.el.
504 (should (string-equal (file-remote-p "/ftp.host:" 'method) "ftp"))
505 (dolist (u '("ftp" "anonymous"))
506 (should (string-equal (file-remote-p (format "/%s@:" u) 'method) "ftp")))
507 ;; Default values in tramp-gvfs.el.
508 (when (and (load "tramp-gvfs" 'noerror 'nomessage)
509 (symbol-value 'tramp-gvfs-enabled))
510 (should (string-equal (file-remote-p "/synce::" 'user) nil)))
511 ;; Default values in tramp-gw.el.
512 (dolist (m '("tunnel" "socks"))
513 (should
514 (string-equal (file-remote-p (format "/%s::" m) 'user) (user-login-name))))
515 ;; Default values in tramp-sh.el.
516 (dolist (h `("127.0.0.1" "[::1]" "localhost" "localhost6" ,(system-name)))
517 (should (string-equal (file-remote-p (format "/root@%s:" h) 'method) "su")))
518 (dolist (m '("su" "sudo" "ksu"))
519 (should (string-equal (file-remote-p (format "/%s::" m) 'user) "root")))
520 (dolist (m '("rcp" "remcp" "rsh" "telnet" "krlogin" "fcp"))
521 (should
522 (string-equal (file-remote-p (format "/%s::" m) 'user) (user-login-name))))
523 ;; Default values in tramp-smb.el.
524 (should (string-equal (file-remote-p "/user%domain@host:" 'method) "smb"))
525 (should (string-equal (file-remote-p "/smb::" 'user) nil)))
526
527 (ert-deftest tramp-test04-substitute-in-file-name ()
528 "Check `substitute-in-file-name'."
529 (should (string-equal (substitute-in-file-name "/method:host://foo") "/foo"))
530 (should
531 (string-equal
532 (substitute-in-file-name "/method:host:/path//foo") "/method:host:/foo"))
533 (should
534 (string-equal (substitute-in-file-name "/method:host:/path///foo") "/foo"))
535 (should
536 (string-equal
537 (substitute-in-file-name "/method:host:/path/~/foo") "/method:host:~/foo"))
538 (should
539 (string-equal (substitute-in-file-name "/method:host:/path//~/foo") "~/foo"))
540 (let (process-environment)
541 (should
542 (string-equal
543 (substitute-in-file-name "/method:host:/path/$FOO")
544 "/method:host:/path/$FOO"))
545 (setenv "FOO" "bla")
546 (should
547 (string-equal
548 (substitute-in-file-name "/method:host:/path/$FOO")
549 "/method:host:/path/bla"))
550 (should
551 (string-equal
552 (substitute-in-file-name "/method:host:/path/$$FOO")
553 "/method:host:/path/$FOO"))))
554
555 (ert-deftest tramp-test05-expand-file-name ()
556 "Check `expand-file-name'."
557 (should
558 (string-equal
559 (expand-file-name "/method:host:/path/./file") "/method:host:/path/file"))
560 (should
561 (string-equal
562 (expand-file-name "/method:host:/path/../file") "/method:host:/file")))
563
564 (ert-deftest tramp-test06-directory-file-name ()
565 "Check `directory-file-name'.
566 This checks also `file-name-as-directory', `file-name-directory'
567 and `file-name-nondirectory'."
568 (should
569 (string-equal
570 (directory-file-name "/method:host:/path/to/file")
571 "/method:host:/path/to/file"))
572 (should
573 (string-equal
574 (directory-file-name "/method:host:/path/to/file/")
575 "/method:host:/path/to/file"))
576 (should
577 (string-equal
578 (file-name-as-directory "/method:host:/path/to/file")
579 "/method:host:/path/to/file/"))
580 (should
581 (string-equal
582 (file-name-as-directory "/method:host:/path/to/file/")
583 "/method:host:/path/to/file/"))
584 (should
585 (string-equal
586 (file-name-directory "/method:host:/path/to/file")
587 "/method:host:/path/to/"))
588 (should
589 (string-equal
590 (file-name-directory "/method:host:/path/to/file/")
591 "/method:host:/path/to/file/"))
592 (should
593 (string-equal (file-name-nondirectory "/method:host:/path/to/file") "file"))
594 (should
595 (string-equal (file-name-nondirectory "/method:host:/path/to/file/") ""))
596 (should-not
597 (file-remote-p
598 (unhandled-file-name-directory "/method:host:/path/to/file"))))
599
600 (ert-deftest tramp-test07-file-exists-p ()
601 "Check `file-exist-p', `write-region' and `delete-file'."
602 (skip-unless (tramp--test-enabled))
603
604 (let ((tmp-name (tramp--test-make-temp-name)))
605 (should-not (file-exists-p tmp-name))
606 (write-region "foo" nil tmp-name)
607 (should (file-exists-p tmp-name))
608 (delete-file tmp-name)
609 (should-not (file-exists-p tmp-name))))
610
611 (ert-deftest tramp-test08-file-local-copy ()
612 "Check `file-local-copy'."
613 (skip-unless (tramp--test-enabled))
614
615 (let ((tmp-name1 (tramp--test-make-temp-name))
616 tmp-name2)
617 (unwind-protect
618 (progn
619 (write-region "foo" nil tmp-name1)
620 (should (setq tmp-name2 (file-local-copy tmp-name1)))
621 (with-temp-buffer
622 (insert-file-contents tmp-name2)
623 (should (string-equal (buffer-string) "foo"))))
624 (ignore-errors
625 (delete-file tmp-name1)
626 (delete-file tmp-name2)))))
627
628 (ert-deftest tramp-test09-insert-file-contents ()
629 "Check `insert-file-contents'."
630 (skip-unless (tramp--test-enabled))
631
632 (let ((tmp-name (tramp--test-make-temp-name)))
633 (unwind-protect
634 (progn
635 (write-region "foo" nil tmp-name)
636 (with-temp-buffer
637 (insert-file-contents tmp-name)
638 (should (string-equal (buffer-string) "foo"))
639 (insert-file-contents tmp-name)
640 (should (string-equal (buffer-string) "foofoo"))
641 ;; Insert partly.
642 (insert-file-contents tmp-name nil 1 3)
643 (should (string-equal (buffer-string) "oofoofoo"))
644 ;; Replace.
645 (insert-file-contents tmp-name nil nil nil 'replace)
646 (should (string-equal (buffer-string) "foo"))))
647 (ignore-errors (delete-file tmp-name)))))
648
649 (ert-deftest tramp-test10-write-region ()
650 "Check `write-region'."
651 (skip-unless (tramp--test-enabled))
652
653 (let ((tmp-name (tramp--test-make-temp-name)))
654 (unwind-protect
655 (progn
656 (with-temp-buffer
657 (insert "foo")
658 (write-region nil nil tmp-name))
659 (with-temp-buffer
660 (insert-file-contents tmp-name)
661 (should (string-equal (buffer-string) "foo")))
662 ;; Append.
663 (with-temp-buffer
664 (insert "bla")
665 (write-region nil nil tmp-name 'append))
666 (with-temp-buffer
667 (insert-file-contents tmp-name)
668 (should (string-equal (buffer-string) "foobla")))
669 ;; Write string.
670 (write-region "foo" nil tmp-name)
671 (with-temp-buffer
672 (insert-file-contents tmp-name)
673 (should (string-equal (buffer-string) "foo")))
674 ;; Write partly.
675 (with-temp-buffer
676 (insert "123456789")
677 (write-region 3 5 tmp-name))
678 (with-temp-buffer
679 (insert-file-contents tmp-name)
680 (should (string-equal (buffer-string) "34"))))
681 (ignore-errors (delete-file tmp-name)))))
682
683 (ert-deftest tramp-test11-copy-file ()
684 "Check `copy-file'."
685 (skip-unless (tramp--test-enabled))
686
687 (let ((tmp-name1 (tramp--test-make-temp-name))
688 (tmp-name2 (tramp--test-make-temp-name))
689 (tmp-name3 (tramp--test-make-temp-name))
690 (tmp-name4 (tramp--test-make-temp-name 'local))
691 (tmp-name5 (tramp--test-make-temp-name 'local)))
692
693 ;; Copy on remote side.
694 (unwind-protect
695 (progn
696 (write-region "foo" nil tmp-name1)
697 (copy-file tmp-name1 tmp-name2)
698 (should (file-exists-p tmp-name2))
699 (with-temp-buffer
700 (insert-file-contents tmp-name2)
701 (should (string-equal (buffer-string) "foo")))
702 (should-error (copy-file tmp-name1 tmp-name2))
703 (copy-file tmp-name1 tmp-name2 'ok)
704 (make-directory tmp-name3)
705 (copy-file tmp-name1 tmp-name3)
706 (should
707 (file-exists-p
708 (expand-file-name (file-name-nondirectory tmp-name1) tmp-name3))))
709 (ignore-errors (delete-file tmp-name1))
710 (ignore-errors (delete-file tmp-name2))
711 (ignore-errors (delete-directory tmp-name3 'recursive)))
712
713 ;; Copy from remote side to local side.
714 (unwind-protect
715 (progn
716 (write-region "foo" nil tmp-name1)
717 (copy-file tmp-name1 tmp-name4)
718 (should (file-exists-p tmp-name4))
719 (with-temp-buffer
720 (insert-file-contents tmp-name4)
721 (should (string-equal (buffer-string) "foo")))
722 (should-error (copy-file tmp-name1 tmp-name4))
723 (copy-file tmp-name1 tmp-name4 'ok)
724 (make-directory tmp-name5)
725 (copy-file tmp-name1 tmp-name5)
726 (should
727 (file-exists-p
728 (expand-file-name (file-name-nondirectory tmp-name1) tmp-name5))))
729 (ignore-errors (delete-file tmp-name1))
730 (ignore-errors (delete-file tmp-name4))
731 (ignore-errors (delete-directory tmp-name5 'recursive)))
732
733 ;; Copy from local side to remote side.
734 (unwind-protect
735 (progn
736 (write-region "foo" nil tmp-name4 nil 'nomessage)
737 (copy-file tmp-name4 tmp-name1)
738 (should (file-exists-p tmp-name1))
739 (with-temp-buffer
740 (insert-file-contents tmp-name1)
741 (should (string-equal (buffer-string) "foo")))
742 (should-error (copy-file tmp-name4 tmp-name1))
743 (copy-file tmp-name4 tmp-name1 'ok)
744 (make-directory tmp-name3)
745 (copy-file tmp-name4 tmp-name3)
746 (should
747 (file-exists-p
748 (expand-file-name (file-name-nondirectory tmp-name4) tmp-name3))))
749 (ignore-errors (delete-file tmp-name1))
750 (ignore-errors (delete-file tmp-name4))
751 (ignore-errors (delete-directory tmp-name3 'recursive)))))
752
753 (ert-deftest tramp-test12-rename-file ()
754 "Check `rename-file'."
755 (skip-unless (tramp--test-enabled))
756
757 (let ((tmp-name1 (tramp--test-make-temp-name))
758 (tmp-name2 (tramp--test-make-temp-name))
759 (tmp-name3 (tramp--test-make-temp-name))
760 (tmp-name4 (tramp--test-make-temp-name 'local))
761 (tmp-name5 (tramp--test-make-temp-name 'local)))
762
763 ;; Rename on remote side.
764 (unwind-protect
765 (progn
766 (write-region "foo" nil tmp-name1)
767 (rename-file tmp-name1 tmp-name2)
768 (should-not (file-exists-p tmp-name1))
769 (should (file-exists-p tmp-name2))
770 (with-temp-buffer
771 (insert-file-contents tmp-name2)
772 (should (string-equal (buffer-string) "foo")))
773 (write-region "foo" nil tmp-name1)
774 (should-error (rename-file tmp-name1 tmp-name2))
775 (rename-file tmp-name1 tmp-name2 'ok)
776 (should-not (file-exists-p tmp-name1))
777 (write-region "foo" nil tmp-name1)
778 (make-directory tmp-name3)
779 (rename-file tmp-name1 tmp-name3)
780 (should-not (file-exists-p tmp-name1))
781 (should
782 (file-exists-p
783 (expand-file-name (file-name-nondirectory tmp-name1) tmp-name3))))
784 (ignore-errors (delete-file tmp-name1))
785 (ignore-errors (delete-file tmp-name2))
786 (ignore-errors (delete-directory tmp-name3 'recursive)))
787
788 ;; Rename from remote side to local side.
789 (unwind-protect
790 (progn
791 (write-region "foo" nil tmp-name1)
792 (rename-file tmp-name1 tmp-name4)
793 (should-not (file-exists-p tmp-name1))
794 (should (file-exists-p tmp-name4))
795 (with-temp-buffer
796 (insert-file-contents tmp-name4)
797 (should (string-equal (buffer-string) "foo")))
798 (write-region "foo" nil tmp-name1)
799 (should-error (rename-file tmp-name1 tmp-name4))
800 (rename-file tmp-name1 tmp-name4 'ok)
801 (should-not (file-exists-p tmp-name1))
802 (write-region "foo" nil tmp-name1)
803 (make-directory tmp-name5)
804 (rename-file tmp-name1 tmp-name5)
805 (should-not (file-exists-p tmp-name1))
806 (should
807 (file-exists-p
808 (expand-file-name (file-name-nondirectory tmp-name1) tmp-name5))))
809 (ignore-errors (delete-file tmp-name1))
810 (ignore-errors (delete-file tmp-name4))
811 (ignore-errors (delete-directory tmp-name5 'recursive)))
812
813 ;; Rename from local side to remote side.
814 (unwind-protect
815 (progn
816 (write-region "foo" nil tmp-name4 nil 'nomessage)
817 (rename-file tmp-name4 tmp-name1)
818 (should-not (file-exists-p tmp-name4))
819 (should (file-exists-p tmp-name1))
820 (with-temp-buffer
821 (insert-file-contents tmp-name1)
822 (should (string-equal (buffer-string) "foo")))
823 (write-region "foo" nil tmp-name4 nil 'nomessage)
824 (should-error (rename-file tmp-name4 tmp-name1))
825 (rename-file tmp-name4 tmp-name1 'ok)
826 (should-not (file-exists-p tmp-name4))
827 (write-region "foo" nil tmp-name4 nil 'nomessage)
828 (make-directory tmp-name3)
829 (rename-file tmp-name4 tmp-name3)
830 (should-not (file-exists-p tmp-name4))
831 (should
832 (file-exists-p
833 (expand-file-name (file-name-nondirectory tmp-name4) tmp-name3))))
834 (ignore-errors (delete-file tmp-name1))
835 (ignore-errors (delete-file tmp-name4))
836 (ignore-errors (delete-directory tmp-name3 'recursive)))))
837
838 (ert-deftest tramp-test13-make-directory ()
839 "Check `make-directory'.
840 This tests also `file-directory-p' and `file-accessible-directory-p'."
841 (skip-unless (tramp--test-enabled))
842
843 (let ((tmp-name (tramp--test-make-temp-name)))
844 (unwind-protect
845 (progn
846 (make-directory tmp-name)
847 (should (file-directory-p tmp-name))
848 (should (file-accessible-directory-p tmp-name)))
849 (ignore-errors (delete-directory tmp-name)))))
850
851 (ert-deftest tramp-test14-delete-directory ()
852 "Check `delete-directory'."
853 (skip-unless (tramp--test-enabled))
854
855 (let ((tmp-name (tramp--test-make-temp-name)))
856 ;; Delete empty directory.
857 (make-directory tmp-name)
858 (should (file-directory-p tmp-name))
859 (delete-directory tmp-name)
860 (should-not (file-directory-p tmp-name))
861 ;; Delete non-empty directory.
862 (make-directory tmp-name)
863 (write-region "foo" nil (expand-file-name "bla" tmp-name))
864 (should-error (delete-directory tmp-name) :type 'file-error)
865 (delete-directory tmp-name 'recursive)
866 (should-not (file-directory-p tmp-name))))
867
868 (ert-deftest tramp-test15-copy-directory ()
869 "Check `copy-directory'."
870 (skip-unless (tramp--test-enabled))
871
872 (let* ((tmp-name1 (tramp--test-make-temp-name))
873 (tmp-name2 (tramp--test-make-temp-name))
874 (tmp-name3 (expand-file-name
875 (file-name-nondirectory tmp-name1) tmp-name2))
876 (tmp-name4 (expand-file-name "foo" tmp-name1))
877 (tmp-name5 (expand-file-name "foo" tmp-name2))
878 (tmp-name6 (expand-file-name "foo" tmp-name3)))
879 (unwind-protect
880 (progn
881 ;; Copy empty directory.
882 (make-directory tmp-name1)
883 (write-region "foo" nil tmp-name4)
884 (should (file-directory-p tmp-name1))
885 (should (file-exists-p tmp-name4))
886 (copy-directory tmp-name1 tmp-name2)
887 (should (file-directory-p tmp-name2))
888 (should (file-exists-p tmp-name5))
889 ;; Target directory does exist already.
890 (copy-directory tmp-name1 tmp-name2)
891 (should (file-directory-p tmp-name3))
892 (should (file-exists-p tmp-name6)))
893 (ignore-errors
894 (delete-directory tmp-name1 'recursive)
895 (delete-directory tmp-name2 'recursive)))))
896
897 (ert-deftest tramp-test16-directory-files ()
898 "Check `directory-files'."
899 (skip-unless (tramp--test-enabled))
900
901 (let* ((tmp-name1 (tramp--test-make-temp-name))
902 (tmp-name2 (expand-file-name "bla" tmp-name1))
903 (tmp-name3 (expand-file-name "foo" tmp-name1)))
904 (unwind-protect
905 (progn
906 (make-directory tmp-name1)
907 (write-region "foo" nil tmp-name2)
908 (write-region "bla" nil tmp-name3)
909 (should (file-directory-p tmp-name1))
910 (should (file-exists-p tmp-name2))
911 (should (file-exists-p tmp-name3))
912 (should (equal (directory-files tmp-name1) '("." ".." "bla" "foo")))
913 (should (equal (directory-files tmp-name1 'full)
914 `(,(concat tmp-name1 "/.")
915 ,(concat tmp-name1 "/..")
916 ,tmp-name2 ,tmp-name3)))
917 (should (equal (directory-files
918 tmp-name1 nil directory-files-no-dot-files-regexp)
919 '("bla" "foo")))
920 (should (equal (directory-files
921 tmp-name1 'full directory-files-no-dot-files-regexp)
922 `(,tmp-name2 ,tmp-name3))))
923 (ignore-errors (delete-directory tmp-name1 'recursive)))))
924
925 (ert-deftest tramp-test17-insert-directory ()
926 "Check `insert-directory'."
927 (skip-unless (tramp--test-enabled))
928
929 (let* ((tmp-name1 (tramp--test-make-temp-name))
930 (tmp-name2 (expand-file-name "foo" tmp-name1)))
931 (unwind-protect
932 (progn
933 (make-directory tmp-name1)
934 (write-region "foo" nil tmp-name2)
935 (should (file-directory-p tmp-name1))
936 (should (file-exists-p tmp-name2))
937 (with-temp-buffer
938 (insert-directory tmp-name1 nil)
939 (goto-char (point-min))
940 (should (looking-at-p (regexp-quote tmp-name1))))
941 (with-temp-buffer
942 (insert-directory tmp-name1 "-al")
943 (goto-char (point-min))
944 (should (looking-at-p (format "^.+ %s$" (regexp-quote tmp-name1)))))
945 (with-temp-buffer
946 (insert-directory (file-name-as-directory tmp-name1) "-al")
947 (goto-char (point-min))
948 (should
949 (looking-at-p (format "^.+ %s/$" (regexp-quote tmp-name1)))))
950 (with-temp-buffer
951 (insert-directory
952 (file-name-as-directory tmp-name1) "-al" nil 'full-directory-p)
953 (goto-char (point-min))
954 (should
955 (looking-at-p
956 "\\(total.+[[:digit:]]+\n\\)?.+ \\.\n.+ \\.\\.\n.+ foo$"))))
957 (ignore-errors (delete-directory tmp-name1 'recursive)))))
958
959 (ert-deftest tramp-test18-file-attributes ()
960 "Check `file-attributes'.
961 This tests also `file-readable-p' and `file-regular-p'."
962 (skip-unless (tramp--test-enabled))
963
964 (let ((tmp-name (tramp--test-make-temp-name))
965 attr)
966 (unwind-protect
967 (progn
968 (write-region "foo" nil tmp-name)
969 (should (file-exists-p tmp-name))
970 (setq attr (file-attributes tmp-name))
971 (should (consp attr))
972 (should (file-exists-p tmp-name))
973 (should (file-readable-p tmp-name))
974 (should (file-regular-p tmp-name))
975 ;; We do not test inodes and device numbers.
976 (should (null (car attr)))
977 (should (numberp (nth 1 attr))) ;; Link.
978 (should (numberp (nth 2 attr))) ;; Uid.
979 (should (numberp (nth 3 attr))) ;; Gid.
980 ;; Last access time.
981 (should (stringp (current-time-string (nth 4 attr))))
982 ;; Last modification time.
983 (should (stringp (current-time-string (nth 5 attr))))
984 ;; Last status change time.
985 (should (stringp (current-time-string (nth 6 attr))))
986 (should (numberp (nth 7 attr))) ;; Size.
987 (should (stringp (nth 8 attr))) ;; Modes.
988
989 (setq attr (file-attributes tmp-name 'string))
990 (should (stringp (nth 2 attr))) ;; Uid.
991 (should (stringp (nth 3 attr))) ;; Gid.
992 (delete-file tmp-name)
993
994 (make-directory tmp-name)
995 (should (file-exists-p tmp-name))
996 (should (file-readable-p tmp-name))
997 (should-not (file-regular-p tmp-name))
998 (setq attr (file-attributes tmp-name))
999 (should (eq (car attr) t)))
1000 (ignore-errors (delete-directory tmp-name)))))
1001
1002 (ert-deftest tramp-test19-directory-files-and-attributes ()
1003 "Check `directory-files-and-attributes'."
1004 (skip-unless (tramp--test-enabled))
1005
1006 ;; `directory-files-and-attributes' contains also values for "../".
1007 ;; Ensure that this doesn't change during tests, for
1008 ;; example due to handling temporary files.
1009 (let* ((tmp-name1 (tramp--test-make-temp-name))
1010 (tmp-name2 (expand-file-name "bla" tmp-name1))
1011 attr)
1012 (unwind-protect
1013 (progn
1014 (make-directory tmp-name1)
1015 (should (file-directory-p tmp-name1))
1016 (make-directory tmp-name2)
1017 (should (file-directory-p tmp-name2))
1018 (write-region "foo" nil (expand-file-name "foo" tmp-name2))
1019 (write-region "bar" nil (expand-file-name "bar" tmp-name2))
1020 (write-region "boz" nil (expand-file-name "boz" tmp-name2))
1021 (setq attr (directory-files-and-attributes tmp-name2))
1022 (should (consp attr))
1023 ;; Dumb remote shells without perl(1) or stat(1) are not
1024 ;; able to return the date correctly. They say "don't know".
1025 (dolist (elt attr)
1026 (unless
1027 (equal
1028 (nth 5
1029 (file-attributes (expand-file-name (car elt) tmp-name2)))
1030 '(0 0))
1031 (should
1032 (equal (file-attributes (expand-file-name (car elt) tmp-name2))
1033 (cdr elt)))))
1034 (setq attr (directory-files-and-attributes tmp-name2 'full))
1035 (dolist (elt attr)
1036 (unless (equal (nth 5 (file-attributes (car elt))) '(0 0))
1037 (should
1038 (equal (file-attributes (car elt)) (cdr elt)))))
1039 (setq attr (directory-files-and-attributes tmp-name2 nil "^b"))
1040 (should (equal (mapcar 'car attr) '("bar" "boz"))))
1041 (ignore-errors (delete-directory tmp-name1 'recursive)))))
1042
1043 (ert-deftest tramp-test20-file-modes ()
1044 "Check `file-modes'.
1045 This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
1046 (skip-unless (tramp--test-enabled))
1047 (skip-unless
1048 (not
1049 (memq
1050 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1051 '(tramp-adb-file-name-handler
1052 tramp-gvfs-file-name-handler
1053 tramp-smb-file-name-handler))))
1054
1055 (let ((tmp-name (tramp--test-make-temp-name)))
1056 (unwind-protect
1057 (progn
1058 (write-region "foo" nil tmp-name)
1059 (should (file-exists-p tmp-name))
1060 (set-file-modes tmp-name #o777)
1061 (should (= (file-modes tmp-name) #o777))
1062 (should (file-executable-p tmp-name))
1063 (should (file-writable-p tmp-name))
1064 (set-file-modes tmp-name #o444)
1065 (should (= (file-modes tmp-name) #o444))
1066 (should-not (file-executable-p tmp-name))
1067 ;; A file is always writable for user "root".
1068 (unless (zerop (nth 2 (file-attributes tmp-name)))
1069 (should-not (file-writable-p tmp-name))))
1070 (ignore-errors (delete-file tmp-name)))))
1071
1072 (ert-deftest tramp-test21-file-links ()
1073 "Check `file-symlink-p'.
1074 This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
1075 (skip-unless (tramp--test-enabled))
1076
1077 (let ((tmp-name1 (tramp--test-make-temp-name))
1078 (tmp-name2 (tramp--test-make-temp-name))
1079 (tmp-name3 (tramp--test-make-temp-name 'local)))
1080 (unwind-protect
1081 (progn
1082 (write-region "foo" nil tmp-name1)
1083 (should (file-exists-p tmp-name1))
1084 ;; Method "smb" supports `make-symbolic-link' only if the
1085 ;; remote host has CIFS capabilities. tramp-adb.el and
1086 ;; tramp-gvfs.el do not support symbolic links at all.
1087 (condition-case err
1088 (make-symbolic-link tmp-name1 tmp-name2)
1089 (file-error
1090 (skip-unless
1091 (not (string-equal (error-message-string err)
1092 "make-symbolic-link not supported")))))
1093 (should (file-symlink-p tmp-name2))
1094 (should-error (make-symbolic-link tmp-name1 tmp-name2))
1095 (make-symbolic-link tmp-name1 tmp-name2 'ok-if-already-exists)
1096 (should (file-symlink-p tmp-name2))
1097 ;; `tmp-name3' is a local file name.
1098 (should-error (make-symbolic-link tmp-name1 tmp-name3)))
1099 (ignore-errors
1100 (delete-file tmp-name1)
1101 (delete-file tmp-name2)))
1102
1103 (unwind-protect
1104 (progn
1105 (write-region "foo" nil tmp-name1)
1106 (should (file-exists-p tmp-name1))
1107 (add-name-to-file tmp-name1 tmp-name2)
1108 (should-not (file-symlink-p tmp-name2))
1109 (should-error (add-name-to-file tmp-name1 tmp-name2))
1110 (add-name-to-file tmp-name1 tmp-name2 'ok-if-already-exists)
1111 (should-not (file-symlink-p tmp-name2))
1112 ;; `tmp-name3' is a local file name.
1113 (should-error (add-name-to-file tmp-name1 tmp-name3)))
1114 (ignore-errors
1115 (delete-file tmp-name1)
1116 (delete-file tmp-name2)))
1117
1118 (unwind-protect
1119 (progn
1120 (write-region "foo" nil tmp-name1)
1121 (should (file-exists-p tmp-name1))
1122 (make-symbolic-link tmp-name1 tmp-name2)
1123 (should (file-symlink-p tmp-name2))
1124 (should-not (string-equal tmp-name2 (file-truename tmp-name2)))
1125 (should
1126 (string-equal (file-truename tmp-name1) (file-truename tmp-name2)))
1127 (should (file-equal-p tmp-name1 tmp-name2)))
1128 (ignore-errors
1129 (delete-file tmp-name1)
1130 (delete-file tmp-name2)))
1131
1132 ;; `file-truename' shall preserve trailing link of directories.
1133 (unless (file-symlink-p tramp-test-temporary-file-directory)
1134 (let* ((dir1 (directory-file-name tramp-test-temporary-file-directory))
1135 (dir2 (file-name-as-directory dir1)))
1136 (should (string-equal (file-truename dir1) (expand-file-name dir1)))
1137 (should (string-equal (file-truename dir2) (expand-file-name dir2)))))))
1138
1139 (ert-deftest tramp-test22-file-times ()
1140 "Check `set-file-times' and `file-newer-than-file-p'."
1141 (skip-unless (tramp--test-enabled))
1142 (skip-unless
1143 (not
1144 (memq
1145 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1146 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler))))
1147
1148 (let ((tmp-name1 (tramp--test-make-temp-name))
1149 (tmp-name2 (tramp--test-make-temp-name))
1150 (tmp-name3 (tramp--test-make-temp-name)))
1151 (unwind-protect
1152 (progn
1153 (write-region "foo" nil tmp-name1)
1154 (should (file-exists-p tmp-name1))
1155 (should (consp (nth 5 (file-attributes tmp-name1))))
1156 ;; '(0 0) means don't know, and will be replaced by
1157 ;; `current-time'. Therefore, we use '(0 1).
1158 ;; We skip the test, if the remote handler is not able to
1159 ;; set the correct time.
1160 (skip-unless (set-file-times tmp-name1 '(0 1)))
1161 ;; Dumb remote shells without perl(1) or stat(1) are not
1162 ;; able to return the date correctly. They say "don't know".
1163 (unless (equal (nth 5 (file-attributes tmp-name1)) '(0 0))
1164 (should (equal (nth 5 (file-attributes tmp-name1)) '(0 1)))
1165 (write-region "bla" nil tmp-name2)
1166 (should (file-exists-p tmp-name2))
1167 (should (file-newer-than-file-p tmp-name2 tmp-name1))
1168 ;; `tmp-name3' does not exist.
1169 (should (file-newer-than-file-p tmp-name2 tmp-name3))
1170 (should-not (file-newer-than-file-p tmp-name3 tmp-name1))))
1171 (ignore-errors
1172 (delete-file tmp-name1)
1173 (delete-file tmp-name2)))))
1174
1175 (ert-deftest tramp-test23-visited-file-modtime ()
1176 "Check `set-visited-file-modtime' and `verify-visited-file-modtime'."
1177 (skip-unless (tramp--test-enabled))
1178
1179 (let ((tmp-name (tramp--test-make-temp-name)))
1180 (unwind-protect
1181 (progn
1182 (write-region "foo" nil tmp-name)
1183 (should (file-exists-p tmp-name))
1184 (with-temp-buffer
1185 (insert-file-contents tmp-name)
1186 (should (verify-visited-file-modtime))
1187 (set-visited-file-modtime '(0 1))
1188 (should (verify-visited-file-modtime))
1189 (should (equal (visited-file-modtime) '(0 1 0 0)))))
1190 (ignore-errors (delete-file tmp-name)))))
1191
1192 (ert-deftest tramp-test24-file-name-completion ()
1193 "Check `file-name-completion' and `file-name-all-completions'."
1194 (skip-unless (tramp--test-enabled))
1195
1196 (let ((tmp-name (tramp--test-make-temp-name)))
1197 (unwind-protect
1198 (progn
1199 (make-directory tmp-name)
1200 (should (file-directory-p tmp-name))
1201 (write-region "foo" nil (expand-file-name "foo" tmp-name))
1202 (write-region "bar" nil (expand-file-name "bold" tmp-name))
1203 (make-directory (expand-file-name "boz" tmp-name))
1204 (should (equal (file-name-completion "fo" tmp-name) "foo"))
1205 (should (equal (file-name-completion "b" tmp-name) "bo"))
1206 (should
1207 (equal (file-name-completion "b" tmp-name 'file-directory-p) "boz/"))
1208 (should (equal (file-name-all-completions "fo" tmp-name) '("foo")))
1209 (should
1210 (equal (sort (file-name-all-completions "b" tmp-name) 'string-lessp)
1211 '("bold" "boz/"))))
1212 (ignore-errors (delete-directory tmp-name 'recursive)))))
1213
1214 (ert-deftest tramp-test25-load ()
1215 "Check `load'."
1216 (skip-unless (tramp--test-enabled))
1217
1218 (let ((tmp-name (tramp--test-make-temp-name)))
1219 (unwind-protect
1220 (progn
1221 (load tmp-name 'noerror 'nomessage)
1222 (should-not (featurep 'tramp-test-load))
1223 (write-region "(provide 'tramp-test-load)" nil tmp-name)
1224 ;; `load' in lread.c does not pass `must-suffix'. Why?
1225 ;(should-error (load tmp-name nil 'nomessage 'nosuffix 'must-suffix))
1226 (load tmp-name nil 'nomessage 'nosuffix)
1227 (should (featurep 'tramp-test-load)))
1228 (ignore-errors
1229 (and (featurep 'tramp-test-load) (unload-feature 'tramp-test-load))
1230 (delete-file tmp-name)))))
1231
1232 (ert-deftest tramp-test26-process-file ()
1233 "Check `process-file'."
1234 (skip-unless (tramp--test-enabled))
1235 (skip-unless
1236 (not
1237 (memq
1238 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1239 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler))))
1240
1241 (let ((tmp-name (tramp--test-make-temp-name))
1242 (default-directory tramp-test-temporary-file-directory)
1243 kill-buffer-query-functions)
1244 (unwind-protect
1245 (progn
1246 ;; We cannot use "/bin/true" and "/bin/false"; those paths
1247 ;; do not exist on hydra.
1248 (should (zerop (process-file "true")))
1249 (should-not (zerop (process-file "false")))
1250 (should-not (zerop (process-file "binary-does-not-exist")))
1251 (with-temp-buffer
1252 (write-region "foo" nil tmp-name)
1253 (should (file-exists-p tmp-name))
1254 (should
1255 (zerop
1256 (process-file "ls" nil t nil (file-name-nondirectory tmp-name))))
1257 ;; `ls' could produce colorized output.
1258 (goto-char (point-min))
1259 (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
1260 (replace-match "" nil nil))
1261 (should
1262 (string-equal
1263 (format "%s\n" (file-name-nondirectory tmp-name))
1264 (buffer-string)))))
1265 (ignore-errors (delete-file tmp-name)))))
1266
1267 (ert-deftest tramp-test27-start-file-process ()
1268 "Check `start-file-process'."
1269 (skip-unless (tramp--test-enabled))
1270 (skip-unless
1271 (not
1272 (memq
1273 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1274 '(tramp-adb-file-name-handler
1275 tramp-gvfs-file-name-handler
1276 tramp-smb-file-name-handler))))
1277
1278 (let ((default-directory tramp-test-temporary-file-directory)
1279 (tmp-name (tramp--test-make-temp-name))
1280 kill-buffer-query-functions proc)
1281 (unwind-protect
1282 (with-temp-buffer
1283 (setq proc (start-file-process "test1" (current-buffer) "cat"))
1284 (should (processp proc))
1285 (should (equal (process-status proc) 'run))
1286 (process-send-string proc "foo")
1287 (process-send-eof proc)
1288 (accept-process-output proc 1)
1289 (should (string-equal (buffer-string) "foo")))
1290 (ignore-errors (delete-process proc)))
1291
1292 (unwind-protect
1293 (with-temp-buffer
1294 (write-region "foo" nil tmp-name)
1295 (should (file-exists-p tmp-name))
1296 (setq proc
1297 (start-file-process
1298 "test2" (current-buffer)
1299 "cat" (file-name-nondirectory tmp-name)))
1300 (should (processp proc))
1301 (accept-process-output proc 1)
1302 (should (string-equal (buffer-string) "foo")))
1303 (ignore-errors
1304 (delete-process proc)
1305 (delete-file tmp-name)))
1306
1307 (unwind-protect
1308 (progn
1309 (setq proc (start-file-process "test3" nil "cat"))
1310 (should (processp proc))
1311 (should (equal (process-status proc) 'run))
1312 (set-process-filter
1313 proc (lambda (_p s) (should (string-equal s "foo"))))
1314 (process-send-string proc "foo")
1315 (process-send-eof proc)
1316 (accept-process-output proc 1))
1317 (ignore-errors (delete-process proc)))))
1318
1319 (ert-deftest tramp-test28-shell-command ()
1320 "Check `shell-command'."
1321 (skip-unless (tramp--test-enabled))
1322 (skip-unless
1323 (not
1324 (memq
1325 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1326 '(tramp-adb-file-name-handler
1327 tramp-gvfs-file-name-handler
1328 tramp-smb-file-name-handler))))
1329
1330 (let ((tmp-name (tramp--test-make-temp-name))
1331 (default-directory tramp-test-temporary-file-directory)
1332 kill-buffer-query-functions)
1333 (unwind-protect
1334 (with-temp-buffer
1335 (write-region "foo" nil tmp-name)
1336 (should (file-exists-p tmp-name))
1337 (shell-command
1338 (format "ls %s" (file-name-nondirectory tmp-name)) (current-buffer))
1339 ;; `ls' could produce colorized output.
1340 (goto-char (point-min))
1341 (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
1342 (replace-match "" nil nil))
1343 (should
1344 (string-equal
1345 (format "%s\n" (file-name-nondirectory tmp-name)) (buffer-string))))
1346 (ignore-errors (delete-file tmp-name)))
1347
1348 (unwind-protect
1349 (with-temp-buffer
1350 (write-region "foo" nil tmp-name)
1351 (should (file-exists-p tmp-name))
1352 (async-shell-command
1353 (format "ls %s" (file-name-nondirectory tmp-name)) (current-buffer))
1354 (accept-process-output (get-buffer-process (current-buffer)) 1)
1355 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
1356 (while
1357 (ignore-errors
1358 (memq (process-status (get-buffer-process (current-buffer)))
1359 '(run open)))
1360 (accept-process-output (get-buffer-process (current-buffer)) 1)))
1361 ;; `ls' could produce colorized output.
1362 (goto-char (point-min))
1363 (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
1364 (replace-match "" nil nil))
1365 (should
1366 (string-equal
1367 (format "%s\n" (file-name-nondirectory tmp-name)) (buffer-string))))
1368 (ignore-errors (delete-file tmp-name)))
1369
1370 (unwind-protect
1371 (with-temp-buffer
1372 (write-region "foo" nil tmp-name)
1373 (should (file-exists-p tmp-name))
1374 (async-shell-command "read line; ls $line" (current-buffer))
1375 (process-send-string
1376 (get-buffer-process (current-buffer))
1377 (format "%s\n" (file-name-nondirectory tmp-name)))
1378 (accept-process-output (get-buffer-process (current-buffer)) 1)
1379 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
1380 (while
1381 (ignore-errors
1382 (memq (process-status (get-buffer-process (current-buffer)))
1383 '(run open)))
1384 (accept-process-output (get-buffer-process (current-buffer)) 1)))
1385 (should
1386 (string-equal
1387 (format "%s\n" (file-name-nondirectory tmp-name)) (buffer-string))))
1388 (ignore-errors (delete-file tmp-name)))))
1389
1390 (ert-deftest tramp-test29-vc-registered ()
1391 "Check `vc-registered'."
1392 (skip-unless (tramp--test-enabled))
1393 (skip-unless
1394 (eq
1395 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1396 'tramp-sh-file-name-handler))
1397
1398 (let* ((default-directory tramp-test-temporary-file-directory)
1399 (tmp-name1 (tramp--test-make-temp-name))
1400 (tmp-name2 (expand-file-name "foo" tmp-name1))
1401 (tramp-remote-process-environment tramp-remote-process-environment)
1402 (vc-handled-backends
1403 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
1404 (cond
1405 ((tramp-find-executable v vc-bzr-program (tramp-get-remote-path v))
1406 (setq tramp-remote-process-environment
1407 (cons (format "BZR_HOME=%s"
1408 (file-remote-p tmp-name1 'localname))
1409 tramp-remote-process-environment))
1410 ;; We must force a reconnect, in order to activate $BZR_HOME.
1411 (tramp-cleanup-connection
1412 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1413 nil 'keep-password)
1414 '(Bzr))
1415 ((tramp-find-executable v vc-git-program (tramp-get-remote-path v))
1416 '(Git))
1417 ((tramp-find-executable v vc-hg-program (tramp-get-remote-path v))
1418 '(Hg))
1419 (t nil)))))
1420 (skip-unless vc-handled-backends)
1421 (message "%s" vc-handled-backends)
1422
1423 (unwind-protect
1424 (progn
1425 (make-directory tmp-name1)
1426 (write-region "foo" nil tmp-name2)
1427 (should (file-directory-p tmp-name1))
1428 (should (file-exists-p tmp-name2))
1429 (should-not (vc-registered tmp-name1))
1430 (should-not (vc-registered tmp-name2))
1431
1432 (let ((default-directory tmp-name1))
1433 ;; Create empty repository, and register the file.
1434 (vc-create-repo (car vc-handled-backends))
1435 ;; The structure of VC-FILESET is not documented. Let's
1436 ;; hope it won't change.
1437 (vc-register
1438 nil (list (car vc-handled-backends)
1439 (list (file-name-nondirectory tmp-name2)))))
1440 (should (vc-registered tmp-name2)))
1441
1442 (ignore-errors (delete-directory tmp-name1 'recursive)))))
1443
1444 (defun tramp--test-check-files (&rest files)
1445 "Runs a simple but comprehensive test over every file in FILES."
1446 (let ((tmp-name1 (tramp--test-make-temp-name))
1447 (tmp-name2 (tramp--test-make-temp-name 'local)))
1448 (unwind-protect
1449 (progn
1450 (make-directory tmp-name1)
1451 (make-directory tmp-name2)
1452 (dolist (elt files)
1453 (let ((file1 (expand-file-name elt tmp-name1))
1454 (file2 (expand-file-name elt tmp-name2)))
1455 (write-region elt nil file1)
1456 (should (file-exists-p file1))
1457 ;; Check file contents.
1458 (with-temp-buffer
1459 (insert-file-contents file1)
1460 (should (string-equal (buffer-string) elt)))
1461 ;; Copy file both directions.
1462 (copy-file file1 tmp-name2)
1463 (should (file-exists-p file2))
1464 (delete-file file1)
1465 (should-not (file-exists-p file1))
1466 (copy-file file2 tmp-name1)
1467 (should (file-exists-p file1))))
1468 ;; Check file names.
1469 (should (equal (directory-files
1470 tmp-name1 nil directory-files-no-dot-files-regexp)
1471 (sort (copy-sequence files) 'string-lessp)))
1472 (should (equal (directory-files
1473 tmp-name2 nil directory-files-no-dot-files-regexp)
1474 (sort files 'string-lessp))))
1475 (ignore-errors (delete-directory tmp-name1 'recursive))
1476 (ignore-errors (delete-directory tmp-name2 'recursive)))))
1477
1478 ;; This test is inspired by Bug#17238.
1479 (ert-deftest tramp-test30-special-characters ()
1480 "Check special characters in file names."
1481 (skip-unless (tramp--test-enabled))
1482
1483 ;; Newlines, slashes and backslashes in file names are not supported.
1484 ;; So we don't test.
1485 (tramp--test-check-files
1486 " foo\tbar baz\t"
1487 "$foo$bar$$baz$"
1488 "-foo-bar-baz-"
1489 "%foo%bar%baz%"
1490 "&foo&bar&baz&"
1491 "?foo?bar?baz?"
1492 "*foo*bar*baz*"
1493 "'foo\"bar'baz\""
1494 "#foo#bar#baz#"
1495 "!foo|bar!baz|"
1496 ":foo;bar:baz;"
1497 "<foo>bar<baz>"
1498 "(foo)bar(baz)"))
1499
1500 (ert-deftest tramp-test31-utf8 ()
1501 "Check UTF8 encoding in file names and file contents."
1502 (skip-unless (tramp--test-enabled))
1503
1504 (let ((coding-system-for-read 'utf-8)
1505 (coding-system-for-write 'utf-8)
1506 (file-name-coding-system 'utf-8))
1507 (tramp--test-check-files
1508 "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت"
1509 "银河系漫游指南系列"
1510 "Автостопом по гала́ктике")))
1511
1512 ;; This test is inspired by Bug#16928.
1513 (ert-deftest tramp-test32-asynchronous-requests ()
1514 "Check parallel asynchronous requests.
1515 Such requests could arrive from timers, process filters and
1516 process sentinels. They shall not disturb each other."
1517 ;; Mark as failed until bug has been fixed.
1518 :expected-result :failed
1519 (skip-unless (tramp--test-enabled))
1520 (skip-unless
1521 (eq
1522 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1523 'tramp-sh-file-name-handler))
1524
1525 ;; Keep instrumentation verbosity 0 until Tramp bug is fixed. This
1526 ;; has the side effect, that this test fails instead to abort. Good
1527 ;; for hydra.
1528 (tramp--instrument-test-case 0
1529 (let* ((tmp-name (tramp--test-make-temp-name))
1530 (default-directory tmp-name)
1531 (remote-file-name-inhibit-cache t)
1532 timer buffers kill-buffer-query-functions)
1533
1534 (unwind-protect
1535 (progn
1536 (make-directory tmp-name)
1537
1538 ;; Setup a timer in order to raise an ordinary command again
1539 ;; and again. `vc-registered' is well suited, because there
1540 ;; are many checks.
1541 (setq
1542 timer
1543 (run-at-time
1544 0 1
1545 (lambda ()
1546 (when buffers
1547 (vc-registered
1548 (buffer-name (nth (random (length buffers)) buffers)))))))
1549
1550 ;; Create temporary buffers. The number of buffers
1551 ;; corresponds to the number of processes; it could be
1552 ;; increased in order to make pressure on Tramp.
1553 (dotimes (i 5)
1554 (add-to-list 'buffers (generate-new-buffer "*temp*")))
1555
1556 ;; Open asynchronous processes. Set process sentinel.
1557 (dolist (buf buffers)
1558 (async-shell-command "read line; touch $line; echo $line" buf)
1559 (set-process-sentinel
1560 (get-buffer-process buf)
1561 (lambda (proc _state)
1562 (delete-file (buffer-name (process-buffer proc))))))
1563
1564 ;; Send a string. Use a random order of the buffers. Mix
1565 ;; with regular operation.
1566 (let ((buffers (copy-sequence buffers))
1567 buf)
1568 (while buffers
1569 (setq buf (nth (random (length buffers)) buffers))
1570 (process-send-string
1571 (get-buffer-process buf) (format "'%s'\n" buf))
1572 (file-attributes (buffer-name buf))
1573 (setq buffers (delq buf buffers))))
1574
1575 ;; Wait until the whole output has been read.
1576 (with-timeout ((* 10 (length buffers))
1577 (ert-fail "`async-shell-command' timed out"))
1578 (let ((buffers (copy-sequence buffers))
1579 buf)
1580 (while buffers
1581 (setq buf (nth (random (length buffers)) buffers))
1582 (if (ignore-errors
1583 (memq (process-status (get-buffer-process buf))
1584 '(run open)))
1585 (accept-process-output (get-buffer-process buf) 0.1)
1586 (setq buffers (delq buf buffers))))))
1587
1588 ;; Check.
1589 (dolist (buf buffers)
1590 (with-current-buffer buf
1591 (should
1592 (string-equal (format "'%s'\n" buf) (buffer-string)))))
1593 (should-not
1594 (directory-files tmp-name nil directory-files-no-dot-files-regexp)))
1595
1596 ;; Cleanup.
1597 (ignore-errors (cancel-timer timer))
1598 (ignore-errors (delete-directory tmp-name 'recursive))
1599 (dolist (buf buffers)
1600 (ignore-errors (kill-buffer buf)))))))
1601
1602 (ert-deftest tramp-test33-recursive-load ()
1603 "Check that Tramp does not fail due to recursive load."
1604 (skip-unless (tramp--test-enabled))
1605
1606 (dolist (code
1607 (list
1608 (format
1609 "(expand-file-name %S)"
1610 tramp-test-temporary-file-directory)
1611 (format
1612 "(let ((default-directory %S)) (expand-file-name %S))"
1613 tramp-test-temporary-file-directory
1614 temporary-file-directory)))
1615 (should-not
1616 (string-match
1617 "Recursive load"
1618 (shell-command-to-string
1619 (format
1620 "%s -batch -Q -L %s --eval %s"
1621 (expand-file-name invocation-name invocation-directory)
1622 (mapconcat 'shell-quote-argument load-path " -L ")
1623 (shell-quote-argument code)))))))
1624
1625 (ert-deftest tramp-test34-unload ()
1626 "Check that Tramp and its subpackages unload completely.
1627 Since it unloads Tramp, it shall be the last test to run."
1628 ;; Mark as failed until all symbols are unbound.
1629 :expected-result (if (featurep 'tramp) :failed :passed)
1630 (when (featurep 'tramp)
1631 (unload-feature 'tramp 'force)
1632 ;; No Tramp feature must be left.
1633 (should-not (featurep 'tramp))
1634 (should-not (all-completions "tramp" (delq 'tramp-tests features)))
1635 ;; `file-name-handler-alist' must be clean.
1636 (should-not (all-completions "tramp" (mapcar 'cdr file-name-handler-alist)))
1637 ;; There shouldn't be left a bound symbol. We do not regard our
1638 ;; test symbols, and the Tramp unload hooks.
1639 (mapatoms
1640 (lambda (x)
1641 (and (or (boundp x) (functionp x))
1642 (string-match "^tramp" (symbol-name x))
1643 (not (string-match "^tramp--?test" (symbol-name x)))
1644 (not (string-match "unload-hook$" (symbol-name x)))
1645 (ert-fail (format "`%s' still bound" x)))))
1646 ; (progn (message "`%s' still bound" x)))))
1647 ;; There shouldn't be left a hook function containing a Tramp
1648 ;; function. We do not regard the Tramp unload hooks.
1649 (mapatoms
1650 (lambda (x)
1651 (and (boundp x)
1652 (string-match "-hooks?$" (symbol-name x))
1653 (not (string-match "unload-hook$" (symbol-name x)))
1654 (consp (symbol-value x))
1655 (ignore-errors (all-completions "tramp" (symbol-value x)))
1656 (ert-fail (format "Hook `%s' still contains Tramp function" x)))))))
1657
1658 ;; TODO:
1659
1660 ;; * dired-compress-file
1661 ;; * dired-uncache
1662 ;; * file-acl
1663 ;; * file-ownership-preserved-p
1664 ;; * file-selinux-context
1665 ;; * find-backup-file-name
1666 ;; * make-auto-save-file-name
1667 ;; * set-file-acl
1668 ;; * set-file-selinux-context
1669
1670 ;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?).
1671 ;; * Fix `tramp-test28-shell-command' on MS Windows (nasty plink message).
1672 ;; * Fix `tramp-test31-utf8' for MS Windows and `nc'/`telnet' (when
1673 ;; target is a dumb busybox). Seems to be in `directory-files'.
1674 ;; * Fix Bug#16928. Set expected error of `tramp-test32-asynchronous-requests'.
1675 ;; * Fix `tramp-test34-unload' (Not all symbols are unbound). Set
1676 ;; expected error.
1677
1678 (defun tramp-test-all (&optional interactive)
1679 "Run all tests for \\[tramp]."
1680 (interactive "p")
1681 (funcall
1682 (if interactive 'ert-run-tests-interactively 'ert-run-tests-batch) "^tramp"))
1683
1684 (provide 'tramp-tests)
1685 ;;; tramp-tests.el ends here