* dbusbind.c (xd_close_bus): Apply proper check on busobj.
[emacs.git] / test / automated / tramp-tests.el
blobf71f7ee239bfdac191b7154d7b758d31d625b283
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/'.
20 ;;; Commentary:
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'.
36 ;;; Code:
38 (require 'ert)
39 (require 'tramp)
40 (require 'vc)
41 (require 'vc-bzr)
42 (require 'vc-git)
43 (require 'vc-hg)
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
50 (cond
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
57 tramp-verbose 0
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'
71 being the result.")
73 (defun tramp--test-enabled ()
74 "Whether remote file access is enabled."
75 (unless (consp tramp--test-enabled-checked)
76 (setq
77 tramp--test-enabled-checked
78 (cons
79 t (ignore-errors
80 (and
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))))))
84 ;; Return result.
85 (cdr tramp--test-enabled-checked))
87 (defun tramp--test-make-temp-name ()
88 "Create a temporary file name for test."
89 (expand-file-name
90 (make-temp-name "tramp-test") tramp-test-temporary-file-directory))
92 (ert-deftest tramp-test00-availability ()
93 "Test availability of Tramp functions."
94 :expected-result (if (tramp--test-enabled) :passed :failed)
95 (should (ignore-errors
96 (and
97 (file-remote-p tramp-test-temporary-file-directory)
98 (file-directory-p tramp-test-temporary-file-directory)
99 (file-writable-p tramp-test-temporary-file-directory)))))
101 (ert-deftest tramp-test01-file-name-syntax ()
102 "Check remote file name syntax."
103 ;; Simple cases.
104 (should (tramp-tramp-file-p "/method::"))
105 (should (tramp-tramp-file-p "/host:"))
106 (should (tramp-tramp-file-p "/user@:"))
107 (should (tramp-tramp-file-p "/user@host:"))
108 (should (tramp-tramp-file-p "/method:host:"))
109 (should (tramp-tramp-file-p "/method:user@:"))
110 (should (tramp-tramp-file-p "/method:user@host:"))
111 (should (tramp-tramp-file-p "/method:user@email@host:"))
113 ;; Using a port.
114 (should (tramp-tramp-file-p "/host#1234:"))
115 (should (tramp-tramp-file-p "/user@host#1234:"))
116 (should (tramp-tramp-file-p "/method:host#1234:"))
117 (should (tramp-tramp-file-p "/method:user@host#1234:"))
119 ;; Using an IPv4 address.
120 (should (tramp-tramp-file-p "/1.2.3.4:"))
121 (should (tramp-tramp-file-p "/user@1.2.3.4:"))
122 (should (tramp-tramp-file-p "/method:1.2.3.4:"))
123 (should (tramp-tramp-file-p "/method:user@1.2.3.4:"))
125 ;; Using an IPv6 address.
126 (should (tramp-tramp-file-p "/[]:"))
127 (should (tramp-tramp-file-p "/[::1]:"))
128 (should (tramp-tramp-file-p "/user@[::1]:"))
129 (should (tramp-tramp-file-p "/method:[::1]:"))
130 (should (tramp-tramp-file-p "/method:user@[::1]:"))
132 ;; Local file name part.
133 (should (tramp-tramp-file-p "/host:/:"))
134 (should (tramp-tramp-file-p "/method:::"))
135 (should (tramp-tramp-file-p "/method::/path/to/file"))
136 (should (tramp-tramp-file-p "/method::file"))
138 ;; Multihop.
139 (should (tramp-tramp-file-p "/method1:|method2::"))
140 (should (tramp-tramp-file-p "/method1:host1|host2:"))
141 (should (tramp-tramp-file-p "/method1:host1|method2:host2:"))
142 (should (tramp-tramp-file-p "/method1:user1@host1|method2:user2@host2:"))
143 (should (tramp-tramp-file-p
144 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:"))
146 ;; No strings.
147 (should-not (tramp-tramp-file-p nil))
148 (should-not (tramp-tramp-file-p 'symbol))
149 ;; "/:" suppresses file name handlers.
150 (should-not (tramp-tramp-file-p "/::"))
151 (should-not (tramp-tramp-file-p "/:@:"))
152 (should-not (tramp-tramp-file-p "/:[]:"))
153 ;; Multihops require a method.
154 (should-not (tramp-tramp-file-p "/host1|host2:"))
155 ;; Methods or hostnames shall be at least two characters on MS Windows.
156 (when (memq system-type '(cygwin windows-nt))
157 (should-not (tramp-tramp-file-p "/c:/path/to/file"))
158 (should-not (tramp-tramp-file-p "/c::/path/to/file"))))
160 (ert-deftest tramp-test02-file-name-dissect ()
161 "Check remote file name components."
162 (let ((tramp-default-method "default-method")
163 (tramp-default-user "default-user")
164 (tramp-default-host "default-host"))
165 ;; Expand `tramp-default-user' and `tramp-default-host'.
166 (should (string-equal
167 (file-remote-p "/method::")
168 (format "/%s:%s@%s:" "method" "default-user" "default-host")))
169 (should (string-equal (file-remote-p "/method::" 'method) "method"))
170 (should (string-equal (file-remote-p "/method::" 'user) "default-user"))
171 (should (string-equal (file-remote-p "/method::" 'host) "default-host"))
172 (should (string-equal (file-remote-p "/method::" 'localname) ""))
174 ;; Expand `tramp-default-method' and `tramp-default-user'.
175 (should (string-equal
176 (file-remote-p "/host:")
177 (format "/%s:%s@%s:" "default-method" "default-user" "host")))
178 (should (string-equal (file-remote-p "/host:" 'method) "default-method"))
179 (should (string-equal (file-remote-p "/host:" 'user) "default-user"))
180 (should (string-equal (file-remote-p "/host:" 'host) "host"))
181 (should (string-equal (file-remote-p "/host:" 'localname) ""))
183 ;; Expand `tramp-default-method' and `tramp-default-host'.
184 (should (string-equal
185 (file-remote-p "/user@:")
186 (format "/%s:%s@%s:" "default-method""user" "default-host")))
187 (should (string-equal (file-remote-p "/user@:" 'method) "default-method"))
188 (should (string-equal (file-remote-p "/user@:" 'user) "user"))
189 (should (string-equal (file-remote-p "/user@:" 'host) "default-host"))
190 (should (string-equal (file-remote-p "/user@:" 'localname) ""))
192 ;; Expand `tramp-default-method'.
193 (should (string-equal
194 (file-remote-p "/user@host:")
195 (format "/%s:%s@%s:" "default-method" "user" "host")))
196 (should (string-equal
197 (file-remote-p "/user@host:" 'method) "default-method"))
198 (should (string-equal (file-remote-p "/user@host:" 'user) "user"))
199 (should (string-equal (file-remote-p "/user@host:" 'host) "host"))
200 (should (string-equal (file-remote-p "/user@host:" 'localname) ""))
202 ;; Expand `tramp-default-user'.
203 (should (string-equal
204 (file-remote-p "/method:host:")
205 (format "/%s:%s@%s:" "method" "default-user" "host")))
206 (should (string-equal (file-remote-p "/method:host:" 'method) "method"))
207 (should (string-equal (file-remote-p "/method:host:" 'user) "default-user"))
208 (should (string-equal (file-remote-p "/method:host:" 'host) "host"))
209 (should (string-equal (file-remote-p "/method:host:" 'localname) ""))
211 ;; Expand `tramp-default-host'.
212 (should (string-equal
213 (file-remote-p "/method:user@:")
214 (format "/%s:%s@%s:" "method" "user" "default-host")))
215 (should (string-equal (file-remote-p "/method:user@:" 'method) "method"))
216 (should (string-equal (file-remote-p "/method:user@:" 'user) "user"))
217 (should (string-equal (file-remote-p "/method:user@:" 'host)
218 "default-host"))
219 (should (string-equal (file-remote-p "/method:user@:" 'localname) ""))
221 ;; No expansion.
222 (should (string-equal
223 (file-remote-p "/method:user@host:")
224 (format "/%s:%s@%s:" "method" "user" "host")))
225 (should (string-equal
226 (file-remote-p "/method:user@host:" 'method) "method"))
227 (should (string-equal (file-remote-p "/method:user@host:" 'user) "user"))
228 (should (string-equal (file-remote-p "/method:user@host:" 'host) "host"))
229 (should (string-equal (file-remote-p "/method:user@host:" 'localname) ""))
231 ;; No expansion.
232 (should (string-equal
233 (file-remote-p "/method:user@email@host:")
234 (format "/%s:%s@%s:" "method" "user@email" "host")))
235 (should (string-equal
236 (file-remote-p "/method:user@email@host:" 'method) "method"))
237 (should (string-equal
238 (file-remote-p "/method:user@email@host:" 'user) "user@email"))
239 (should (string-equal
240 (file-remote-p "/method:user@email@host:" 'host) "host"))
241 (should (string-equal
242 (file-remote-p "/method:user@email@host:" 'localname) ""))
244 ;; Expand `tramp-default-method' and `tramp-default-user'.
245 (should (string-equal
246 (file-remote-p "/host#1234:")
247 (format "/%s:%s@%s:" "default-method" "default-user" "host#1234")))
248 (should (string-equal
249 (file-remote-p "/host#1234:" 'method) "default-method"))
250 (should (string-equal (file-remote-p "/host#1234:" 'user) "default-user"))
251 (should (string-equal (file-remote-p "/host#1234:" 'host) "host#1234"))
252 (should (string-equal (file-remote-p "/host#1234:" 'localname) ""))
254 ;; Expand `tramp-default-method'.
255 (should (string-equal
256 (file-remote-p "/user@host#1234:")
257 (format "/%s:%s@%s:" "default-method" "user" "host#1234")))
258 (should (string-equal
259 (file-remote-p "/user@host#1234:" 'method) "default-method"))
260 (should (string-equal (file-remote-p "/user@host#1234:" 'user) "user"))
261 (should (string-equal (file-remote-p "/user@host#1234:" 'host) "host#1234"))
262 (should (string-equal (file-remote-p "/user@host#1234:" 'localname) ""))
264 ;; Expand `tramp-default-user'.
265 (should (string-equal
266 (file-remote-p "/method:host#1234:")
267 (format "/%s:%s@%s:" "method" "default-user" "host#1234")))
268 (should (string-equal
269 (file-remote-p "/method:host#1234:" 'method) "method"))
270 (should (string-equal
271 (file-remote-p "/method:host#1234:" 'user) "default-user"))
272 (should (string-equal
273 (file-remote-p "/method:host#1234:" 'host) "host#1234"))
274 (should (string-equal (file-remote-p "/method:host#1234:" 'localname) ""))
276 ;; No expansion.
277 (should (string-equal
278 (file-remote-p "/method:user@host#1234:")
279 (format "/%s:%s@%s:" "method" "user" "host#1234")))
280 (should (string-equal
281 (file-remote-p "/method:user@host#1234:" 'method) "method"))
282 (should (string-equal
283 (file-remote-p "/method:user@host#1234:" 'user) "user"))
284 (should (string-equal
285 (file-remote-p "/method:user@host#1234:" 'host) "host#1234"))
286 (should (string-equal
287 (file-remote-p "/method:user@host#1234:" 'localname) ""))
289 ;; Expand `tramp-default-method' and `tramp-default-user'.
290 (should (string-equal
291 (file-remote-p "/1.2.3.4:")
292 (format "/%s:%s@%s:" "default-method" "default-user" "1.2.3.4")))
293 (should (string-equal (file-remote-p "/1.2.3.4:" 'method) "default-method"))
294 (should (string-equal (file-remote-p "/1.2.3.4:" 'user) "default-user"))
295 (should (string-equal (file-remote-p "/1.2.3.4:" 'host) "1.2.3.4"))
296 (should (string-equal (file-remote-p "/1.2.3.4:" 'localname) ""))
298 ;; Expand `tramp-default-method'.
299 (should (string-equal
300 (file-remote-p "/user@1.2.3.4:")
301 (format "/%s:%s@%s:" "default-method" "user" "1.2.3.4")))
302 (should (string-equal
303 (file-remote-p "/user@1.2.3.4:" 'method) "default-method"))
304 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'user) "user"))
305 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'host) "1.2.3.4"))
306 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'localname) ""))
308 ;; Expand `tramp-default-user'.
309 (should (string-equal
310 (file-remote-p "/method:1.2.3.4:")
311 (format "/%s:%s@%s:" "method" "default-user" "1.2.3.4")))
312 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'method) "method"))
313 (should (string-equal
314 (file-remote-p "/method:1.2.3.4:" 'user) "default-user"))
315 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'host) "1.2.3.4"))
316 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'localname) ""))
318 ;; No expansion.
319 (should (string-equal
320 (file-remote-p "/method:user@1.2.3.4:")
321 (format "/%s:%s@%s:" "method" "user" "1.2.3.4")))
322 (should (string-equal
323 (file-remote-p "/method:user@1.2.3.4:" 'method) "method"))
324 (should (string-equal (file-remote-p "/method:user@1.2.3.4:" 'user) "user"))
325 (should (string-equal
326 (file-remote-p "/method:user@1.2.3.4:" 'host) "1.2.3.4"))
327 (should (string-equal
328 (file-remote-p "/method:user@1.2.3.4:" 'localname) ""))
330 ;; Expand `tramp-default-method', `tramp-default-user' and
331 ;; `tramp-default-host'.
332 (should (string-equal
333 (file-remote-p "/[]:")
334 (format
335 "/%s:%s@%s:" "default-method" "default-user" "default-host")))
336 (should (string-equal (file-remote-p "/[]:" 'method) "default-method"))
337 (should (string-equal (file-remote-p "/[]:" 'user) "default-user"))
338 (should (string-equal (file-remote-p "/[]:" 'host) "default-host"))
339 (should (string-equal (file-remote-p "/[]:" 'localname) ""))
341 ;; Expand `tramp-default-method' and `tramp-default-user'.
342 (let ((tramp-default-host "::1"))
343 (should (string-equal
344 (file-remote-p "/[]:")
345 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
346 (should (string-equal (file-remote-p "/[]:" 'method) "default-method"))
347 (should (string-equal (file-remote-p "/[]:" 'user) "default-user"))
348 (should (string-equal (file-remote-p "/[]:" 'host) "::1"))
349 (should (string-equal (file-remote-p "/[]:" 'localname) "")))
351 ;; Expand `tramp-default-method' and `tramp-default-user'.
352 (should (string-equal
353 (file-remote-p "/[::1]:")
354 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
355 (should (string-equal (file-remote-p "/[::1]:" 'method) "default-method"))
356 (should (string-equal (file-remote-p "/[::1]:" 'user) "default-user"))
357 (should (string-equal (file-remote-p "/[::1]:" 'host) "::1"))
358 (should (string-equal (file-remote-p "/[::1]:" 'localname) ""))
360 ;; Expand `tramp-default-method'.
361 (should (string-equal
362 (file-remote-p "/user@[::1]:")
363 (format "/%s:%s@%s:" "default-method" "user" "[::1]")))
364 (should (string-equal
365 (file-remote-p "/user@[::1]:" 'method) "default-method"))
366 (should (string-equal (file-remote-p "/user@[::1]:" 'user) "user"))
367 (should (string-equal (file-remote-p "/user@[::1]:" 'host) "::1"))
368 (should (string-equal (file-remote-p "/user@[::1]:" 'localname) ""))
370 ;; Expand `tramp-default-user'.
371 (should (string-equal
372 (file-remote-p "/method:[::1]:")
373 (format "/%s:%s@%s:" "method" "default-user" "[::1]")))
374 (should (string-equal (file-remote-p "/method:[::1]:" 'method) "method"))
375 (should (string-equal
376 (file-remote-p "/method:[::1]:" 'user) "default-user"))
377 (should (string-equal (file-remote-p "/method:[::1]:" 'host) "::1"))
378 (should (string-equal (file-remote-p "/method:[::1]:" 'localname) ""))
380 ;; No expansion.
381 (should (string-equal
382 (file-remote-p "/method:user@[::1]:")
383 (format "/%s:%s@%s:" "method" "user" "[::1]")))
384 (should (string-equal
385 (file-remote-p "/method:user@[::1]:" 'method) "method"))
386 (should (string-equal (file-remote-p "/method:user@[::1]:" 'user) "user"))
387 (should (string-equal (file-remote-p "/method:user@[::1]:" 'host) "::1"))
388 (should (string-equal
389 (file-remote-p "/method:user@[::1]:" 'localname) ""))
391 ;; Local file name part.
392 (should (string-equal (file-remote-p "/host:/:" 'localname) "/:"))
393 (should (string-equal (file-remote-p "/method:::" 'localname) ":"))
394 (should (string-equal (file-remote-p "/method:: " 'localname) " "))
395 (should (string-equal (file-remote-p "/method::file" 'localname) "file"))
396 (should (string-equal
397 (file-remote-p "/method::/path/to/file" 'localname)
398 "/path/to/file"))
400 ;; Multihop.
401 (should
402 (string-equal
403 (file-remote-p "/method1:user1@host1|method2:user2@host2:/path/to/file")
404 (format "/%s:%s@%s:" "method2" "user2" "host2")))
405 (should
406 (string-equal
407 (file-remote-p
408 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'method)
409 "method2"))
410 (should
411 (string-equal
412 (file-remote-p
413 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'user)
414 "user2"))
415 (should
416 (string-equal
417 (file-remote-p
418 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'host)
419 "host2"))
420 (should
421 (string-equal
422 (file-remote-p
423 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'localname)
424 "/path/to/file"))
426 (should
427 (string-equal
428 (file-remote-p
429 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file")
430 (format "/%s:%s@%s:" "method3" "user3" "host3")))
431 (should
432 (string-equal
433 (file-remote-p
434 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
435 'method)
436 "method3"))
437 (should
438 (string-equal
439 (file-remote-p
440 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
441 'user)
442 "user3"))
443 (should
444 (string-equal
445 (file-remote-p
446 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
447 'host)
448 "host3"))
449 (should
450 (string-equal
451 (file-remote-p
452 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
453 'localname)
454 "/path/to/file"))))
456 (ert-deftest tramp-test03-file-name-defaults ()
457 "Check default values for some methods."
458 ;; Default values in tramp-adb.el.
459 (should (string-equal (file-remote-p "/adb::" 'host) ""))
460 ;; Default values in tramp-ftp.el.
461 (should (string-equal (file-remote-p "/ftp.host:" 'method) "ftp"))
462 (dolist (u '("ftp" "anonymous"))
463 (should (string-equal (file-remote-p (format "/%s@:" u) 'method) "ftp")))
464 ;; Default values in tramp-gvfs.el.
465 (when (and (load "tramp-gvfs" 'noerror 'nomessage)
466 (symbol-value 'tramp-gvfs-enabled))
467 (should (string-equal (file-remote-p "/synce::" 'user) nil)))
468 ;; Default values in tramp-gw.el.
469 (dolist (m '("tunnel" "socks"))
470 (should
471 (string-equal (file-remote-p (format "/%s::" m) 'user) (user-login-name))))
472 ;; Default values in tramp-sh.el.
473 (dolist (h `("127.0.0.1" "[::1]" "localhost" "localhost6" ,(system-name)))
474 (should (string-equal (file-remote-p (format "/root@%s:" h) 'method) "su")))
475 (dolist (m '("su" "sudo" "ksu"))
476 (should (string-equal (file-remote-p (format "/%s::" m) 'user) "root")))
477 (dolist (m '("rcp" "remcp" "rsh" "telnet" "krlogin" "fcp"))
478 (should
479 (string-equal (file-remote-p (format "/%s::" m) 'user) (user-login-name))))
480 ;; Default values in tramp-smb.el.
481 (should (string-equal (file-remote-p "/user%domain@host:" 'method) "smb"))
482 (should (string-equal (file-remote-p "/smb::" 'user) nil)))
484 (ert-deftest tramp-test04-substitute-in-file-name ()
485 "Check `substitute-in-file-name'."
486 (should (string-equal (substitute-in-file-name "/method:host://foo") "/foo"))
487 (should
488 (string-equal
489 (substitute-in-file-name "/method:host:/path//foo") "/method:host:/foo"))
490 (should
491 (string-equal (substitute-in-file-name "/method:host:/path///foo") "/foo"))
492 (should
493 (string-equal
494 (substitute-in-file-name "/method:host:/path/~/foo") "/method:host:~/foo"))
495 (should
496 (string-equal (substitute-in-file-name "/method:host:/path//~/foo") "~/foo"))
497 (let (process-environment)
498 (should
499 (string-equal
500 (substitute-in-file-name "/method:host:/path/$FOO")
501 "/method:host:/path/$FOO"))
502 (setenv "FOO" "bla")
503 (should
504 (string-equal
505 (substitute-in-file-name "/method:host:/path/$FOO")
506 "/method:host:/path/bla"))
507 (should
508 (string-equal
509 (substitute-in-file-name "/method:host:/path/$$FOO")
510 "/method:host:/path/$FOO"))))
512 (ert-deftest tramp-test05-expand-file-name ()
513 "Check `expand-file-name'."
514 (should
515 (string-equal
516 (expand-file-name "/method:host:/path/./file") "/method:host:/path/file"))
517 (should
518 (string-equal
519 (expand-file-name "/method:host:/path/../file") "/method:host:/file")))
521 (ert-deftest tramp-test06-directory-file-name ()
522 "Check `directory-file-name'.
523 This checks also `file-name-as-directory', `file-name-directory'
524 and `file-name-nondirectory'."
525 (should
526 (string-equal
527 (directory-file-name "/method:host:/path/to/file")
528 "/method:host:/path/to/file"))
529 (should
530 (string-equal
531 (directory-file-name "/method:host:/path/to/file/")
532 "/method:host:/path/to/file"))
533 (should
534 (string-equal
535 (file-name-as-directory "/method:host:/path/to/file")
536 "/method:host:/path/to/file/"))
537 (should
538 (string-equal
539 (file-name-as-directory "/method:host:/path/to/file/")
540 "/method:host:/path/to/file/"))
541 (should
542 (string-equal
543 (file-name-directory "/method:host:/path/to/file")
544 "/method:host:/path/to/"))
545 (should
546 (string-equal
547 (file-name-directory "/method:host:/path/to/file/")
548 "/method:host:/path/to/file/"))
549 (should
550 (string-equal (file-name-nondirectory "/method:host:/path/to/file") "file"))
551 (should
552 (string-equal (file-name-nondirectory "/method:host:/path/to/file/") ""))
553 (should-not
554 (file-remote-p
555 (unhandled-file-name-directory "/method:host:/path/to/file"))))
557 (ert-deftest tramp-test07-file-exists-p ()
558 "Check `file-exist-p', `write-region' and `delete-file'."
559 (skip-unless (tramp--test-enabled))
560 (tramp-cleanup-connection
561 (tramp-dissect-file-name tramp-test-temporary-file-directory)
562 nil 'keep-password)
564 (let ((tmp-name (tramp--test-make-temp-name)))
565 (should-not (file-exists-p tmp-name))
566 (write-region "foo" nil tmp-name)
567 (should (file-exists-p tmp-name))
568 (delete-file tmp-name)
569 (should-not (file-exists-p tmp-name))))
571 (ert-deftest tramp-test08-file-local-copy ()
572 "Check `file-local-copy'."
573 (skip-unless (tramp--test-enabled))
574 (tramp-cleanup-connection
575 (tramp-dissect-file-name tramp-test-temporary-file-directory)
576 nil 'keep-password)
578 (let ((tmp-name1 (tramp--test-make-temp-name))
579 tmp-name2)
580 (unwind-protect
581 (progn
582 (write-region "foo" nil tmp-name1)
583 (should (setq tmp-name2 (file-local-copy tmp-name1)))
584 (with-temp-buffer
585 (insert-file-contents tmp-name2)
586 (should (string-equal (buffer-string) "foo"))))
587 (ignore-errors
588 (delete-file tmp-name1)
589 (delete-file tmp-name2)))))
591 (ert-deftest tramp-test09-insert-file-contents ()
592 "Check `insert-file-contents'."
593 (skip-unless (tramp--test-enabled))
594 (tramp-cleanup-connection
595 (tramp-dissect-file-name tramp-test-temporary-file-directory)
596 nil 'keep-password)
598 (let ((tmp-name (tramp--test-make-temp-name)))
599 (unwind-protect
600 (progn
601 (write-region "foo" nil tmp-name)
602 (with-temp-buffer
603 (insert-file-contents tmp-name)
604 (should (string-equal (buffer-string) "foo"))
605 (insert-file-contents tmp-name)
606 (should (string-equal (buffer-string) "foofoo"))
607 ;; Insert partly.
608 (insert-file-contents tmp-name nil 1 3)
609 (should (string-equal (buffer-string) "oofoofoo"))
610 ;; Replace.
611 (insert-file-contents tmp-name nil nil nil 'replace)
612 (should (string-equal (buffer-string) "foo"))))
613 (ignore-errors (delete-file tmp-name)))))
615 (ert-deftest tramp-test10-write-region ()
616 "Check `write-region'."
617 (skip-unless (tramp--test-enabled))
618 (tramp-cleanup-connection
619 (tramp-dissect-file-name tramp-test-temporary-file-directory)
620 nil 'keep-password)
622 (let ((tmp-name (tramp--test-make-temp-name)))
623 (unwind-protect
624 (progn
625 (with-temp-buffer
626 (insert "foo")
627 (write-region nil nil tmp-name))
628 (with-temp-buffer
629 (insert-file-contents tmp-name)
630 (should (string-equal (buffer-string) "foo")))
631 ;; Append.
632 (with-temp-buffer
633 (insert "bla")
634 (write-region nil nil tmp-name 'append))
635 (with-temp-buffer
636 (insert-file-contents tmp-name)
637 (should (string-equal (buffer-string) "foobla")))
638 ;; Write string.
639 (write-region "foo" nil tmp-name)
640 (with-temp-buffer
641 (insert-file-contents tmp-name)
642 (should (string-equal (buffer-string) "foo")))
643 ;; Write partly.
644 (with-temp-buffer
645 (insert "123456789")
646 (write-region 3 5 tmp-name))
647 (with-temp-buffer
648 (insert-file-contents tmp-name)
649 (should (string-equal (buffer-string) "34"))))
650 (ignore-errors (delete-file tmp-name)))))
652 (ert-deftest tramp-test11-copy-file ()
653 "Check `copy-file'."
654 (skip-unless (tramp--test-enabled))
655 (tramp-cleanup-connection
656 (tramp-dissect-file-name tramp-test-temporary-file-directory)
657 nil 'keep-password)
659 (let ((tmp-name1 (tramp--test-make-temp-name))
660 (tmp-name2 (tramp--test-make-temp-name)))
661 (unwind-protect
662 (progn
663 (write-region "foo" nil tmp-name1)
664 (copy-file tmp-name1 tmp-name2)
665 (should (file-exists-p tmp-name2))
666 (with-temp-buffer
667 (insert-file-contents tmp-name2)
668 (should (string-equal (buffer-string) "foo"))))
669 (ignore-errors
670 (delete-file tmp-name1)
671 (delete-file tmp-name2)))))
673 (ert-deftest tramp-test12-rename-file ()
674 "Check `rename-file'."
675 (skip-unless (tramp--test-enabled))
676 (tramp-cleanup-connection
677 (tramp-dissect-file-name tramp-test-temporary-file-directory)
678 nil 'keep-password)
680 (let ((tmp-name1 (tramp--test-make-temp-name))
681 (tmp-name2 (tramp--test-make-temp-name)))
682 (unwind-protect
683 (progn
684 (write-region "foo" nil tmp-name1)
685 (rename-file tmp-name1 tmp-name2)
686 (should-not (file-exists-p tmp-name1))
687 (should (file-exists-p tmp-name2))
688 (with-temp-buffer
689 (insert-file-contents tmp-name2)
690 (should (string-equal (buffer-string) "foo"))))
691 (ignore-errors (delete-file tmp-name2)))))
693 (ert-deftest tramp-test13-make-directory ()
694 "Check `make-directory'.
695 This tests also `file-directory-p' and `file-accessible-directory-p'."
696 (skip-unless (tramp--test-enabled))
697 (tramp-cleanup-connection
698 (tramp-dissect-file-name tramp-test-temporary-file-directory)
699 nil 'keep-password)
701 (let ((tmp-name (tramp--test-make-temp-name)))
702 (unwind-protect
703 (progn
704 (make-directory tmp-name)
705 (should (file-directory-p tmp-name))
706 (should (file-accessible-directory-p tmp-name)))
707 (ignore-errors (delete-directory tmp-name)))))
709 (ert-deftest tramp-test14-delete-directory ()
710 "Check `delete-directory'."
711 (skip-unless (tramp--test-enabled))
712 (tramp-cleanup-connection
713 (tramp-dissect-file-name tramp-test-temporary-file-directory)
714 nil 'keep-password)
716 (let ((tmp-name (tramp--test-make-temp-name)))
717 ;; Delete empty directory.
718 (make-directory tmp-name)
719 (should (file-directory-p tmp-name))
720 (delete-directory tmp-name)
721 (should-not (file-directory-p tmp-name))
722 ;; Delete non-empty directory.
723 (make-directory tmp-name)
724 (write-region "foo" nil (expand-file-name "bla" tmp-name))
725 (should-error (delete-directory tmp-name))
726 (delete-directory tmp-name 'recursive)
727 (should-not (file-directory-p tmp-name))))
729 (ert-deftest tramp-test15-copy-directory ()
730 "Check `copy-directory'."
731 (skip-unless (tramp--test-enabled))
732 (tramp-cleanup-connection
733 (tramp-dissect-file-name tramp-test-temporary-file-directory)
734 nil 'keep-password)
736 (let* ((tmp-name1 (tramp--test-make-temp-name))
737 (tmp-name2 (tramp--test-make-temp-name))
738 (tmp-name3 (expand-file-name
739 (file-name-nondirectory tmp-name1) tmp-name2))
740 (tmp-name4 (expand-file-name "foo" tmp-name1))
741 (tmp-name5 (expand-file-name "foo" tmp-name2))
742 (tmp-name6 (expand-file-name "foo" tmp-name3)))
743 (unwind-protect
744 (progn
745 ;; Copy empty directory.
746 (make-directory tmp-name1)
747 (write-region "foo" nil tmp-name4)
748 (should (file-directory-p tmp-name1))
749 (should (file-exists-p tmp-name4))
750 (copy-directory tmp-name1 tmp-name2)
751 (should (file-directory-p tmp-name2))
752 (should (file-exists-p tmp-name5))
753 ;; Target directory does exist already.
754 (copy-directory tmp-name1 tmp-name2)
755 (should (file-directory-p tmp-name3))
756 (should (file-exists-p tmp-name6)))
757 (ignore-errors
758 (delete-directory tmp-name1 'recursive)
759 (delete-directory tmp-name2 'recursive)))))
761 (ert-deftest tramp-test16-directory-files ()
762 "Check `directory-files'."
763 (skip-unless (tramp--test-enabled))
764 (tramp-cleanup-connection
765 (tramp-dissect-file-name tramp-test-temporary-file-directory)
766 nil 'keep-password)
768 (let* ((tmp-name1 (tramp--test-make-temp-name))
769 (tmp-name2 (expand-file-name "bla" tmp-name1))
770 (tmp-name3 (expand-file-name "foo" tmp-name1)))
771 (unwind-protect
772 (progn
773 (make-directory tmp-name1)
774 (write-region "foo" nil tmp-name2)
775 (write-region "bla" nil tmp-name3)
776 (should (file-directory-p tmp-name1))
777 (should (file-exists-p tmp-name2))
778 (should (file-exists-p tmp-name3))
779 (should (equal (directory-files tmp-name1) '("." ".." "bla" "foo")))
780 (should (equal (directory-files tmp-name1 'full)
781 `(,(concat tmp-name1 "/.")
782 ,(concat tmp-name1 "/..")
783 ,tmp-name2 ,tmp-name3)))
784 (should (equal (directory-files
785 tmp-name1 nil directory-files-no-dot-files-regexp)
786 '("bla" "foo")))
787 (should (equal (directory-files
788 tmp-name1 'full directory-files-no-dot-files-regexp)
789 `(,tmp-name2 ,tmp-name3))))
790 (ignore-errors (delete-directory tmp-name1 'recursive)))))
792 (ert-deftest tramp-test17-insert-directory ()
793 "Check `insert-directory'."
794 (skip-unless (tramp--test-enabled))
795 (tramp-cleanup-connection
796 (tramp-dissect-file-name tramp-test-temporary-file-directory)
797 nil 'keep-password)
799 (let* ((tmp-name1 (tramp--test-make-temp-name))
800 (tmp-name2 (expand-file-name "foo" tmp-name1)))
801 (unwind-protect
802 (progn
803 (make-directory tmp-name1)
804 (write-region "foo" nil tmp-name2)
805 (should (file-directory-p tmp-name1))
806 (should (file-exists-p tmp-name2))
807 (with-temp-buffer
808 (insert-directory tmp-name1 nil)
809 (goto-char (point-min))
810 (should (looking-at-p (regexp-quote tmp-name1))))
811 (with-temp-buffer
812 (insert-directory tmp-name1 "-al")
813 (goto-char (point-min))
814 (should (looking-at-p (format "^.+ %s$" (regexp-quote tmp-name1)))))
815 (with-temp-buffer
816 (insert-directory (file-name-as-directory tmp-name1) "-al")
817 (goto-char (point-min))
818 (should
819 (looking-at-p (format "^.+ %s/$" (regexp-quote tmp-name1)))))
820 (with-temp-buffer
821 (insert-directory
822 (file-name-as-directory tmp-name1) "-al" nil 'full-directory-p)
823 (goto-char (point-min))
824 (should
825 (looking-at-p "total +[[:digit:]]+\n.+ \\.\n.+ \\.\\.\n.+ foo$"))))
826 (ignore-errors (delete-directory tmp-name1 'recursive)))))
828 (ert-deftest tramp-test18-file-attributes ()
829 "Check `file-attributes'.
830 This tests also `file-readable-p' and `file-regular-p'."
831 (skip-unless (tramp--test-enabled))
832 (tramp-cleanup-connection
833 (tramp-dissect-file-name tramp-test-temporary-file-directory)
834 nil 'keep-password)
836 (let ((tmp-name (tramp--test-make-temp-name))
837 attr)
838 (unwind-protect
839 (progn
840 (write-region "foo" nil tmp-name)
841 (should (file-exists-p tmp-name))
842 (setq attr (file-attributes tmp-name))
843 (should (consp attr))
844 (should (file-exists-p tmp-name))
845 (should (file-readable-p tmp-name))
846 (should (file-regular-p tmp-name))
847 ;; We do not test inodes and device numbers.
848 (should (null (car attr)))
849 (should (numberp (nth 1 attr))) ;; Link.
850 (should (numberp (nth 2 attr))) ;; Uid.
851 (should (numberp (nth 3 attr))) ;; Gid.
852 ;; Last access time.
853 (should (stringp (current-time-string (nth 4 attr))))
854 ;; Last modification time.
855 (should (stringp (current-time-string (nth 5 attr))))
856 ;; Last status change time.
857 (should (stringp (current-time-string (nth 6 attr))))
858 (should (numberp (nth 7 attr))) ;; Size.
859 (should (stringp (nth 8 attr))) ;; Modes.
861 (setq attr (file-attributes tmp-name 'string))
862 (should (stringp (nth 2 attr))) ;; Uid.
863 (should (stringp (nth 3 attr))) ;; Gid.
864 (delete-file tmp-name)
866 (make-directory tmp-name)
867 (should (file-exists-p tmp-name))
868 (should (file-readable-p tmp-name))
869 (should-not (file-regular-p tmp-name))
870 (setq attr (file-attributes tmp-name))
871 (should (eq (car attr) t)))
872 (ignore-errors (delete-directory tmp-name)))))
874 (ert-deftest tramp-test19-directory-files-and-attributes ()
875 "Check `directory-files-and-attributes'."
876 (skip-unless (tramp--test-enabled))
877 (tramp-cleanup-connection
878 (tramp-dissect-file-name tramp-test-temporary-file-directory)
879 nil 'keep-password)
881 (let ((tmp-name (tramp--test-make-temp-name))
882 attr)
883 (unwind-protect
884 (progn
885 (make-directory tmp-name)
886 (should (file-directory-p tmp-name))
887 (write-region "foo" nil (expand-file-name "foo" tmp-name))
888 (write-region "bar" nil (expand-file-name "bar" tmp-name))
889 (write-region "boz" nil (expand-file-name "boz" tmp-name))
890 (setq attr (directory-files-and-attributes tmp-name))
891 (should (consp attr))
892 (dolist (elt attr)
893 (should
894 (equal (file-attributes (expand-file-name (car elt) tmp-name))
895 (cdr elt))))
896 (setq attr (directory-files-and-attributes tmp-name 'full))
897 (dolist (elt attr)
898 (should
899 (equal (file-attributes (car elt)) (cdr elt))))
900 (setq attr (directory-files-and-attributes tmp-name nil "^b"))
901 (should (equal (mapcar 'car attr) '("bar" "boz"))))
902 (ignore-errors (delete-directory tmp-name 'recursive)))))
904 (ert-deftest tramp-test20-file-modes ()
905 "Check `file-modes'.
906 This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
907 (skip-unless (tramp--test-enabled))
908 (tramp-cleanup-connection
909 (tramp-dissect-file-name tramp-test-temporary-file-directory)
910 nil 'keep-password)
912 (let ((tmp-name (tramp--test-make-temp-name)))
913 (unwind-protect
914 (progn
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 (unless (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))
933 (tramp-cleanup-connection
934 (tramp-dissect-file-name tramp-test-temporary-file-directory)
935 nil 'keep-password)
937 (let ((tmp-name1 (tramp--test-make-temp-name))
938 (tmp-name2 (tramp--test-make-temp-name))
939 (tmp-name3 (make-temp-name "tramp-")))
940 (unwind-protect
941 (progn
942 (write-region "foo" nil tmp-name1)
943 (should (file-exists-p tmp-name1))
944 (make-symbolic-link tmp-name1 tmp-name2)
945 (should (file-symlink-p tmp-name2))
946 (should-error (make-symbolic-link tmp-name1 tmp-name2))
947 (make-symbolic-link tmp-name1 tmp-name2 'ok-if-already-exists)
948 (should (file-symlink-p tmp-name2))
949 ;; `tmp-name3' is a local file name.
950 (should-error (make-symbolic-link tmp-name1 tmp-name3)))
951 (ignore-errors
952 (delete-file tmp-name1)
953 (delete-file tmp-name2)))
955 (unwind-protect
956 (progn
957 (write-region "foo" nil tmp-name1)
958 (should (file-exists-p tmp-name1))
959 (add-name-to-file tmp-name1 tmp-name2)
960 (should-not (file-symlink-p tmp-name2))
961 (should-error (add-name-to-file tmp-name1 tmp-name2))
962 (add-name-to-file tmp-name1 tmp-name2 'ok-if-already-exists)
963 (should-not (file-symlink-p tmp-name2))
964 ;; `tmp-name3' is a local file name.
965 (should-error (add-name-to-file tmp-name1 tmp-name3)))
966 (ignore-errors
967 (delete-file tmp-name1)
968 (delete-file tmp-name2)))
970 (unwind-protect
971 (progn
972 (write-region "foo" nil tmp-name1)
973 (should (file-exists-p tmp-name1))
974 (make-symbolic-link tmp-name1 tmp-name2)
975 (should (file-symlink-p tmp-name2))
976 (should-not (string-equal tmp-name2 (file-truename tmp-name2)))
977 (should
978 (string-equal (file-truename tmp-name1) (file-truename tmp-name2))))
979 (ignore-errors
980 (delete-file tmp-name1)
981 (delete-file tmp-name2)))))
983 (ert-deftest tramp-test22-file-times ()
984 "Check `set-file-times' and `file-newer-than-file-p'."
985 (skip-unless (tramp--test-enabled))
986 (tramp-cleanup-connection
987 (tramp-dissect-file-name tramp-test-temporary-file-directory)
988 nil 'keep-password)
990 (let ((tmp-name1 (tramp--test-make-temp-name))
991 (tmp-name2 (tramp--test-make-temp-name))
992 (tmp-name3 (tramp--test-make-temp-name)))
993 (unwind-protect
994 (progn
995 (write-region "foo" nil tmp-name1)
996 (should (file-exists-p tmp-name1))
997 (should (consp (nth 5 (file-attributes tmp-name1))))
998 ;; '(0 0) means don't know, and will be replaced by `current-time'.
999 (set-file-times tmp-name1 '(0 1))
1000 (should (equal (nth 5 (file-attributes tmp-name1)) '(0 1)))
1001 (write-region "bla" nil tmp-name2)
1002 (should (file-exists-p tmp-name2))
1003 (should (file-newer-than-file-p tmp-name2 tmp-name1))
1004 ;; `tmp-name3' does not exist.
1005 (should (file-newer-than-file-p tmp-name2 tmp-name3))
1006 (should-not (file-newer-than-file-p tmp-name3 tmp-name1)))
1007 (ignore-errors
1008 (delete-file tmp-name1)
1009 (delete-file tmp-name2)))))
1011 (ert-deftest tramp-test23-visited-file-modtime ()
1012 "Check `set-visited-file-modtime' and `verify-visited-file-modtime'."
1013 (skip-unless (tramp--test-enabled))
1014 (tramp-cleanup-connection
1015 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1016 nil 'keep-password)
1018 (let ((tmp-name (tramp--test-make-temp-name)))
1019 (unwind-protect
1020 (progn
1021 (write-region "foo" nil tmp-name)
1022 (should (file-exists-p tmp-name))
1023 (with-temp-buffer
1024 (insert-file-contents tmp-name)
1025 (should (verify-visited-file-modtime))
1026 (set-visited-file-modtime '(0 1))
1027 (should (verify-visited-file-modtime))
1028 (should (equal (visited-file-modtime) '(0 1 0 0)))))
1029 (ignore-errors (delete-file tmp-name)))))
1031 (ert-deftest tramp-test24-file-name-completion ()
1032 "Check `file-name-completion' and `file-name-all-completions'."
1033 (skip-unless (tramp--test-enabled))
1034 (tramp-cleanup-connection
1035 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1036 nil 'keep-password)
1038 (let ((tmp-name (tramp--test-make-temp-name)))
1039 (unwind-protect
1040 (progn
1041 (make-directory tmp-name)
1042 (should (file-directory-p tmp-name))
1043 (write-region "foo" nil (expand-file-name "foo" tmp-name))
1044 (write-region "bar" nil (expand-file-name "bold" tmp-name))
1045 (make-directory (expand-file-name "boz" tmp-name))
1046 (should (equal (file-name-completion "fo" tmp-name) "foo"))
1047 (should (equal (file-name-completion "b" tmp-name) "bo"))
1048 (should
1049 (equal (file-name-completion "b" tmp-name 'file-directory-p) "boz/"))
1050 (should (equal (file-name-all-completions "fo" tmp-name) '("foo")))
1051 (should
1052 (equal (sort (file-name-all-completions "b" tmp-name) 'string-lessp)
1053 '("bold" "boz/"))))
1054 (ignore-errors (delete-directory tmp-name 'recursive)))))
1056 (ert-deftest tramp-test25-load ()
1057 "Check `load'."
1058 (skip-unless (tramp--test-enabled))
1059 (tramp-cleanup-connection
1060 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1061 nil 'keep-password)
1063 (let ((tmp-name (tramp--test-make-temp-name)))
1064 (unwind-protect
1065 (progn
1066 (load tmp-name 'noerror 'nomessage)
1067 (should-not (featurep 'tramp-test-load))
1068 (write-region "(provide 'tramp-test-load)" nil tmp-name)
1069 ;; `load' in lread.c does not pass `must-suffix'. Why?
1070 ;(should-error (load tmp-name nil 'nomessage 'nosuffix 'must-suffix))
1071 (load tmp-name nil 'nomessage 'nosuffix)
1072 (should (featurep 'tramp-test-load)))
1073 (ignore-errors
1074 (and (featurep 'tramp-test-load) (unload-feature 'tramp-test-load))
1075 (delete-file tmp-name)))))
1077 (ert-deftest tramp-test26-process-file ()
1078 "Check `process-file'."
1079 (skip-unless (tramp--test-enabled))
1080 (tramp-cleanup-connection
1081 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1082 nil 'keep-password)
1084 (let ((tmp-name (tramp--test-make-temp-name))
1085 (default-directory tramp-test-temporary-file-directory))
1086 (unwind-protect
1087 (progn
1088 ;; We cannot use "/bin/true" and "/bin/false"; those paths
1089 ;; do not exist on hydra.
1090 (should (zerop (process-file "true")))
1091 (should-not (zerop (process-file "false")))
1092 (should-not (zerop (process-file "binary-does-not-exist")))
1093 (with-temp-buffer
1094 (write-region "foo" nil tmp-name)
1095 (should (file-exists-p tmp-name))
1096 (should
1097 (zerop
1098 (process-file "ls" nil t nil (file-name-nondirectory tmp-name))))
1099 (should
1100 (string-equal
1101 (format "%s\n" (file-name-nondirectory tmp-name))
1102 (buffer-string)))))
1103 (ignore-errors (delete-file tmp-name)))))
1105 (ert-deftest tramp-test27-start-file-process ()
1106 "Check `start-file-process'."
1107 (skip-unless (tramp--test-enabled))
1108 (tramp-cleanup-connection
1109 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1110 nil 'keep-password)
1112 (let ((default-directory tramp-test-temporary-file-directory)
1113 (tmp-name (tramp--test-make-temp-name))
1114 kill-buffer-query-functions proc)
1115 (unwind-protect
1116 (with-temp-buffer
1117 (setq proc (start-file-process "test1" (current-buffer) "cat"))
1118 (should (processp proc))
1119 (should (equal (process-status proc) 'run))
1120 (process-send-string proc "foo")
1121 (process-send-eof proc)
1122 (accept-process-output proc 1)
1123 (should (string-equal (buffer-string) "foo")))
1124 (ignore-errors (delete-process proc)))
1126 (unwind-protect
1127 (with-temp-buffer
1128 (write-region "foo" nil tmp-name)
1129 (should (file-exists-p tmp-name))
1130 (setq proc
1131 (start-file-process
1132 "test2" (current-buffer)
1133 "cat" (file-name-nondirectory tmp-name)))
1134 (should (processp proc))
1135 (accept-process-output proc 1)
1136 (should (string-equal (buffer-string) "foo")))
1137 (ignore-errors
1138 (delete-process proc)
1139 (delete-file tmp-name)))
1141 (unwind-protect
1142 (progn
1143 (setq proc (start-file-process "test3" nil "cat"))
1144 (should (processp proc))
1145 (should (equal (process-status proc) 'run))
1146 (set-process-filter
1147 proc (lambda (_p s) (should (string-equal s "foo"))))
1148 (process-send-string proc "foo")
1149 (process-send-eof proc)
1150 (accept-process-output proc 1))
1151 (ignore-errors (delete-process proc)))))
1153 (ert-deftest tramp-test28-shell-command ()
1154 "Check `shell-command'."
1155 (skip-unless (tramp--test-enabled))
1156 (tramp-cleanup-connection
1157 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1158 nil 'keep-password)
1160 (let ((tmp-name (tramp--test-make-temp-name))
1161 (default-directory tramp-test-temporary-file-directory))
1162 (unwind-protect
1163 (with-temp-buffer
1164 (write-region "foo" nil tmp-name)
1165 (should (file-exists-p tmp-name))
1166 (shell-command
1167 (format "ls %s" (file-name-nondirectory tmp-name)) (current-buffer))
1168 (should
1169 (string-equal
1170 (format "%s\n" (file-name-nondirectory tmp-name)) (buffer-string))))
1171 (ignore-errors (delete-file tmp-name)))
1173 (unwind-protect
1174 (with-temp-buffer
1175 (write-region "foo" nil tmp-name)
1176 (should (file-exists-p tmp-name))
1177 (async-shell-command
1178 (format "ls %s" (file-name-nondirectory tmp-name)) (current-buffer))
1179 (sit-for 1 'nodisplay)
1180 (while (ignore-errors
1181 (memq (process-status (get-buffer-process (current-buffer)))
1182 '(run open)))
1183 (sit-for 1 'nodisplay))
1184 (should
1185 (string-equal
1186 (format "%s\n" (file-name-nondirectory tmp-name)) (buffer-string))))
1187 (ignore-errors (delete-file tmp-name)))
1189 (unwind-protect
1190 (with-temp-buffer
1191 (write-region "foo" nil tmp-name)
1192 (should (file-exists-p tmp-name))
1193 (async-shell-command "read line; ls $line" (current-buffer))
1194 (process-send-string
1195 (get-buffer-process (current-buffer))
1196 (format "%s\n" (file-name-nondirectory tmp-name)))
1197 (sit-for 1 'nodisplay)
1198 (while (ignore-errors
1199 (memq (process-status (get-buffer-process (current-buffer)))
1200 '(run open)))
1201 (sit-for 1 'nodisplay))
1202 (should
1203 (string-equal
1204 (format "%s\n" (file-name-nondirectory tmp-name)) (buffer-string))))
1205 (ignore-errors (delete-file tmp-name)))))
1207 (ert-deftest tramp-test29-vc-registered ()
1208 "Check `vc-registered'."
1209 (skip-unless (tramp--test-enabled))
1210 (skip-unless
1212 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory)
1213 'tramp-sh-file-name-handler))
1214 (tramp-cleanup-connection
1215 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1216 nil 'keep-password)
1218 (let* ((default-directory tramp-test-temporary-file-directory)
1219 (tmp-name1 (tramp--test-make-temp-name))
1220 (tmp-name2 (expand-file-name "foo" tmp-name1))
1221 (vc-handled-backends
1222 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
1223 (cond
1224 ((tramp-find-executable v vc-bzr-program (tramp-get-remote-path v))
1225 '(Bzr))
1226 ((tramp-find-executable v vc-git-program (tramp-get-remote-path v))
1227 '(Git))
1228 ((tramp-find-executable v vc-hg-program (tramp-get-remote-path v))
1229 '(Hg))
1230 (t nil)))))
1231 (skip-unless vc-handled-backends)
1232 (message "%s" vc-handled-backends)
1234 (unwind-protect
1235 (progn
1236 (make-directory tmp-name1)
1237 (write-region "foo" nil tmp-name2)
1238 (should (file-directory-p tmp-name1))
1239 (should (file-exists-p tmp-name2))
1240 (should-not (vc-registered tmp-name1))
1241 (should-not (vc-registered tmp-name2))
1243 (let ((default-directory tmp-name1))
1244 ;; Create empty repository, and register the file.
1245 (vc-create-repo (car vc-handled-backends))
1246 ;; The structure of VC-FILESET is not documented. Let's
1247 ;; hope it won't change.
1248 (vc-register
1249 nil (list (car vc-handled-backends)
1250 (list (file-name-nondirectory tmp-name2)))))
1251 (should (vc-registered tmp-name2)))
1253 (ignore-errors (delete-directory tmp-name1 'recursive)))))
1255 (ert-deftest tramp-test30-utf8 ()
1256 "Check UTF8 encoding in file names and file contents."
1257 (skip-unless (tramp--test-enabled))
1258 (tramp-cleanup-connection
1259 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1260 nil 'keep-password)
1262 (let ((tmp-name (tramp--test-make-temp-name))
1263 (arabic "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت")
1264 (chinese "银河系漫游指南系列")
1265 (russian "Автостопом по гала́ктике"))
1266 (unwind-protect
1267 (progn
1268 (make-directory tmp-name)
1269 (dolist (lang `(,arabic ,chinese ,russian))
1270 (let ((file (expand-file-name lang tmp-name)))
1271 (write-region lang nil file)
1272 (should (file-exists-p file))
1273 ;; Check file contents.
1274 (with-temp-buffer
1275 (insert-file-contents file)
1276 (should (string-equal (buffer-string) lang)))))
1277 ;; Check file names.
1278 (should (equal (directory-files
1279 tmp-name nil directory-files-no-dot-files-regexp)
1280 (sort `(,arabic ,chinese ,russian) 'string-lessp))))
1281 (ignore-errors (delete-directory tmp-name 'recursive)))))
1283 ;; TODO:
1285 ;; * dired-compress-file
1286 ;; * dired-uncache
1287 ;; * file-acl
1288 ;; * file-ownership-preserved-p
1289 ;; * file-selinux-context
1290 ;; * find-backup-file-name
1291 ;; * make-auto-save-file-name
1292 ;; * set-file-acl
1293 ;; * set-file-selinux-context
1295 ;; * Fix `tramp-test17-insert-directory' for
1296 ;; `ls-lisp-insert-directory' ("plink" and friends).
1297 ;; * Fix `tramp-test27-start-file-process' on MS Windows
1298 ;; (`process-send-eof'?).
1299 ;; * Fix `tramp-test29-utf8' on MS Windows.
1301 (defun tramp-test-all (&optional interactive)
1302 "Run all tests for \\[tramp]."
1303 (interactive "p")
1304 (funcall
1305 (if interactive 'ert-run-tests-interactively 'ert-run-tests-batch) "^tramp"))
1307 (provide 'tramp-tests)
1308 ;;; tramp-tests.el ends here