1 ;;; tramp-tests.el --- Tests of remote file access
3 ;; Copyright (C) 2013-2014 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
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.
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.
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/'.
22 ;; The tests require a recent ert.el from Emacs 24.4.
24 ;; Some of the tests require access to a remote host files. Set
25 ;; $REMOTE_TEMPORARY_FILE_DIRECTORY to a suitable value in order
26 ;; to overwrite the default value. If you want to skip tests
27 ;; accessing a remote host, set this environment variable to
28 ;; "/dev/null" or whatever is appropriate on your system.
30 ;; When running the tests in batch mode, it must NOT require an
31 ;; interactive password prompt unless the environment variable
32 ;; $REMOTE_ALLOW_PASSWORD is set.
34 ;; A whole test run can be performed calling the command `tramp-test-all'.
45 (declare-function tramp-find-executable "tramp-sh")
46 (declare-function tramp-get-remote-path "tramp-sh")
48 ;; There is no default value on w32 systems, which could work out of the box.
49 (defconst tramp-test-temporary-file-directory
51 ((getenv "REMOTE_TEMPORARY_FILE_DIRECTORY"))
52 ((eq system-type 'windows-nt) null-device)
53 (t (format "/ssh::%s" temporary-file-directory)))
54 "Temporary directory for Tramp tests.")
56 (setq password-cache-expiry nil
58 tramp-message-show-message nil)
60 ;; Disable interactive passwords in batch mode.
61 (when (and noninteractive (not (getenv "REMOTE_ALLOW_PASSWORD")))
62 (defalias 'tramp-read-passwd 'ignore))
64 ;; This shall happen on hydra only.
65 (when (getenv "NIX_STORE")
66 (add-to-list 'tramp-remote-path 'tramp-own-remote-path))
68 (defvar tramp--test-enabled-checked nil
69 "Cached result of `tramp--test-enabled'.
70 If the function did run, the value is a cons cell, the `cdr'
73 (defun tramp--test-enabled ()
74 "Whether remote file access is enabled."
75 (unless (consp tramp--test-enabled-checked)
77 tramp--test-enabled-checked
81 (file-remote-p tramp-test-temporary-file-directory)
82 (file-directory-p tramp-test-temporary-file-directory)
83 (file-writable-p tramp-test-temporary-file-directory))))))
85 (when (cdr tramp--test-enabled-checked)
86 ;; Cleanup connection. We don't cleanup for adb, because it
87 ;; doesn't behave well when is disconnect several times.
88 (tramp-cleanup-connection
89 (tramp-dissect-file-name tramp-test-temporary-file-directory)
93 (cdr tramp--test-enabled-checked))
95 (defun tramp--test-make-temp-name ()
96 "Create a temporary file name for test."
98 (make-temp-name "tramp-test") tramp-test-temporary-file-directory))
100 (defmacro tramp--instrument-test-case (verbose &rest body)
101 "Run BODY with `tramp-verbose' equal VERBOSE.
102 Print the the content of the Tramp debug buffer, if BODY does not
103 eval properly in `should', `should-not' or `should-error'."
104 (declare (indent 1) (debug (natnump body)))
105 `(let ((tramp-verbose ,verbose)
106 (tramp-debug-on-error t))
110 (signal (car err) (cdr err)))
112 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
113 (with-current-buffer (tramp-get-connection-buffer v)
114 (message "%s" (buffer-string)))
115 (with-current-buffer (tramp-get-debug-buffer v)
116 (message "%s" (buffer-string))))
118 (signal (car err) (cdr err))))))
120 (ert-deftest tramp-test00-availability ()
121 "Test availability of Tramp functions."
122 :expected-result (if (tramp--test-enabled) :passed :failed)
123 (should (ignore-errors
125 (file-remote-p tramp-test-temporary-file-directory)
126 (file-directory-p tramp-test-temporary-file-directory)
127 (file-writable-p tramp-test-temporary-file-directory)))))
129 (ert-deftest tramp-test01-file-name-syntax ()
130 "Check remote file name syntax."
132 (should (tramp-tramp-file-p "/method::"))
133 (should (tramp-tramp-file-p "/host:"))
134 (should (tramp-tramp-file-p "/user@:"))
135 (should (tramp-tramp-file-p "/user@host:"))
136 (should (tramp-tramp-file-p "/method:host:"))
137 (should (tramp-tramp-file-p "/method:user@:"))
138 (should (tramp-tramp-file-p "/method:user@host:"))
139 (should (tramp-tramp-file-p "/method:user@email@host:"))
142 (should (tramp-tramp-file-p "/host#1234:"))
143 (should (tramp-tramp-file-p "/user@host#1234:"))
144 (should (tramp-tramp-file-p "/method:host#1234:"))
145 (should (tramp-tramp-file-p "/method:user@host#1234:"))
147 ;; Using an IPv4 address.
148 (should (tramp-tramp-file-p "/1.2.3.4:"))
149 (should (tramp-tramp-file-p "/user@1.2.3.4:"))
150 (should (tramp-tramp-file-p "/method:1.2.3.4:"))
151 (should (tramp-tramp-file-p "/method:user@1.2.3.4:"))
153 ;; Using an IPv6 address.
154 (should (tramp-tramp-file-p "/[]:"))
155 (should (tramp-tramp-file-p "/[::1]:"))
156 (should (tramp-tramp-file-p "/user@[::1]:"))
157 (should (tramp-tramp-file-p "/method:[::1]:"))
158 (should (tramp-tramp-file-p "/method:user@[::1]:"))
160 ;; Local file name part.
161 (should (tramp-tramp-file-p "/host:/:"))
162 (should (tramp-tramp-file-p "/method:::"))
163 (should (tramp-tramp-file-p "/method::/path/to/file"))
164 (should (tramp-tramp-file-p "/method::file"))
167 (should (tramp-tramp-file-p "/method1:|method2::"))
168 (should (tramp-tramp-file-p "/method1:host1|host2:"))
169 (should (tramp-tramp-file-p "/method1:host1|method2:host2:"))
170 (should (tramp-tramp-file-p "/method1:user1@host1|method2:user2@host2:"))
171 (should (tramp-tramp-file-p
172 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:"))
175 (should-not (tramp-tramp-file-p nil))
176 (should-not (tramp-tramp-file-p 'symbol))
177 ;; "/:" suppresses file name handlers.
178 (should-not (tramp-tramp-file-p "/::"))
179 (should-not (tramp-tramp-file-p "/:@:"))
180 (should-not (tramp-tramp-file-p "/:[]:"))
181 ;; Multihops require a method.
182 (should-not (tramp-tramp-file-p "/host1|host2:"))
183 ;; Methods or hostnames shall be at least two characters on MS Windows.
184 (when (memq system-type '(cygwin windows-nt))
185 (should-not (tramp-tramp-file-p "/c:/path/to/file"))
186 (should-not (tramp-tramp-file-p "/c::/path/to/file"))))
188 (ert-deftest tramp-test02-file-name-dissect ()
189 "Check remote file name components."
190 (let ((tramp-default-method "default-method")
191 (tramp-default-user "default-user")
192 (tramp-default-host "default-host"))
193 ;; Expand `tramp-default-user' and `tramp-default-host'.
194 (should (string-equal
195 (file-remote-p "/method::")
196 (format "/%s:%s@%s:" "method" "default-user" "default-host")))
197 (should (string-equal (file-remote-p "/method::" 'method) "method"))
198 (should (string-equal (file-remote-p "/method::" 'user) "default-user"))
199 (should (string-equal (file-remote-p "/method::" 'host) "default-host"))
200 (should (string-equal (file-remote-p "/method::" 'localname) ""))
202 ;; Expand `tramp-default-method' and `tramp-default-user'.
203 (should (string-equal
204 (file-remote-p "/host:")
205 (format "/%s:%s@%s:" "default-method" "default-user" "host")))
206 (should (string-equal (file-remote-p "/host:" 'method) "default-method"))
207 (should (string-equal (file-remote-p "/host:" 'user) "default-user"))
208 (should (string-equal (file-remote-p "/host:" 'host) "host"))
209 (should (string-equal (file-remote-p "/host:" 'localname) ""))
211 ;; Expand `tramp-default-method' and `tramp-default-host'.
212 (should (string-equal
213 (file-remote-p "/user@:")
214 (format "/%s:%s@%s:" "default-method""user" "default-host")))
215 (should (string-equal (file-remote-p "/user@:" 'method) "default-method"))
216 (should (string-equal (file-remote-p "/user@:" 'user) "user"))
217 (should (string-equal (file-remote-p "/user@:" 'host) "default-host"))
218 (should (string-equal (file-remote-p "/user@:" 'localname) ""))
220 ;; Expand `tramp-default-method'.
221 (should (string-equal
222 (file-remote-p "/user@host:")
223 (format "/%s:%s@%s:" "default-method" "user" "host")))
224 (should (string-equal
225 (file-remote-p "/user@host:" 'method) "default-method"))
226 (should (string-equal (file-remote-p "/user@host:" 'user) "user"))
227 (should (string-equal (file-remote-p "/user@host:" 'host) "host"))
228 (should (string-equal (file-remote-p "/user@host:" 'localname) ""))
230 ;; Expand `tramp-default-user'.
231 (should (string-equal
232 (file-remote-p "/method:host:")
233 (format "/%s:%s@%s:" "method" "default-user" "host")))
234 (should (string-equal (file-remote-p "/method:host:" 'method) "method"))
235 (should (string-equal (file-remote-p "/method:host:" 'user) "default-user"))
236 (should (string-equal (file-remote-p "/method:host:" 'host) "host"))
237 (should (string-equal (file-remote-p "/method:host:" 'localname) ""))
239 ;; Expand `tramp-default-host'.
240 (should (string-equal
241 (file-remote-p "/method:user@:")
242 (format "/%s:%s@%s:" "method" "user" "default-host")))
243 (should (string-equal (file-remote-p "/method:user@:" 'method) "method"))
244 (should (string-equal (file-remote-p "/method:user@:" 'user) "user"))
245 (should (string-equal (file-remote-p "/method:user@:" 'host)
247 (should (string-equal (file-remote-p "/method:user@:" 'localname) ""))
250 (should (string-equal
251 (file-remote-p "/method:user@host:")
252 (format "/%s:%s@%s:" "method" "user" "host")))
253 (should (string-equal
254 (file-remote-p "/method:user@host:" 'method) "method"))
255 (should (string-equal (file-remote-p "/method:user@host:" 'user) "user"))
256 (should (string-equal (file-remote-p "/method:user@host:" 'host) "host"))
257 (should (string-equal (file-remote-p "/method:user@host:" 'localname) ""))
260 (should (string-equal
261 (file-remote-p "/method:user@email@host:")
262 (format "/%s:%s@%s:" "method" "user@email" "host")))
263 (should (string-equal
264 (file-remote-p "/method:user@email@host:" 'method) "method"))
265 (should (string-equal
266 (file-remote-p "/method:user@email@host:" 'user) "user@email"))
267 (should (string-equal
268 (file-remote-p "/method:user@email@host:" 'host) "host"))
269 (should (string-equal
270 (file-remote-p "/method:user@email@host:" 'localname) ""))
272 ;; Expand `tramp-default-method' and `tramp-default-user'.
273 (should (string-equal
274 (file-remote-p "/host#1234:")
275 (format "/%s:%s@%s:" "default-method" "default-user" "host#1234")))
276 (should (string-equal
277 (file-remote-p "/host#1234:" 'method) "default-method"))
278 (should (string-equal (file-remote-p "/host#1234:" 'user) "default-user"))
279 (should (string-equal (file-remote-p "/host#1234:" 'host) "host#1234"))
280 (should (string-equal (file-remote-p "/host#1234:" 'localname) ""))
282 ;; Expand `tramp-default-method'.
283 (should (string-equal
284 (file-remote-p "/user@host#1234:")
285 (format "/%s:%s@%s:" "default-method" "user" "host#1234")))
286 (should (string-equal
287 (file-remote-p "/user@host#1234:" 'method) "default-method"))
288 (should (string-equal (file-remote-p "/user@host#1234:" 'user) "user"))
289 (should (string-equal (file-remote-p "/user@host#1234:" 'host) "host#1234"))
290 (should (string-equal (file-remote-p "/user@host#1234:" 'localname) ""))
292 ;; Expand `tramp-default-user'.
293 (should (string-equal
294 (file-remote-p "/method:host#1234:")
295 (format "/%s:%s@%s:" "method" "default-user" "host#1234")))
296 (should (string-equal
297 (file-remote-p "/method:host#1234:" 'method) "method"))
298 (should (string-equal
299 (file-remote-p "/method:host#1234:" 'user) "default-user"))
300 (should (string-equal
301 (file-remote-p "/method:host#1234:" 'host) "host#1234"))
302 (should (string-equal (file-remote-p "/method:host#1234:" 'localname) ""))
305 (should (string-equal
306 (file-remote-p "/method:user@host#1234:")
307 (format "/%s:%s@%s:" "method" "user" "host#1234")))
308 (should (string-equal
309 (file-remote-p "/method:user@host#1234:" 'method) "method"))
310 (should (string-equal
311 (file-remote-p "/method:user@host#1234:" 'user) "user"))
312 (should (string-equal
313 (file-remote-p "/method:user@host#1234:" 'host) "host#1234"))
314 (should (string-equal
315 (file-remote-p "/method:user@host#1234:" 'localname) ""))
317 ;; Expand `tramp-default-method' and `tramp-default-user'.
318 (should (string-equal
319 (file-remote-p "/1.2.3.4:")
320 (format "/%s:%s@%s:" "default-method" "default-user" "1.2.3.4")))
321 (should (string-equal (file-remote-p "/1.2.3.4:" 'method) "default-method"))
322 (should (string-equal (file-remote-p "/1.2.3.4:" 'user) "default-user"))
323 (should (string-equal (file-remote-p "/1.2.3.4:" 'host) "1.2.3.4"))
324 (should (string-equal (file-remote-p "/1.2.3.4:" 'localname) ""))
326 ;; Expand `tramp-default-method'.
327 (should (string-equal
328 (file-remote-p "/user@1.2.3.4:")
329 (format "/%s:%s@%s:" "default-method" "user" "1.2.3.4")))
330 (should (string-equal
331 (file-remote-p "/user@1.2.3.4:" 'method) "default-method"))
332 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'user) "user"))
333 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'host) "1.2.3.4"))
334 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'localname) ""))
336 ;; Expand `tramp-default-user'.
337 (should (string-equal
338 (file-remote-p "/method:1.2.3.4:")
339 (format "/%s:%s@%s:" "method" "default-user" "1.2.3.4")))
340 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'method) "method"))
341 (should (string-equal
342 (file-remote-p "/method:1.2.3.4:" 'user) "default-user"))
343 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'host) "1.2.3.4"))
344 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'localname) ""))
347 (should (string-equal
348 (file-remote-p "/method:user@1.2.3.4:")
349 (format "/%s:%s@%s:" "method" "user" "1.2.3.4")))
350 (should (string-equal
351 (file-remote-p "/method:user@1.2.3.4:" 'method) "method"))
352 (should (string-equal (file-remote-p "/method:user@1.2.3.4:" 'user) "user"))
353 (should (string-equal
354 (file-remote-p "/method:user@1.2.3.4:" 'host) "1.2.3.4"))
355 (should (string-equal
356 (file-remote-p "/method:user@1.2.3.4:" 'localname) ""))
358 ;; Expand `tramp-default-method', `tramp-default-user' and
359 ;; `tramp-default-host'.
360 (should (string-equal
361 (file-remote-p "/[]:")
363 "/%s:%s@%s:" "default-method" "default-user" "default-host")))
364 (should (string-equal (file-remote-p "/[]:" 'method) "default-method"))
365 (should (string-equal (file-remote-p "/[]:" 'user) "default-user"))
366 (should (string-equal (file-remote-p "/[]:" 'host) "default-host"))
367 (should (string-equal (file-remote-p "/[]:" 'localname) ""))
369 ;; Expand `tramp-default-method' and `tramp-default-user'.
370 (let ((tramp-default-host "::1"))
371 (should (string-equal
372 (file-remote-p "/[]:")
373 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
374 (should (string-equal (file-remote-p "/[]:" 'method) "default-method"))
375 (should (string-equal (file-remote-p "/[]:" 'user) "default-user"))
376 (should (string-equal (file-remote-p "/[]:" 'host) "::1"))
377 (should (string-equal (file-remote-p "/[]:" 'localname) "")))
379 ;; Expand `tramp-default-method' and `tramp-default-user'.
380 (should (string-equal
381 (file-remote-p "/[::1]:")
382 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
383 (should (string-equal (file-remote-p "/[::1]:" 'method) "default-method"))
384 (should (string-equal (file-remote-p "/[::1]:" 'user) "default-user"))
385 (should (string-equal (file-remote-p "/[::1]:" 'host) "::1"))
386 (should (string-equal (file-remote-p "/[::1]:" 'localname) ""))
388 ;; Expand `tramp-default-method'.
389 (should (string-equal
390 (file-remote-p "/user@[::1]:")
391 (format "/%s:%s@%s:" "default-method" "user" "[::1]")))
392 (should (string-equal
393 (file-remote-p "/user@[::1]:" 'method) "default-method"))
394 (should (string-equal (file-remote-p "/user@[::1]:" 'user) "user"))
395 (should (string-equal (file-remote-p "/user@[::1]:" 'host) "::1"))
396 (should (string-equal (file-remote-p "/user@[::1]:" 'localname) ""))
398 ;; Expand `tramp-default-user'.
399 (should (string-equal
400 (file-remote-p "/method:[::1]:")
401 (format "/%s:%s@%s:" "method" "default-user" "[::1]")))
402 (should (string-equal (file-remote-p "/method:[::1]:" 'method) "method"))
403 (should (string-equal
404 (file-remote-p "/method:[::1]:" 'user) "default-user"))
405 (should (string-equal (file-remote-p "/method:[::1]:" 'host) "::1"))
406 (should (string-equal (file-remote-p "/method:[::1]:" 'localname) ""))
409 (should (string-equal
410 (file-remote-p "/method:user@[::1]:")
411 (format "/%s:%s@%s:" "method" "user" "[::1]")))
412 (should (string-equal
413 (file-remote-p "/method:user@[::1]:" 'method) "method"))
414 (should (string-equal (file-remote-p "/method:user@[::1]:" 'user) "user"))
415 (should (string-equal (file-remote-p "/method:user@[::1]:" 'host) "::1"))
416 (should (string-equal
417 (file-remote-p "/method:user@[::1]:" 'localname) ""))
419 ;; Local file name part.
420 (should (string-equal (file-remote-p "/host:/:" 'localname) "/:"))
421 (should (string-equal (file-remote-p "/method:::" 'localname) ":"))
422 (should (string-equal (file-remote-p "/method:: " 'localname) " "))
423 (should (string-equal (file-remote-p "/method::file" 'localname) "file"))
424 (should (string-equal
425 (file-remote-p "/method::/path/to/file" 'localname)
431 (file-remote-p "/method1:user1@host1|method2:user2@host2:/path/to/file")
432 (format "/%s:%s@%s:" "method2" "user2" "host2")))
436 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'method)
441 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'user)
446 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'host)
451 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'localname)
457 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file")
458 (format "/%s:%s@%s:" "method3" "user3" "host3")))
462 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
468 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
474 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
480 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
484 (ert-deftest tramp-test03-file-name-defaults ()
485 "Check default values for some methods."
486 ;; Default values in tramp-adb.el.
487 (should (string-equal (file-remote-p "/adb::" 'host) ""))
488 ;; Default values in tramp-ftp.el.
489 (should (string-equal (file-remote-p "/ftp.host:" 'method) "ftp"))
490 (dolist (u '("ftp" "anonymous"))
491 (should (string-equal (file-remote-p (format "/%s@:" u) 'method) "ftp")))
492 ;; Default values in tramp-gvfs.el.
493 (when (and (load "tramp-gvfs" 'noerror 'nomessage)
494 (symbol-value 'tramp-gvfs-enabled))
495 (should (string-equal (file-remote-p "/synce::" 'user) nil)))
496 ;; Default values in tramp-gw.el.
497 (dolist (m '("tunnel" "socks"))
499 (string-equal (file-remote-p (format "/%s::" m) 'user) (user-login-name))))
500 ;; Default values in tramp-sh.el.
501 (dolist (h `("127.0.0.1" "[::1]" "localhost" "localhost6" ,(system-name)))
502 (should (string-equal (file-remote-p (format "/root@%s:" h) 'method) "su")))
503 (dolist (m '("su" "sudo" "ksu"))
504 (should (string-equal (file-remote-p (format "/%s::" m) 'user) "root")))
505 (dolist (m '("rcp" "remcp" "rsh" "telnet" "krlogin" "fcp"))
507 (string-equal (file-remote-p (format "/%s::" m) 'user) (user-login-name))))
508 ;; Default values in tramp-smb.el.
509 (should (string-equal (file-remote-p "/user%domain@host:" 'method) "smb"))
510 (should (string-equal (file-remote-p "/smb::" 'user) nil)))
512 (ert-deftest tramp-test04-substitute-in-file-name ()
513 "Check `substitute-in-file-name'."
514 (should (string-equal (substitute-in-file-name "/method:host://foo") "/foo"))
517 (substitute-in-file-name "/method:host:/path//foo") "/method:host:/foo"))
519 (string-equal (substitute-in-file-name "/method:host:/path///foo") "/foo"))
522 (substitute-in-file-name "/method:host:/path/~/foo") "/method:host:~/foo"))
524 (string-equal (substitute-in-file-name "/method:host:/path//~/foo") "~/foo"))
525 (let (process-environment)
528 (substitute-in-file-name "/method:host:/path/$FOO")
529 "/method:host:/path/$FOO"))
533 (substitute-in-file-name "/method:host:/path/$FOO")
534 "/method:host:/path/bla"))
537 (substitute-in-file-name "/method:host:/path/$$FOO")
538 "/method:host:/path/$FOO"))))
540 (ert-deftest tramp-test05-expand-file-name ()
541 "Check `expand-file-name'."
544 (expand-file-name "/method:host:/path/./file") "/method:host:/path/file"))
547 (expand-file-name "/method:host:/path/../file") "/method:host:/file")))
549 (ert-deftest tramp-test06-directory-file-name ()
550 "Check `directory-file-name'.
551 This checks also `file-name-as-directory', `file-name-directory'
552 and `file-name-nondirectory'."
555 (directory-file-name "/method:host:/path/to/file")
556 "/method:host:/path/to/file"))
559 (directory-file-name "/method:host:/path/to/file/")
560 "/method:host:/path/to/file"))
563 (file-name-as-directory "/method:host:/path/to/file")
564 "/method:host:/path/to/file/"))
567 (file-name-as-directory "/method:host:/path/to/file/")
568 "/method:host:/path/to/file/"))
571 (file-name-directory "/method:host:/path/to/file")
572 "/method:host:/path/to/"))
575 (file-name-directory "/method:host:/path/to/file/")
576 "/method:host:/path/to/file/"))
578 (string-equal (file-name-nondirectory "/method:host:/path/to/file") "file"))
580 (string-equal (file-name-nondirectory "/method:host:/path/to/file/") ""))
583 (unhandled-file-name-directory "/method:host:/path/to/file"))))
585 (ert-deftest tramp-test07-file-exists-p ()
586 "Check `file-exist-p', `write-region' and `delete-file'."
587 (skip-unless (tramp--test-enabled))
589 (let ((tmp-name (tramp--test-make-temp-name)))
590 (should-not (file-exists-p tmp-name))
591 (write-region "foo" nil tmp-name)
592 (should (file-exists-p tmp-name))
593 (delete-file tmp-name)
594 (should-not (file-exists-p tmp-name))))
596 (ert-deftest tramp-test08-file-local-copy ()
597 "Check `file-local-copy'."
598 (skip-unless (tramp--test-enabled))
600 (let ((tmp-name1 (tramp--test-make-temp-name))
604 (write-region "foo" nil tmp-name1)
605 (should (setq tmp-name2 (file-local-copy tmp-name1)))
607 (insert-file-contents tmp-name2)
608 (should (string-equal (buffer-string) "foo"))))
610 (delete-file tmp-name1)
611 (delete-file tmp-name2)))))
613 (ert-deftest tramp-test09-insert-file-contents ()
614 "Check `insert-file-contents'."
615 (skip-unless (tramp--test-enabled))
617 (let ((tmp-name (tramp--test-make-temp-name)))
620 (write-region "foo" nil tmp-name)
622 (insert-file-contents tmp-name)
623 (should (string-equal (buffer-string) "foo"))
624 (insert-file-contents tmp-name)
625 (should (string-equal (buffer-string) "foofoo"))
627 (insert-file-contents tmp-name nil 1 3)
628 (should (string-equal (buffer-string) "oofoofoo"))
630 (insert-file-contents tmp-name nil nil nil 'replace)
631 (should (string-equal (buffer-string) "foo"))))
632 (ignore-errors (delete-file tmp-name)))))
634 (ert-deftest tramp-test10-write-region ()
635 "Check `write-region'."
636 (skip-unless (tramp--test-enabled))
638 (let ((tmp-name (tramp--test-make-temp-name)))
643 (write-region nil nil tmp-name))
645 (insert-file-contents tmp-name)
646 (should (string-equal (buffer-string) "foo")))
650 (write-region nil nil tmp-name 'append))
652 (insert-file-contents tmp-name)
653 (should (string-equal (buffer-string) "foobla")))
655 (write-region "foo" nil tmp-name)
657 (insert-file-contents tmp-name)
658 (should (string-equal (buffer-string) "foo")))
662 (write-region 3 5 tmp-name))
664 (insert-file-contents tmp-name)
665 (should (string-equal (buffer-string) "34"))))
666 (ignore-errors (delete-file tmp-name)))))
668 (ert-deftest tramp-test11-copy-file ()
670 (skip-unless (tramp--test-enabled))
672 (let ((tmp-name1 (tramp--test-make-temp-name))
673 (tmp-name2 (tramp--test-make-temp-name)))
676 (write-region "foo" nil tmp-name1)
677 (copy-file tmp-name1 tmp-name2)
678 (should (file-exists-p tmp-name2))
680 (insert-file-contents tmp-name2)
681 (should (string-equal (buffer-string) "foo"))))
683 (delete-file tmp-name1)
684 (delete-file tmp-name2)))))
686 (ert-deftest tramp-test12-rename-file ()
687 "Check `rename-file'."
688 (skip-unless (tramp--test-enabled))
690 (let ((tmp-name1 (tramp--test-make-temp-name))
691 (tmp-name2 (tramp--test-make-temp-name)))
694 (write-region "foo" nil tmp-name1)
695 (rename-file tmp-name1 tmp-name2)
696 (should-not (file-exists-p tmp-name1))
697 (should (file-exists-p tmp-name2))
699 (insert-file-contents tmp-name2)
700 (should (string-equal (buffer-string) "foo"))))
701 (ignore-errors (delete-file tmp-name2)))))
703 (ert-deftest tramp-test13-make-directory ()
704 "Check `make-directory'.
705 This tests also `file-directory-p' and `file-accessible-directory-p'."
706 (skip-unless (tramp--test-enabled))
708 (let ((tmp-name (tramp--test-make-temp-name)))
711 (make-directory tmp-name)
712 (should (file-directory-p tmp-name))
713 (should (file-accessible-directory-p tmp-name)))
714 (ignore-errors (delete-directory tmp-name)))))
716 (ert-deftest tramp-test14-delete-directory ()
717 "Check `delete-directory'."
718 (skip-unless (tramp--test-enabled))
720 (let ((tmp-name (tramp--test-make-temp-name)))
721 ;; Delete empty directory.
722 (make-directory tmp-name)
723 (should (file-directory-p tmp-name))
724 (delete-directory tmp-name)
725 (should-not (file-directory-p tmp-name))
726 ;; Delete non-empty directory.
727 (make-directory tmp-name)
728 (write-region "foo" nil (expand-file-name "bla" tmp-name))
729 (should-error (delete-directory tmp-name) :type 'file-error)
730 (delete-directory tmp-name 'recursive)
731 (should-not (file-directory-p tmp-name))))
733 (ert-deftest tramp-test15-copy-directory ()
734 "Check `copy-directory'."
735 (skip-unless (tramp--test-enabled))
737 (let* ((tmp-name1 (tramp--test-make-temp-name))
738 (tmp-name2 (tramp--test-make-temp-name))
739 (tmp-name3 (expand-file-name
740 (file-name-nondirectory tmp-name1) tmp-name2))
741 (tmp-name4 (expand-file-name "foo" tmp-name1))
742 (tmp-name5 (expand-file-name "foo" tmp-name2))
743 (tmp-name6 (expand-file-name "foo" tmp-name3)))
746 ;; Copy empty directory.
747 (make-directory tmp-name1)
748 (write-region "foo" nil tmp-name4)
749 (should (file-directory-p tmp-name1))
750 (should (file-exists-p tmp-name4))
751 (copy-directory tmp-name1 tmp-name2)
752 (should (file-directory-p tmp-name2))
753 (should (file-exists-p tmp-name5))
754 ;; Target directory does exist already.
755 (copy-directory tmp-name1 tmp-name2)
756 (should (file-directory-p tmp-name3))
757 (should (file-exists-p tmp-name6)))
759 (delete-directory tmp-name1 'recursive)
760 (delete-directory tmp-name2 'recursive)))))
762 (ert-deftest tramp-test16-directory-files ()
763 "Check `directory-files'."
764 (skip-unless (tramp--test-enabled))
766 (let* ((tmp-name1 (tramp--test-make-temp-name))
767 (tmp-name2 (expand-file-name "bla" tmp-name1))
768 (tmp-name3 (expand-file-name "foo" tmp-name1)))
771 (make-directory tmp-name1)
772 (write-region "foo" nil tmp-name2)
773 (write-region "bla" nil tmp-name3)
774 (should (file-directory-p tmp-name1))
775 (should (file-exists-p tmp-name2))
776 (should (file-exists-p tmp-name3))
777 (should (equal (directory-files tmp-name1) '("." ".." "bla" "foo")))
778 (should (equal (directory-files tmp-name1 'full)
779 `(,(concat tmp-name1 "/.")
780 ,(concat tmp-name1 "/..")
781 ,tmp-name2 ,tmp-name3)))
782 (should (equal (directory-files
783 tmp-name1 nil directory-files-no-dot-files-regexp)
785 (should (equal (directory-files
786 tmp-name1 'full directory-files-no-dot-files-regexp)
787 `(,tmp-name2 ,tmp-name3))))
788 (ignore-errors (delete-directory tmp-name1 'recursive)))))
790 (ert-deftest tramp-test17-insert-directory ()
791 "Check `insert-directory'."
792 (skip-unless (tramp--test-enabled))
794 (let* ((tmp-name1 (tramp--test-make-temp-name))
795 (tmp-name2 (expand-file-name "foo" tmp-name1)))
798 (make-directory tmp-name1)
799 (write-region "foo" nil tmp-name2)
800 (should (file-directory-p tmp-name1))
801 (should (file-exists-p tmp-name2))
803 (insert-directory tmp-name1 nil)
804 (goto-char (point-min))
805 (should (looking-at-p (regexp-quote tmp-name1))))
807 (insert-directory tmp-name1 "-al")
808 (goto-char (point-min))
809 (should (looking-at-p (format "^.+ %s$" (regexp-quote tmp-name1)))))
811 (insert-directory (file-name-as-directory tmp-name1) "-al")
812 (goto-char (point-min))
814 (looking-at-p (format "^.+ %s/$" (regexp-quote tmp-name1)))))
817 (file-name-as-directory tmp-name1) "-al" nil 'full-directory-p)
818 (goto-char (point-min))
821 "\\(total.+[[:digit:]]+\n\\)?.+ \\.\n.+ \\.\\.\n.+ foo$"))))
822 (ignore-errors (delete-directory tmp-name1 'recursive)))))
824 (ert-deftest tramp-test18-file-attributes ()
825 "Check `file-attributes'.
826 This tests also `file-readable-p' and `file-regular-p'."
827 (skip-unless (tramp--test-enabled))
829 (let ((tmp-name (tramp--test-make-temp-name))
833 (write-region "foo" nil tmp-name)
834 (should (file-exists-p tmp-name))
835 (setq attr (file-attributes tmp-name))
836 (should (consp attr))
837 (should (file-exists-p tmp-name))
838 (should (file-readable-p tmp-name))
839 (should (file-regular-p tmp-name))
840 ;; We do not test inodes and device numbers.
841 (should (null (car attr)))
842 (should (numberp (nth 1 attr))) ;; Link.
843 (should (numberp (nth 2 attr))) ;; Uid.
844 (should (numberp (nth 3 attr))) ;; Gid.
846 (should (stringp (current-time-string (nth 4 attr))))
847 ;; Last modification time.
848 (should (stringp (current-time-string (nth 5 attr))))
849 ;; Last status change time.
850 (should (stringp (current-time-string (nth 6 attr))))
851 (should (numberp (nth 7 attr))) ;; Size.
852 (should (stringp (nth 8 attr))) ;; Modes.
854 (setq attr (file-attributes tmp-name 'string))
855 (should (stringp (nth 2 attr))) ;; Uid.
856 (should (stringp (nth 3 attr))) ;; Gid.
857 (delete-file tmp-name)
859 (make-directory tmp-name)
860 (should (file-exists-p tmp-name))
861 (should (file-readable-p tmp-name))
862 (should-not (file-regular-p tmp-name))
863 (setq attr (file-attributes tmp-name))
864 (should (eq (car attr) t)))
865 (ignore-errors (delete-directory tmp-name)))))
867 (ert-deftest tramp-test19-directory-files-and-attributes ()
868 "Check `directory-files-and-attributes'."
869 (skip-unless (tramp--test-enabled))
871 ;; `directory-files-and-attributes' contains also values for "../".
872 ;; Ensure that this doesn't change during tests, for
873 ;; example due to handling temporary files.
874 (let* ((tmp-name1 (tramp--test-make-temp-name))
875 (tmp-name2 (expand-file-name "bla" tmp-name1))
879 (make-directory tmp-name1)
880 (should (file-directory-p tmp-name1))
881 (make-directory tmp-name2)
882 (should (file-directory-p tmp-name2))
883 (write-region "foo" nil (expand-file-name "foo" tmp-name2))
884 (write-region "bar" nil (expand-file-name "bar" tmp-name2))
885 (write-region "boz" nil (expand-file-name "boz" tmp-name2))
886 (setq attr (directory-files-and-attributes tmp-name2))
887 (should (consp attr))
890 (equal (file-attributes (expand-file-name (car elt) tmp-name2))
892 (setq attr (directory-files-and-attributes tmp-name2 'full))
895 (equal (file-attributes (car elt)) (cdr elt))))
896 (setq attr (directory-files-and-attributes tmp-name2 nil "^b"))
897 (should (equal (mapcar 'car attr) '("bar" "boz"))))
898 (ignore-errors (delete-directory tmp-name1 'recursive)))))
900 (ert-deftest tramp-test20-file-modes ()
902 This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
903 (skip-unless (tramp--test-enabled))
907 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
908 '(tramp-adb-file-name-handler
909 tramp-gvfs-file-name-handler
910 tramp-smb-file-name-handler))))
912 (let ((tmp-name (tramp--test-make-temp-name)))
915 (write-region "foo" nil tmp-name)
916 (should (file-exists-p tmp-name))
917 (set-file-modes tmp-name #o777)
918 (should (= (file-modes tmp-name) #o777))
919 (should (file-executable-p tmp-name))
920 (should (file-writable-p tmp-name))
921 (set-file-modes tmp-name #o444)
922 (should (= (file-modes tmp-name) #o444))
923 (should-not (file-executable-p tmp-name))
924 ;; A file is always writable for user "root".
925 (when (not (string-equal (file-remote-p tmp-name 'user) "root"))
926 (should-not (file-writable-p tmp-name))))
927 (ignore-errors (delete-file tmp-name)))))
929 (ert-deftest tramp-test21-file-links ()
930 "Check `file-symlink-p'.
931 This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
932 (skip-unless (tramp--test-enabled))
934 (let ((tmp-name1 (tramp--test-make-temp-name))
935 (tmp-name2 (tramp--test-make-temp-name))
936 (tmp-name3 (make-temp-name "tramp-")))
939 (write-region "foo" nil tmp-name1)
940 (should (file-exists-p tmp-name1))
941 ;; Method "smb" supports `make-symbolic-link' only if the
942 ;; remote host has CIFS capabilities. tramp-adb.el and
943 ;; tramp-gvfs.el do not support symbolic links at all.
945 (make-symbolic-link tmp-name1 tmp-name2)
948 (not (string-equal (error-message-string err)
949 "make-symbolic-link not supported")))))
950 (should (file-symlink-p tmp-name2))
951 (should-error (make-symbolic-link tmp-name1 tmp-name2))
952 (make-symbolic-link tmp-name1 tmp-name2 'ok-if-already-exists)
953 (should (file-symlink-p tmp-name2))
954 ;; `tmp-name3' is a local file name.
955 (should-error (make-symbolic-link tmp-name1 tmp-name3)))
957 (delete-file tmp-name1)
958 (delete-file tmp-name2)))
962 (write-region "foo" nil tmp-name1)
963 (should (file-exists-p tmp-name1))
964 (add-name-to-file tmp-name1 tmp-name2)
965 (should-not (file-symlink-p tmp-name2))
966 (should-error (add-name-to-file tmp-name1 tmp-name2))
967 (add-name-to-file tmp-name1 tmp-name2 'ok-if-already-exists)
968 (should-not (file-symlink-p tmp-name2))
969 ;; `tmp-name3' is a local file name.
970 (should-error (add-name-to-file tmp-name1 tmp-name3)))
972 (delete-file tmp-name1)
973 (delete-file tmp-name2)))
977 (write-region "foo" nil tmp-name1)
978 (should (file-exists-p tmp-name1))
979 (make-symbolic-link tmp-name1 tmp-name2)
980 (should (file-symlink-p tmp-name2))
981 (should-not (string-equal tmp-name2 (file-truename tmp-name2)))
983 (string-equal (file-truename tmp-name1) (file-truename tmp-name2))))
985 (delete-file tmp-name1)
986 (delete-file tmp-name2)))
988 ;; `file-truename' shall preserve trailing link of directories.
989 (let* ((dir1 (directory-file-name tramp-test-temporary-file-directory))
990 (dir2 (file-name-as-directory dir1)))
991 (should (string-equal (file-truename dir1) (expand-file-name dir1)))
992 (should (string-equal (file-truename dir2) (expand-file-name dir2))))))
994 (ert-deftest tramp-test22-file-times ()
995 "Check `set-file-times' and `file-newer-than-file-p'."
996 (skip-unless (tramp--test-enabled))
1000 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1001 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler))))
1003 (let ((tmp-name1 (tramp--test-make-temp-name))
1004 (tmp-name2 (tramp--test-make-temp-name))
1005 (tmp-name3 (tramp--test-make-temp-name)))
1008 (write-region "foo" nil tmp-name1)
1009 (should (file-exists-p tmp-name1))
1010 (should (consp (nth 5 (file-attributes tmp-name1))))
1011 ;; '(0 0) means don't know, and will be replaced by
1012 ;; `current-time'. Therefore, we use '(0 1).
1013 ;; We skip the test, if the remote handler is not able to
1014 ;; set the correct time.
1015 (skip-unless (set-file-times tmp-name1 '(0 1)))
1016 ;; Dumb busyboxes are not able to return the date correctly.
1017 ;; They say "don't know.
1018 (skip-unless (not (equal (nth 5 (file-attributes tmp-name1)) '(0 0))))
1019 (should (equal (nth 5 (file-attributes tmp-name1)) '(0 1)))
1020 (write-region "bla" nil tmp-name2)
1021 (should (file-exists-p tmp-name2))
1022 (should (file-newer-than-file-p tmp-name2 tmp-name1))
1023 ;; `tmp-name3' does not exist.
1024 (should (file-newer-than-file-p tmp-name2 tmp-name3))
1025 (should-not (file-newer-than-file-p tmp-name3 tmp-name1)))
1027 (delete-file tmp-name1)
1028 (delete-file tmp-name2)))))
1030 (ert-deftest tramp-test23-visited-file-modtime ()
1031 "Check `set-visited-file-modtime' and `verify-visited-file-modtime'."
1032 (skip-unless (tramp--test-enabled))
1034 (let ((tmp-name (tramp--test-make-temp-name)))
1037 (write-region "foo" nil tmp-name)
1038 (should (file-exists-p tmp-name))
1040 (insert-file-contents tmp-name)
1041 (should (verify-visited-file-modtime))
1042 (set-visited-file-modtime '(0 1))
1043 (should (verify-visited-file-modtime))
1044 (should (equal (visited-file-modtime) '(0 1 0 0)))))
1045 (ignore-errors (delete-file tmp-name)))))
1047 (ert-deftest tramp-test24-file-name-completion ()
1048 "Check `file-name-completion' and `file-name-all-completions'."
1049 (skip-unless (tramp--test-enabled))
1051 (let ((tmp-name (tramp--test-make-temp-name)))
1054 (make-directory tmp-name)
1055 (should (file-directory-p tmp-name))
1056 (write-region "foo" nil (expand-file-name "foo" tmp-name))
1057 (write-region "bar" nil (expand-file-name "bold" tmp-name))
1058 (make-directory (expand-file-name "boz" tmp-name))
1059 (should (equal (file-name-completion "fo" tmp-name) "foo"))
1060 (should (equal (file-name-completion "b" tmp-name) "bo"))
1062 (equal (file-name-completion "b" tmp-name 'file-directory-p) "boz/"))
1063 (should (equal (file-name-all-completions "fo" tmp-name) '("foo")))
1065 (equal (sort (file-name-all-completions "b" tmp-name) 'string-lessp)
1067 (ignore-errors (delete-directory tmp-name 'recursive)))))
1069 (ert-deftest tramp-test25-load ()
1071 (skip-unless (tramp--test-enabled))
1073 (let ((tmp-name (tramp--test-make-temp-name)))
1076 (load tmp-name 'noerror 'nomessage)
1077 (should-not (featurep 'tramp-test-load))
1078 (write-region "(provide 'tramp-test-load)" nil tmp-name)
1079 ;; `load' in lread.c does not pass `must-suffix'. Why?
1080 ;(should-error (load tmp-name nil 'nomessage 'nosuffix 'must-suffix))
1081 (load tmp-name nil 'nomessage 'nosuffix)
1082 (should (featurep 'tramp-test-load)))
1084 (and (featurep 'tramp-test-load) (unload-feature 'tramp-test-load))
1085 (delete-file tmp-name)))))
1087 (ert-deftest tramp-test26-process-file ()
1088 "Check `process-file'."
1089 (skip-unless (tramp--test-enabled))
1093 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1094 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler))))
1096 (let ((tmp-name (tramp--test-make-temp-name))
1097 (default-directory tramp-test-temporary-file-directory)
1098 kill-buffer-query-functions)
1101 ;; We cannot use "/bin/true" and "/bin/false"; those paths
1102 ;; do not exist on hydra.
1103 (should (zerop (process-file "true")))
1104 (should-not (zerop (process-file "false")))
1105 (should-not (zerop (process-file "binary-does-not-exist")))
1107 (write-region "foo" nil tmp-name)
1108 (should (file-exists-p tmp-name))
1111 (process-file "ls" nil t nil (file-name-nondirectory tmp-name))))
1112 ;; `ls' could produce colorized output.
1113 (goto-char (point-min))
1114 (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
1115 (replace-match "" nil nil))
1118 (format "%s\n" (file-name-nondirectory tmp-name))
1120 (ignore-errors (delete-file tmp-name)))))
1122 (ert-deftest tramp-test27-start-file-process ()
1123 "Check `start-file-process'."
1124 (skip-unless (tramp--test-enabled))
1128 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1129 '(tramp-adb-file-name-handler
1130 tramp-gvfs-file-name-handler
1131 tramp-smb-file-name-handler))))
1133 (let ((default-directory tramp-test-temporary-file-directory)
1134 (tmp-name (tramp--test-make-temp-name))
1135 kill-buffer-query-functions proc)
1138 (setq proc (start-file-process "test1" (current-buffer) "cat"))
1139 (should (processp proc))
1140 (should (equal (process-status proc) 'run))
1141 (process-send-string proc "foo")
1142 (process-send-eof proc)
1143 (accept-process-output proc 1)
1144 (should (string-equal (buffer-string) "foo")))
1145 (ignore-errors (delete-process proc)))
1149 (write-region "foo" nil tmp-name)
1150 (should (file-exists-p tmp-name))
1153 "test2" (current-buffer)
1154 "cat" (file-name-nondirectory tmp-name)))
1155 (should (processp proc))
1156 (accept-process-output proc 1)
1157 (should (string-equal (buffer-string) "foo")))
1159 (delete-process proc)
1160 (delete-file tmp-name)))
1164 (setq proc (start-file-process "test3" nil "cat"))
1165 (should (processp proc))
1166 (should (equal (process-status proc) 'run))
1168 proc (lambda (_p s) (should (string-equal s "foo"))))
1169 (process-send-string proc "foo")
1170 (process-send-eof proc)
1171 (accept-process-output proc 1))
1172 (ignore-errors (delete-process proc)))))
1174 (ert-deftest tramp-test28-shell-command ()
1175 "Check `shell-command'."
1176 (skip-unless (tramp--test-enabled))
1180 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1181 '(tramp-adb-file-name-handler
1182 tramp-gvfs-file-name-handler
1183 tramp-smb-file-name-handler))))
1185 (let ((tmp-name (tramp--test-make-temp-name))
1186 (default-directory tramp-test-temporary-file-directory)
1187 kill-buffer-query-functions)
1190 (write-region "foo" nil tmp-name)
1191 (should (file-exists-p tmp-name))
1193 (format "ls %s" (file-name-nondirectory tmp-name)) (current-buffer))
1194 ;; `ls' could produce colorized output.
1195 (goto-char (point-min))
1196 (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
1197 (replace-match "" nil nil))
1200 (format "%s\n" (file-name-nondirectory tmp-name)) (buffer-string))))
1201 (ignore-errors (delete-file tmp-name)))
1205 (write-region "foo" nil tmp-name)
1206 (should (file-exists-p tmp-name))
1207 (async-shell-command
1208 (format "ls %s" (file-name-nondirectory tmp-name)) (current-buffer))
1209 (accept-process-output (get-buffer-process (current-buffer)) 1)
1210 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
1213 (memq (process-status (get-buffer-process (current-buffer)))
1215 (accept-process-output (get-buffer-process (current-buffer)) 1)))
1216 ;; `ls' could produce colorized output.
1217 (goto-char (point-min))
1218 (while (re-search-forward tramp-color-escape-sequence-regexp nil t)
1219 (replace-match "" nil nil))
1222 (format "%s\n" (file-name-nondirectory tmp-name)) (buffer-string))))
1223 (ignore-errors (delete-file tmp-name)))
1227 (write-region "foo" nil tmp-name)
1228 (should (file-exists-p tmp-name))
1229 (async-shell-command "read line; ls $line" (current-buffer))
1230 (process-send-string
1231 (get-buffer-process (current-buffer))
1232 (format "%s\n" (file-name-nondirectory tmp-name)))
1233 (accept-process-output (get-buffer-process (current-buffer)) 1)
1234 (with-timeout (10 (ert-fail "`async-shell-command' timed out"))
1237 (memq (process-status (get-buffer-process (current-buffer)))
1239 (accept-process-output (get-buffer-process (current-buffer)) 1)))
1242 (format "%s\n" (file-name-nondirectory tmp-name)) (buffer-string))))
1243 (ignore-errors (delete-file tmp-name)))))
1245 (ert-deftest tramp-test29-vc-registered ()
1246 "Check `vc-registered'."
1247 (skip-unless (tramp--test-enabled))
1250 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1251 'tramp-sh-file-name-handler))
1253 (let* ((default-directory tramp-test-temporary-file-directory)
1254 (tmp-name1 (tramp--test-make-temp-name))
1255 (tmp-name2 (expand-file-name "foo" tmp-name1))
1256 (vc-handled-backends
1257 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
1259 ((tramp-find-executable v vc-bzr-program (tramp-get-remote-path v))
1261 ((tramp-find-executable v vc-git-program (tramp-get-remote-path v))
1263 ((tramp-find-executable v vc-hg-program (tramp-get-remote-path v))
1266 (skip-unless vc-handled-backends)
1267 (message "%s" vc-handled-backends)
1271 (make-directory tmp-name1)
1272 (write-region "foo" nil tmp-name2)
1273 (should (file-directory-p tmp-name1))
1274 (should (file-exists-p tmp-name2))
1275 (should-not (vc-registered tmp-name1))
1276 (should-not (vc-registered tmp-name2))
1278 (let ((default-directory tmp-name1))
1279 ;; Create empty repository, and register the file.
1280 (vc-create-repo (car vc-handled-backends))
1281 ;; The structure of VC-FILESET is not documented. Let's
1282 ;; hope it won't change.
1284 nil (list (car vc-handled-backends)
1285 (list (file-name-nondirectory tmp-name2)))))
1286 (should (vc-registered tmp-name2)))
1288 (ignore-errors (delete-directory tmp-name1 'recursive)))))
1290 (ert-deftest tramp-test30-utf8 ()
1291 "Check UTF8 encoding in file names and file contents."
1292 (skip-unless (tramp--test-enabled))
1294 (let ((tmp-name (tramp--test-make-temp-name))
1295 (coding-system-for-read 'utf-8)
1296 (coding-system-for-write 'utf-8)
1297 (arabic "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت")
1298 (chinese "银河系漫游指南系列")
1299 (russian "Автостопом по гала́ктике"))
1302 (make-directory tmp-name)
1303 (dolist (lang `(,arabic ,chinese ,russian))
1304 (let ((file (expand-file-name lang tmp-name)))
1305 (write-region lang nil file)
1306 (should (file-exists-p file))
1307 ;; Check file contents.
1309 (insert-file-contents file)
1310 (should (string-equal (buffer-string) lang)))))
1311 ;; Check file names.
1312 (should (equal (directory-files
1313 tmp-name nil directory-files-no-dot-files-regexp)
1314 (sort `(,arabic ,chinese ,russian) 'string-lessp))))
1315 (ignore-errors (delete-directory tmp-name 'recursive)))))
1319 ;; * dired-compress-file
1322 ;; * file-ownership-preserved-p
1323 ;; * file-selinux-context
1324 ;; * find-backup-file-name
1325 ;; * make-auto-save-file-name
1327 ;; * set-file-selinux-context
1329 ;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?).
1330 ;; * Fix `tramp-test28-shell-command' on MS Windows (`process-send-eof'?).
1331 ;; * Fix `tramp-test30-utf8' on MS Windows. Seems to be in `directory-files'.
1333 (defun tramp-test-all (&optional interactive)
1334 "Run all tests for \\[tramp]."
1337 (if interactive 'ert-run-tests-interactively 'ert-run-tests-batch) "^tramp"))
1339 (provide 'tramp-tests)
1340 ;;; tramp-tests.el ends here