Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / test / automated / tramp-tests.el
blobf038d687e34a1102c531d5129e8287c60814e15f
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)
41 ;; There is no default value on w32 systems, which could work out of the box.
42 (defconst tramp-test-temporary-file-directory
43 (cond
44 ((getenv "REMOTE_TEMPORARY_FILE_DIRECTORY"))
45 ((eq system-type 'windows-nt) null-device)
46 (t (format "/ssh::%s" temporary-file-directory)))
47 "Temporary directory for Tramp tests.")
49 (setq tramp-verbose 0
50 tramp-message-show-message nil)
52 ;; Disable interactive passwords in batch mode.
53 (when (and noninteractive (not (getenv "REMOTE_ALLOW_PASSWORD")))
54 (defalias 'tramp-read-passwd 'ignore))
56 ;; This shall happen on hydra only.
57 (when (getenv "NIX_STORE")
58 (add-to-list 'tramp-remote-path 'tramp-own-remote-path))
60 (defvar tramp--test-enabled-checked nil
61 "Cached result of `tramp--test-enabled'.
62 If the function did run, the value is a cons cell, the `cdr'
63 being the result.")
65 (defun tramp--test-enabled ()
66 "Whether remote file access is enabled."
67 (unless (consp tramp--test-enabled-checked)
68 (setq
69 tramp--test-enabled-checked
70 (cons
71 t (ignore-errors
72 (and
73 (file-remote-p tramp-test-temporary-file-directory)
74 (file-directory-p tramp-test-temporary-file-directory)
75 (file-writable-p tramp-test-temporary-file-directory))))))
76 ;; Return result.
77 (cdr tramp--test-enabled-checked))
79 (defun tramp--test-make-temp-name ()
80 "Create a temporary file name for test."
81 (expand-file-name
82 (make-temp-name "tramp-test") tramp-test-temporary-file-directory))
84 (ert-deftest tramp-test00-availability ()
85 "Test availability of Tramp functions."
86 :expected-result (if (tramp--test-enabled) :passed :failed)
87 (should (ignore-errors
88 (and
89 (file-remote-p tramp-test-temporary-file-directory)
90 (file-directory-p tramp-test-temporary-file-directory)
91 (file-writable-p tramp-test-temporary-file-directory)))))
93 (ert-deftest tramp-test01-file-name-syntax ()
94 "Check remote file name syntax."
95 ;; Simple cases.
96 (should (tramp-tramp-file-p "/method::"))
97 (should (tramp-tramp-file-p "/host:"))
98 (should (tramp-tramp-file-p "/user@:"))
99 (should (tramp-tramp-file-p "/user@host:"))
100 (should (tramp-tramp-file-p "/method:host:"))
101 (should (tramp-tramp-file-p "/method:user@:"))
102 (should (tramp-tramp-file-p "/method:user@host:"))
103 (should (tramp-tramp-file-p "/method:user@email@host:"))
105 ;; Using a port.
106 (should (tramp-tramp-file-p "/host#1234:"))
107 (should (tramp-tramp-file-p "/user@host#1234:"))
108 (should (tramp-tramp-file-p "/method:host#1234:"))
109 (should (tramp-tramp-file-p "/method:user@host#1234:"))
111 ;; Using an IPv4 address.
112 (should (tramp-tramp-file-p "/1.2.3.4:"))
113 (should (tramp-tramp-file-p "/user@1.2.3.4:"))
114 (should (tramp-tramp-file-p "/method:1.2.3.4:"))
115 (should (tramp-tramp-file-p "/method:user@1.2.3.4:"))
117 ;; Using an IPv6 address.
118 (should (tramp-tramp-file-p "/[]:"))
119 (should (tramp-tramp-file-p "/[::1]:"))
120 (should (tramp-tramp-file-p "/user@[::1]:"))
121 (should (tramp-tramp-file-p "/method:[::1]:"))
122 (should (tramp-tramp-file-p "/method:user@[::1]:"))
124 ;; Local file name part.
125 (should (tramp-tramp-file-p "/host:/:"))
126 (should (tramp-tramp-file-p "/method:::"))
127 (should (tramp-tramp-file-p "/method::/path/to/file"))
128 (should (tramp-tramp-file-p "/method::file"))
130 ;; Multihop.
131 (should (tramp-tramp-file-p "/method1:|method2::"))
132 (should (tramp-tramp-file-p "/method1:host1|host2:"))
133 (should (tramp-tramp-file-p "/method1:host1|method2:host2:"))
134 (should (tramp-tramp-file-p "/method1:user1@host1|method2:user2@host2:"))
135 (should (tramp-tramp-file-p
136 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:"))
138 ;; No strings.
139 (should-not (tramp-tramp-file-p nil))
140 (should-not (tramp-tramp-file-p 'symbol))
141 ;; "/:" suppresses file name handlers.
142 (should-not (tramp-tramp-file-p "/::"))
143 (should-not (tramp-tramp-file-p "/:@:"))
144 (should-not (tramp-tramp-file-p "/:[]:"))
145 ;; Multihops require a method.
146 (should-not (tramp-tramp-file-p "/host1|host2:"))
147 ;; Methods or hostnames shall be at least two characters on MS Windows.
148 (when (memq system-type '(cygwin windows-nt))
149 (should-not (tramp-tramp-file-p "/c:/path/to/file"))
150 (should-not (tramp-tramp-file-p "/c::/path/to/file"))))
152 (ert-deftest tramp-test02-file-name-dissect ()
153 "Check remote file name components."
154 (let ((tramp-default-method "default-method")
155 (tramp-default-user "default-user")
156 (tramp-default-host "default-host"))
157 ;; Expand `tramp-default-user' and `tramp-default-host'.
158 (should (string-equal
159 (file-remote-p "/method::")
160 (format "/%s:%s@%s:" "method" "default-user" "default-host")))
161 (should (string-equal (file-remote-p "/method::" 'method) "method"))
162 (should (string-equal (file-remote-p "/method::" 'user) "default-user"))
163 (should (string-equal (file-remote-p "/method::" 'host) "default-host"))
164 (should (string-equal (file-remote-p "/method::" 'localname) ""))
166 ;; Expand `tramp-default-method' and `tramp-default-user'.
167 (should (string-equal
168 (file-remote-p "/host:")
169 (format "/%s:%s@%s:" "default-method" "default-user" "host")))
170 (should (string-equal (file-remote-p "/host:" 'method) "default-method"))
171 (should (string-equal (file-remote-p "/host:" 'user) "default-user"))
172 (should (string-equal (file-remote-p "/host:" 'host) "host"))
173 (should (string-equal (file-remote-p "/host:" 'localname) ""))
175 ;; Expand `tramp-default-method' and `tramp-default-host'.
176 (should (string-equal
177 (file-remote-p "/user@:")
178 (format "/%s:%s@%s:" "default-method""user" "default-host")))
179 (should (string-equal (file-remote-p "/user@:" 'method) "default-method"))
180 (should (string-equal (file-remote-p "/user@:" 'user) "user"))
181 (should (string-equal (file-remote-p "/user@:" 'host) "default-host"))
182 (should (string-equal (file-remote-p "/user@:" 'localname) ""))
184 ;; Expand `tramp-default-method'.
185 (should (string-equal
186 (file-remote-p "/user@host:")
187 (format "/%s:%s@%s:" "default-method" "user" "host")))
188 (should (string-equal
189 (file-remote-p "/user@host:" 'method) "default-method"))
190 (should (string-equal (file-remote-p "/user@host:" 'user) "user"))
191 (should (string-equal (file-remote-p "/user@host:" 'host) "host"))
192 (should (string-equal (file-remote-p "/user@host:" 'localname) ""))
194 ;; Expand `tramp-default-user'.
195 (should (string-equal
196 (file-remote-p "/method:host:")
197 (format "/%s:%s@%s:" "method" "default-user" "host")))
198 (should (string-equal (file-remote-p "/method:host:" 'method) "method"))
199 (should (string-equal (file-remote-p "/method:host:" 'user) "default-user"))
200 (should (string-equal (file-remote-p "/method:host:" 'host) "host"))
201 (should (string-equal (file-remote-p "/method:host:" 'localname) ""))
203 ;; Expand `tramp-default-host'.
204 (should (string-equal
205 (file-remote-p "/method:user@:")
206 (format "/%s:%s@%s:" "method" "user" "default-host")))
207 (should (string-equal (file-remote-p "/method:user@:" 'method) "method"))
208 (should (string-equal (file-remote-p "/method:user@:" 'user) "user"))
209 (should (string-equal (file-remote-p "/method:user@:" 'host)
210 "default-host"))
211 (should (string-equal (file-remote-p "/method:user@:" 'localname) ""))
213 ;; No expansion.
214 (should (string-equal
215 (file-remote-p "/method:user@host:")
216 (format "/%s:%s@%s:" "method" "user" "host")))
217 (should (string-equal
218 (file-remote-p "/method:user@host:" 'method) "method"))
219 (should (string-equal (file-remote-p "/method:user@host:" 'user) "user"))
220 (should (string-equal (file-remote-p "/method:user@host:" 'host) "host"))
221 (should (string-equal (file-remote-p "/method:user@host:" 'localname) ""))
223 ;; No expansion.
224 (should (string-equal
225 (file-remote-p "/method:user@email@host:")
226 (format "/%s:%s@%s:" "method" "user@email" "host")))
227 (should (string-equal
228 (file-remote-p "/method:user@email@host:" 'method) "method"))
229 (should (string-equal
230 (file-remote-p "/method:user@email@host:" 'user) "user@email"))
231 (should (string-equal
232 (file-remote-p "/method:user@email@host:" 'host) "host"))
233 (should (string-equal
234 (file-remote-p "/method:user@email@host:" 'localname) ""))
236 ;; Expand `tramp-default-method' and `tramp-default-user'.
237 (should (string-equal
238 (file-remote-p "/host#1234:")
239 (format "/%s:%s@%s:" "default-method" "default-user" "host#1234")))
240 (should (string-equal
241 (file-remote-p "/host#1234:" 'method) "default-method"))
242 (should (string-equal (file-remote-p "/host#1234:" 'user) "default-user"))
243 (should (string-equal (file-remote-p "/host#1234:" 'host) "host#1234"))
244 (should (string-equal (file-remote-p "/host#1234:" 'localname) ""))
246 ;; Expand `tramp-default-method'.
247 (should (string-equal
248 (file-remote-p "/user@host#1234:")
249 (format "/%s:%s@%s:" "default-method" "user" "host#1234")))
250 (should (string-equal
251 (file-remote-p "/user@host#1234:" 'method) "default-method"))
252 (should (string-equal (file-remote-p "/user@host#1234:" 'user) "user"))
253 (should (string-equal (file-remote-p "/user@host#1234:" 'host) "host#1234"))
254 (should (string-equal (file-remote-p "/user@host#1234:" 'localname) ""))
256 ;; Expand `tramp-default-user'.
257 (should (string-equal
258 (file-remote-p "/method:host#1234:")
259 (format "/%s:%s@%s:" "method" "default-user" "host#1234")))
260 (should (string-equal
261 (file-remote-p "/method:host#1234:" 'method) "method"))
262 (should (string-equal
263 (file-remote-p "/method:host#1234:" 'user) "default-user"))
264 (should (string-equal
265 (file-remote-p "/method:host#1234:" 'host) "host#1234"))
266 (should (string-equal (file-remote-p "/method:host#1234:" 'localname) ""))
268 ;; No expansion.
269 (should (string-equal
270 (file-remote-p "/method:user@host#1234:")
271 (format "/%s:%s@%s:" "method" "user" "host#1234")))
272 (should (string-equal
273 (file-remote-p "/method:user@host#1234:" 'method) "method"))
274 (should (string-equal
275 (file-remote-p "/method:user@host#1234:" 'user) "user"))
276 (should (string-equal
277 (file-remote-p "/method:user@host#1234:" 'host) "host#1234"))
278 (should (string-equal
279 (file-remote-p "/method:user@host#1234:" 'localname) ""))
281 ;; Expand `tramp-default-method' and `tramp-default-user'.
282 (should (string-equal
283 (file-remote-p "/1.2.3.4:")
284 (format "/%s:%s@%s:" "default-method" "default-user" "1.2.3.4")))
285 (should (string-equal (file-remote-p "/1.2.3.4:" 'method) "default-method"))
286 (should (string-equal (file-remote-p "/1.2.3.4:" 'user) "default-user"))
287 (should (string-equal (file-remote-p "/1.2.3.4:" 'host) "1.2.3.4"))
288 (should (string-equal (file-remote-p "/1.2.3.4:" 'localname) ""))
290 ;; Expand `tramp-default-method'.
291 (should (string-equal
292 (file-remote-p "/user@1.2.3.4:")
293 (format "/%s:%s@%s:" "default-method" "user" "1.2.3.4")))
294 (should (string-equal
295 (file-remote-p "/user@1.2.3.4:" 'method) "default-method"))
296 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'user) "user"))
297 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'host) "1.2.3.4"))
298 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'localname) ""))
300 ;; Expand `tramp-default-user'.
301 (should (string-equal
302 (file-remote-p "/method:1.2.3.4:")
303 (format "/%s:%s@%s:" "method" "default-user" "1.2.3.4")))
304 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'method) "method"))
305 (should (string-equal
306 (file-remote-p "/method:1.2.3.4:" 'user) "default-user"))
307 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'host) "1.2.3.4"))
308 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'localname) ""))
310 ;; No expansion.
311 (should (string-equal
312 (file-remote-p "/method:user@1.2.3.4:")
313 (format "/%s:%s@%s:" "method" "user" "1.2.3.4")))
314 (should (string-equal
315 (file-remote-p "/method:user@1.2.3.4:" 'method) "method"))
316 (should (string-equal (file-remote-p "/method:user@1.2.3.4:" 'user) "user"))
317 (should (string-equal
318 (file-remote-p "/method:user@1.2.3.4:" 'host) "1.2.3.4"))
319 (should (string-equal
320 (file-remote-p "/method:user@1.2.3.4:" 'localname) ""))
322 ;; Expand `tramp-default-method', `tramp-default-user' and
323 ;; `tramp-default-host'.
324 (should (string-equal
325 (file-remote-p "/[]:")
326 (format
327 "/%s:%s@%s:" "default-method" "default-user" "default-host")))
328 (should (string-equal (file-remote-p "/[]:" 'method) "default-method"))
329 (should (string-equal (file-remote-p "/[]:" 'user) "default-user"))
330 (should (string-equal (file-remote-p "/[]:" 'host) "default-host"))
331 (should (string-equal (file-remote-p "/[]:" 'localname) ""))
333 ;; Expand `tramp-default-method' and `tramp-default-user'.
334 (let ((tramp-default-host "::1"))
335 (should (string-equal
336 (file-remote-p "/[]:")
337 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
338 (should (string-equal (file-remote-p "/[]:" 'method) "default-method"))
339 (should (string-equal (file-remote-p "/[]:" 'user) "default-user"))
340 (should (string-equal (file-remote-p "/[]:" 'host) "::1"))
341 (should (string-equal (file-remote-p "/[]:" 'localname) "")))
343 ;; Expand `tramp-default-method' and `tramp-default-user'.
344 (should (string-equal
345 (file-remote-p "/[::1]:")
346 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
347 (should (string-equal (file-remote-p "/[::1]:" 'method) "default-method"))
348 (should (string-equal (file-remote-p "/[::1]:" 'user) "default-user"))
349 (should (string-equal (file-remote-p "/[::1]:" 'host) "::1"))
350 (should (string-equal (file-remote-p "/[::1]:" 'localname) ""))
352 ;; Expand `tramp-default-method'.
353 (should (string-equal
354 (file-remote-p "/user@[::1]:")
355 (format "/%s:%s@%s:" "default-method" "user" "[::1]")))
356 (should (string-equal
357 (file-remote-p "/user@[::1]:" 'method) "default-method"))
358 (should (string-equal (file-remote-p "/user@[::1]:" 'user) "user"))
359 (should (string-equal (file-remote-p "/user@[::1]:" 'host) "::1"))
360 (should (string-equal (file-remote-p "/user@[::1]:" 'localname) ""))
362 ;; Expand `tramp-default-user'.
363 (should (string-equal
364 (file-remote-p "/method:[::1]:")
365 (format "/%s:%s@%s:" "method" "default-user" "[::1]")))
366 (should (string-equal (file-remote-p "/method:[::1]:" 'method) "method"))
367 (should (string-equal
368 (file-remote-p "/method:[::1]:" 'user) "default-user"))
369 (should (string-equal (file-remote-p "/method:[::1]:" 'host) "::1"))
370 (should (string-equal (file-remote-p "/method:[::1]:" 'localname) ""))
372 ;; No expansion.
373 (should (string-equal
374 (file-remote-p "/method:user@[::1]:")
375 (format "/%s:%s@%s:" "method" "user" "[::1]")))
376 (should (string-equal
377 (file-remote-p "/method:user@[::1]:" 'method) "method"))
378 (should (string-equal (file-remote-p "/method:user@[::1]:" 'user) "user"))
379 (should (string-equal (file-remote-p "/method:user@[::1]:" 'host) "::1"))
380 (should (string-equal
381 (file-remote-p "/method:user@[::1]:" 'localname) ""))
383 ;; Local file name part.
384 (should (string-equal (file-remote-p "/host:/:" 'localname) "/:"))
385 (should (string-equal (file-remote-p "/method:::" 'localname) ":"))
386 (should (string-equal (file-remote-p "/method:: " 'localname) " "))
387 (should (string-equal (file-remote-p "/method::file" 'localname) "file"))
388 (should (string-equal
389 (file-remote-p "/method::/path/to/file" 'localname)
390 "/path/to/file"))
392 ;; Multihop.
393 (should
394 (string-equal
395 (file-remote-p "/method1:user1@host1|method2:user2@host2:/path/to/file")
396 (format "/%s:%s@%s:" "method2" "user2" "host2")))
397 (should
398 (string-equal
399 (file-remote-p
400 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'method)
401 "method2"))
402 (should
403 (string-equal
404 (file-remote-p
405 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'user)
406 "user2"))
407 (should
408 (string-equal
409 (file-remote-p
410 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'host)
411 "host2"))
412 (should
413 (string-equal
414 (file-remote-p
415 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'localname)
416 "/path/to/file"))
418 (should
419 (string-equal
420 (file-remote-p
421 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file")
422 (format "/%s:%s@%s:" "method3" "user3" "host3")))
423 (should
424 (string-equal
425 (file-remote-p
426 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
427 'method)
428 "method3"))
429 (should
430 (string-equal
431 (file-remote-p
432 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
433 'user)
434 "user3"))
435 (should
436 (string-equal
437 (file-remote-p
438 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
439 'host)
440 "host3"))
441 (should
442 (string-equal
443 (file-remote-p
444 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
445 'localname)
446 "/path/to/file"))))
448 (ert-deftest tramp-test03-file-name-defaults ()
449 "Check default values for some methods."
450 ;; Default values in tramp-adb.el.
451 (should (string-equal (file-remote-p "/adb::" 'host) ""))
452 ;; Default values in tramp-ftp.el.
453 (should (string-equal (file-remote-p "/ftp.host:" 'method) "ftp"))
454 (dolist (u '("ftp" "anonymous"))
455 (should (string-equal (file-remote-p (format "/%s@:" u) 'method) "ftp")))
456 ;; Default values in tramp-gvfs.el.
457 (when (and (load "tramp-gvfs" 'noerror 'nomessage)
458 (symbol-value 'tramp-gvfs-enabled))
459 (should (string-equal (file-remote-p "/synce::" 'user) nil)))
460 ;; Default values in tramp-gw.el.
461 (dolist (m '("tunnel" "socks"))
462 (should
463 (string-equal (file-remote-p (format "/%s::" m) 'user) (user-login-name))))
464 ;; Default values in tramp-sh.el.
465 (dolist (h `("127.0.0.1" "[::1]" "localhost" "localhost6" ,(system-name)))
466 (should (string-equal (file-remote-p (format "/root@%s:" h) 'method) "su")))
467 (dolist (m '("su" "sudo" "ksu"))
468 (should (string-equal (file-remote-p (format "/%s::" m) 'user) "root")))
469 (dolist (m '("rcp" "remcp" "rsh" "telnet" "krlogin" "fcp"))
470 (should
471 (string-equal (file-remote-p (format "/%s::" m) 'user) (user-login-name))))
472 ;; Default values in tramp-smb.el.
473 (should (string-equal (file-remote-p "/user%domain@host:" 'method) "smb"))
474 (should (string-equal (file-remote-p "/smb::" 'user) nil)))
476 (ert-deftest tramp-test04-substitute-in-file-name ()
477 "Check `substitute-in-file-name'."
478 (should (string-equal (substitute-in-file-name "/method:host://foo") "/foo"))
479 (should
480 (string-equal
481 (substitute-in-file-name "/method:host:/path//foo") "/method:host:/foo"))
482 (should
483 (string-equal (substitute-in-file-name "/method:host:/path///foo") "/foo"))
484 (should
485 (string-equal
486 (substitute-in-file-name "/method:host:/path/~/foo") "/method:host:~/foo"))
487 (should
488 (string-equal (substitute-in-file-name "/method:host:/path//~/foo") "~/foo"))
489 (let (process-environment)
490 (should
491 (string-equal
492 (substitute-in-file-name "/method:host:/path/$FOO")
493 "/method:host:/path/$FOO"))
494 (setenv "FOO" "bla")
495 (should
496 (string-equal
497 (substitute-in-file-name "/method:host:/path/$FOO")
498 "/method:host:/path/bla"))
499 (should
500 (string-equal
501 (substitute-in-file-name "/method:host:/path/$$FOO")
502 "/method:host:/path/$FOO"))))
504 (ert-deftest tramp-test05-expand-file-name ()
505 "Check `expand-file-name'."
506 (should
507 (string-equal
508 (expand-file-name "/method:host:/path/./file") "/method:host:/path/file"))
509 (should
510 (string-equal
511 (expand-file-name "/method:host:/path/../file") "/method:host:/file")))
513 (ert-deftest tramp-test06-directory-file-name ()
514 "Check `directory-file-name'.
515 This checks also `file-name-as-directory', `file-name-directory'
516 and `file-name-nondirectory'."
517 (should
518 (string-equal
519 (directory-file-name "/method:host:/path/to/file")
520 "/method:host:/path/to/file"))
521 (should
522 (string-equal
523 (directory-file-name "/method:host:/path/to/file/")
524 "/method:host:/path/to/file"))
525 (should
526 (string-equal
527 (file-name-as-directory "/method:host:/path/to/file")
528 "/method:host:/path/to/file/"))
529 (should
530 (string-equal
531 (file-name-as-directory "/method:host:/path/to/file/")
532 "/method:host:/path/to/file/"))
533 (should
534 (string-equal
535 (file-name-directory "/method:host:/path/to/file")
536 "/method:host:/path/to/"))
537 (should
538 (string-equal
539 (file-name-directory "/method:host:/path/to/file/")
540 "/method:host:/path/to/file/"))
541 (should
542 (string-equal (file-name-nondirectory "/method:host:/path/to/file") "file"))
543 (should
544 (string-equal (file-name-nondirectory "/method:host:/path/to/file/") ""))
545 (should-not
546 (file-remote-p
547 (unhandled-file-name-directory "/method:host:/path/to/file"))))
549 (ert-deftest tramp-test07-file-exists-p ()
550 "Check `file-exist-p', `write-region' and `delete-file'."
551 (skip-unless (tramp--test-enabled))
552 (tramp-cleanup-connection
553 (tramp-dissect-file-name tramp-test-temporary-file-directory)
554 nil 'keep-password)
556 (let ((tmp-name (tramp--test-make-temp-name)))
557 (should-not (file-exists-p tmp-name))
558 (write-region "foo" nil tmp-name)
559 (should (file-exists-p tmp-name))
560 (delete-file tmp-name)
561 (should-not (file-exists-p tmp-name))))
563 (ert-deftest tramp-test08-file-local-copy ()
564 "Check `file-local-copy'."
565 (skip-unless (tramp--test-enabled))
566 (tramp-cleanup-connection
567 (tramp-dissect-file-name tramp-test-temporary-file-directory)
568 nil 'keep-password)
570 (let ((tmp-name1 (tramp--test-make-temp-name))
571 tmp-name2)
572 (unwind-protect
573 (progn
574 (write-region "foo" nil tmp-name1)
575 (should (setq tmp-name2 (file-local-copy tmp-name1)))
576 (with-temp-buffer
577 (insert-file-contents tmp-name2)
578 (should (string-equal (buffer-string) "foo"))))
579 (ignore-errors
580 (delete-file tmp-name1)
581 (delete-file tmp-name2)))))
583 (ert-deftest tramp-test09-insert-file-contents ()
584 "Check `insert-file-contents'."
585 (skip-unless (tramp--test-enabled))
586 (tramp-cleanup-connection
587 (tramp-dissect-file-name tramp-test-temporary-file-directory)
588 nil 'keep-password)
590 (let ((tmp-name (tramp--test-make-temp-name)))
591 (unwind-protect
592 (progn
593 (write-region "foo" nil tmp-name)
594 (with-temp-buffer
595 (insert-file-contents tmp-name)
596 (should (string-equal (buffer-string) "foo"))
597 (insert-file-contents tmp-name)
598 (should (string-equal (buffer-string) "foofoo"))
599 ;; Insert partly.
600 (insert-file-contents tmp-name nil 1 3)
601 (should (string-equal (buffer-string) "oofoofoo"))
602 ;; Replace.
603 (insert-file-contents tmp-name nil nil nil 'replace)
604 (should (string-equal (buffer-string) "foo"))))
605 (ignore-errors (delete-file tmp-name)))))
607 (ert-deftest tramp-test10-write-region ()
608 "Check `write-region'."
609 (skip-unless (tramp--test-enabled))
610 (tramp-cleanup-connection
611 (tramp-dissect-file-name tramp-test-temporary-file-directory)
612 nil 'keep-password)
614 (let ((tmp-name (tramp--test-make-temp-name)))
615 (unwind-protect
616 (progn
617 (with-temp-buffer
618 (insert "foo")
619 (write-region nil nil tmp-name))
620 (with-temp-buffer
621 (insert-file-contents tmp-name)
622 (should (string-equal (buffer-string) "foo")))
623 ;; Append.
624 (with-temp-buffer
625 (insert "bla")
626 (write-region nil nil tmp-name 'append))
627 (with-temp-buffer
628 (insert-file-contents tmp-name)
629 (should (string-equal (buffer-string) "foobla")))
630 ;; Write string.
631 (write-region "foo" nil tmp-name)
632 (with-temp-buffer
633 (insert-file-contents tmp-name)
634 (should (string-equal (buffer-string) "foo")))
635 ;; Write partly.
636 (with-temp-buffer
637 (insert "123456789")
638 (write-region 3 5 tmp-name))
639 (with-temp-buffer
640 (insert-file-contents tmp-name)
641 (should (string-equal (buffer-string) "34"))))
642 (ignore-errors (delete-file tmp-name)))))
644 (ert-deftest tramp-test11-copy-file ()
645 "Check `copy-file'."
646 (skip-unless (tramp--test-enabled))
647 (tramp-cleanup-connection
648 (tramp-dissect-file-name tramp-test-temporary-file-directory)
649 nil 'keep-password)
651 (let ((tmp-name1 (tramp--test-make-temp-name))
652 (tmp-name2 (tramp--test-make-temp-name)))
653 (unwind-protect
654 (progn
655 (write-region "foo" nil tmp-name1)
656 (copy-file tmp-name1 tmp-name2)
657 (should (file-exists-p tmp-name2))
658 (with-temp-buffer
659 (insert-file-contents tmp-name2)
660 (should (string-equal (buffer-string) "foo"))))
661 (ignore-errors
662 (delete-file tmp-name1)
663 (delete-file tmp-name2)))))
665 (ert-deftest tramp-test12-rename-file ()
666 "Check `rename-file'."
667 (skip-unless (tramp--test-enabled))
668 (tramp-cleanup-connection
669 (tramp-dissect-file-name tramp-test-temporary-file-directory)
670 nil 'keep-password)
672 (let ((tmp-name1 (tramp--test-make-temp-name))
673 (tmp-name2 (tramp--test-make-temp-name)))
674 (unwind-protect
675 (progn
676 (write-region "foo" nil tmp-name1)
677 (rename-file tmp-name1 tmp-name2)
678 (should-not (file-exists-p tmp-name1))
679 (should (file-exists-p tmp-name2))
680 (with-temp-buffer
681 (insert-file-contents tmp-name2)
682 (should (string-equal (buffer-string) "foo"))))
683 (ignore-errors (delete-file tmp-name2)))))
685 (ert-deftest tramp-test13-make-directory ()
686 "Check `make-directory'.
687 This tests also `file-directory-p' and `file-accessible-directory-p'."
688 (skip-unless (tramp--test-enabled))
689 (tramp-cleanup-connection
690 (tramp-dissect-file-name tramp-test-temporary-file-directory)
691 nil 'keep-password)
693 (let ((tmp-name (tramp--test-make-temp-name)))
694 (unwind-protect
695 (progn
696 (make-directory tmp-name)
697 (should (file-directory-p tmp-name))
698 (should (file-accessible-directory-p tmp-name)))
699 (ignore-errors (delete-directory tmp-name)))))
701 (ert-deftest tramp-test14-delete-directory ()
702 "Check `delete-directory'."
703 (skip-unless (tramp--test-enabled))
704 (tramp-cleanup-connection
705 (tramp-dissect-file-name tramp-test-temporary-file-directory)
706 nil 'keep-password)
708 (let ((tmp-name (tramp--test-make-temp-name)))
709 ;; Delete empty directory.
710 (make-directory tmp-name)
711 (should (file-directory-p tmp-name))
712 (delete-directory tmp-name)
713 (should-not (file-directory-p tmp-name))
714 ;; Delete non-empty directory.
715 (make-directory tmp-name)
716 (write-region "foo" nil (expand-file-name "bla" tmp-name))
717 (should-error (delete-directory tmp-name))
718 (delete-directory tmp-name 'recursive)
719 (should-not (file-directory-p tmp-name))))
721 (ert-deftest tramp-test15-copy-directory ()
722 "Check `copy-directory'."
723 (skip-unless (tramp--test-enabled))
724 (tramp-cleanup-connection
725 (tramp-dissect-file-name tramp-test-temporary-file-directory)
726 nil 'keep-password)
728 (let* ((tmp-name1 (tramp--test-make-temp-name))
729 (tmp-name2 (tramp--test-make-temp-name))
730 (tmp-name3 (expand-file-name
731 (file-name-nondirectory tmp-name1) tmp-name2))
732 (tmp-name4 (expand-file-name "foo" tmp-name1))
733 (tmp-name5 (expand-file-name "foo" tmp-name2))
734 (tmp-name6 (expand-file-name "foo" tmp-name3)))
735 (unwind-protect
736 (progn
737 ;; Copy empty directory.
738 (make-directory tmp-name1)
739 (write-region "foo" nil tmp-name4)
740 (should (file-directory-p tmp-name1))
741 (should (file-exists-p tmp-name4))
742 (copy-directory tmp-name1 tmp-name2)
743 (should (file-directory-p tmp-name2))
744 (should (file-exists-p tmp-name5))
745 ;; Target directory does exist already.
746 (copy-directory tmp-name1 tmp-name2)
747 (should (file-directory-p tmp-name3))
748 (should (file-exists-p tmp-name6)))
749 (ignore-errors
750 (delete-directory tmp-name1 'recursive)
751 (delete-directory tmp-name2 'recursive)))))
753 (ert-deftest tramp-test16-directory-files ()
754 "Check `directory-files'."
755 (skip-unless (tramp--test-enabled))
756 (tramp-cleanup-connection
757 (tramp-dissect-file-name tramp-test-temporary-file-directory)
758 nil 'keep-password)
760 (let* ((tmp-name1 (tramp--test-make-temp-name))
761 (tmp-name2 (expand-file-name "bla" tmp-name1))
762 (tmp-name3 (expand-file-name "foo" tmp-name1)))
763 (unwind-protect
764 (progn
765 (make-directory tmp-name1)
766 (write-region "foo" nil tmp-name2)
767 (write-region "bla" nil tmp-name3)
768 (should (file-directory-p tmp-name1))
769 (should (file-exists-p tmp-name2))
770 (should (file-exists-p tmp-name3))
771 (should (equal (directory-files tmp-name1) '("." ".." "bla" "foo")))
772 (should (equal (directory-files tmp-name1 'full)
773 `(,(concat tmp-name1 "/.")
774 ,(concat tmp-name1 "/..")
775 ,tmp-name2 ,tmp-name3)))
776 (should (equal (directory-files
777 tmp-name1 nil directory-files-no-dot-files-regexp)
778 '("bla" "foo")))
779 (should (equal (directory-files
780 tmp-name1 'full directory-files-no-dot-files-regexp)
781 `(,tmp-name2 ,tmp-name3))))
782 (ignore-errors (delete-directory tmp-name1 'recursive)))))
784 (ert-deftest tramp-test17-insert-directory ()
785 "Check `insert-directory'."
786 (skip-unless (tramp--test-enabled))
787 (tramp-cleanup-connection
788 (tramp-dissect-file-name tramp-test-temporary-file-directory)
789 nil 'keep-password)
791 (let* ((tmp-name1 (tramp--test-make-temp-name))
792 (tmp-name2 (expand-file-name "foo" tmp-name1)))
793 (unwind-protect
794 (progn
795 (make-directory tmp-name1)
796 (write-region "foo" nil tmp-name2)
797 (should (file-directory-p tmp-name1))
798 (should (file-exists-p tmp-name2))
799 (with-temp-buffer
800 (insert-directory tmp-name1 nil)
801 (goto-char (point-min))
802 (should (looking-at-p (regexp-quote tmp-name1))))
803 (with-temp-buffer
804 (insert-directory tmp-name1 "-al")
805 (goto-char (point-min))
806 (should (looking-at-p (format "^.+ %s$" (regexp-quote tmp-name1)))))
807 (with-temp-buffer
808 (insert-directory (file-name-as-directory tmp-name1) "-al")
809 (goto-char (point-min))
810 (should
811 (looking-at-p (format "^.+ %s/$" (regexp-quote tmp-name1)))))
812 (with-temp-buffer
813 (insert-directory
814 (file-name-as-directory tmp-name1) "-al" nil 'full-directory-p)
815 (goto-char (point-min))
816 (should
817 (looking-at-p "total +[[:digit:]]+\n.+ \\.\n.+ \\.\\.\n.+ foo$"))))
818 (ignore-errors (delete-directory tmp-name1 'recursive)))))
820 (ert-deftest tramp-test18-file-attributes ()
821 "Check `file-attributes'.
822 This tests also `file-readable-p' and `file-regular-p'."
823 (skip-unless (tramp--test-enabled))
824 (tramp-cleanup-connection
825 (tramp-dissect-file-name tramp-test-temporary-file-directory)
826 nil 'keep-password)
828 (let ((tmp-name (tramp--test-make-temp-name))
829 attr)
830 (unwind-protect
831 (progn
832 (write-region "foo" nil tmp-name)
833 (should (file-exists-p tmp-name))
834 (setq attr (file-attributes tmp-name))
835 (should (consp attr))
836 (should (file-exists-p tmp-name))
837 (should (file-readable-p tmp-name))
838 (should (file-regular-p tmp-name))
839 ;; We do not test inodes and device numbers.
840 (should (null (car attr)))
841 (should (numberp (nth 1 attr))) ;; Link.
842 (should (numberp (nth 2 attr))) ;; Uid.
843 (should (numberp (nth 3 attr))) ;; Gid.
844 ;; Last access time.
845 (should (stringp (current-time-string (nth 4 attr))))
846 ;; Last modification time.
847 (should (stringp (current-time-string (nth 5 attr))))
848 ;; Last status change time.
849 (should (stringp (current-time-string (nth 6 attr))))
850 (should (numberp (nth 7 attr))) ;; Size.
851 (should (stringp (nth 8 attr))) ;; Modes.
853 (setq attr (file-attributes tmp-name 'string))
854 (should (stringp (nth 2 attr))) ;; Uid.
855 (should (stringp (nth 3 attr))) ;; Gid.
856 (delete-file tmp-name)
858 (make-directory tmp-name)
859 (should (file-exists-p tmp-name))
860 (should (file-readable-p tmp-name))
861 (should-not (file-regular-p tmp-name))
862 (setq attr (file-attributes tmp-name))
863 (should (eq (car attr) t)))
864 (ignore-errors (delete-directory tmp-name)))))
866 (ert-deftest tramp-test19-directory-files-and-attributes ()
867 "Check `directory-files-and-attributes'."
868 (skip-unless (tramp--test-enabled))
869 (tramp-cleanup-connection
870 (tramp-dissect-file-name tramp-test-temporary-file-directory)
871 nil 'keep-password)
873 (let ((tmp-name (tramp--test-make-temp-name))
874 attr)
875 (unwind-protect
876 (progn
877 (make-directory tmp-name)
878 (should (file-directory-p tmp-name))
879 (write-region "foo" nil (expand-file-name "foo" tmp-name))
880 (write-region "bar" nil (expand-file-name "bar" tmp-name))
881 (write-region "boz" nil (expand-file-name "boz" tmp-name))
882 (setq attr (directory-files-and-attributes tmp-name))
883 (should (consp attr))
884 (dolist (elt attr)
885 (should
886 (equal (file-attributes (expand-file-name (car elt) tmp-name))
887 (cdr elt))))
888 (setq attr (directory-files-and-attributes tmp-name 'full))
889 (dolist (elt attr)
890 (should
891 (equal (file-attributes (car elt)) (cdr elt))))
892 (setq attr (directory-files-and-attributes tmp-name nil "^b"))
893 (should (equal (mapcar 'car attr) '("bar" "boz"))))
894 (ignore-errors (delete-directory tmp-name 'recursive)))))
896 (ert-deftest tramp-test20-file-modes ()
897 "Check `file-modes'.
898 This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
899 (skip-unless (tramp--test-enabled))
900 (tramp-cleanup-connection
901 (tramp-dissect-file-name tramp-test-temporary-file-directory)
902 nil 'keep-password)
904 (let ((tmp-name (tramp--test-make-temp-name)))
905 (unwind-protect
906 (progn
907 (write-region "foo" nil tmp-name)
908 (should (file-exists-p tmp-name))
909 (set-file-modes tmp-name #o777)
910 (should (= (file-modes tmp-name) #o777))
911 (should (file-executable-p tmp-name))
912 (should (file-writable-p tmp-name))
913 (set-file-modes tmp-name #o444)
914 (should (= (file-modes tmp-name) #o444))
915 (should-not (file-executable-p tmp-name))
916 ;; A file is always writable for user "root".
917 (unless (string-equal (file-remote-p tmp-name 'user) "root")
918 (should-not (file-writable-p tmp-name))))
919 (ignore-errors (delete-file tmp-name)))))
921 (ert-deftest tramp-test21-file-links ()
922 "Check `file-symlink-p'.
923 This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
924 (skip-unless (tramp--test-enabled))
925 (tramp-cleanup-connection
926 (tramp-dissect-file-name tramp-test-temporary-file-directory)
927 nil 'keep-password)
929 (let ((tmp-name1 (tramp--test-make-temp-name))
930 (tmp-name2 (tramp--test-make-temp-name))
931 (tmp-name3 (make-temp-name "tramp-")))
932 (unwind-protect
933 (progn
934 (write-region "foo" nil tmp-name1)
935 (should (file-exists-p tmp-name1))
936 (make-symbolic-link tmp-name1 tmp-name2)
937 (should (file-symlink-p tmp-name2))
938 (should-error (make-symbolic-link tmp-name1 tmp-name2))
939 (make-symbolic-link tmp-name1 tmp-name2 'ok-if-already-exists)
940 (should (file-symlink-p tmp-name2))
941 ;; `tmp-name3' is a local file name.
942 (should-error (make-symbolic-link tmp-name1 tmp-name3)))
943 (ignore-errors
944 (delete-file tmp-name1)
945 (delete-file tmp-name2)))
947 (unwind-protect
948 (progn
949 (write-region "foo" nil tmp-name1)
950 (should (file-exists-p tmp-name1))
951 (add-name-to-file tmp-name1 tmp-name2)
952 (should-not (file-symlink-p tmp-name2))
953 (should-error (add-name-to-file tmp-name1 tmp-name2))
954 (add-name-to-file tmp-name1 tmp-name2 'ok-if-already-exists)
955 (should-not (file-symlink-p tmp-name2))
956 ;; `tmp-name3' is a local file name.
957 (should-error (add-name-to-file tmp-name1 tmp-name3)))
958 (ignore-errors
959 (delete-file tmp-name1)
960 (delete-file tmp-name2)))
962 (unwind-protect
963 (progn
964 (write-region "foo" nil tmp-name1)
965 (should (file-exists-p tmp-name1))
966 (make-symbolic-link tmp-name1 tmp-name2)
967 (should (file-symlink-p tmp-name2))
968 (should-not (string-equal tmp-name2 (file-truename tmp-name2)))
969 (should
970 (string-equal (file-truename tmp-name1) (file-truename tmp-name2))))
971 (ignore-errors
972 (delete-file tmp-name1)
973 (delete-file tmp-name2)))))
975 (ert-deftest tramp-test22-file-times ()
976 "Check `set-file-times' and `file-newer-than-file-p'."
977 (skip-unless (tramp--test-enabled))
978 (tramp-cleanup-connection
979 (tramp-dissect-file-name tramp-test-temporary-file-directory)
980 nil 'keep-password)
982 (let ((tmp-name1 (tramp--test-make-temp-name))
983 (tmp-name2 (tramp--test-make-temp-name))
984 (tmp-name3 (tramp--test-make-temp-name)))
985 (unwind-protect
986 (progn
987 (write-region "foo" nil tmp-name1)
988 (should (file-exists-p tmp-name1))
989 (should (consp (nth 5 (file-attributes tmp-name1))))
990 ;; '(0 0) means don't know, and will be replaced by `current-time'.
991 (set-file-times tmp-name1 '(0 1))
992 (should (equal (nth 5 (file-attributes tmp-name1)) '(0 1)))
993 (write-region "bla" nil tmp-name2)
994 (should (file-exists-p tmp-name2))
995 (should (file-newer-than-file-p tmp-name2 tmp-name1))
996 ;; `tmp-name3' does not exist.
997 (should (file-newer-than-file-p tmp-name2 tmp-name3))
998 (should-not (file-newer-than-file-p tmp-name3 tmp-name1)))
999 (ignore-errors
1000 (delete-file tmp-name1)
1001 (delete-file tmp-name2)))))
1003 (ert-deftest tramp-test23-visited-file-modtime ()
1004 "Check `set-visited-file-modtime' and `verify-visited-file-modtime'."
1005 (skip-unless (tramp--test-enabled))
1006 (tramp-cleanup-connection
1007 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1008 nil 'keep-password)
1010 (let ((tmp-name (tramp--test-make-temp-name)))
1011 (unwind-protect
1012 (progn
1013 (write-region "foo" nil tmp-name)
1014 (should (file-exists-p tmp-name))
1015 (with-temp-buffer
1016 (insert-file-contents tmp-name)
1017 (should (verify-visited-file-modtime))
1018 (set-visited-file-modtime '(0 1))
1019 (should (verify-visited-file-modtime))
1020 (should (equal (visited-file-modtime) '(0 1 0 0)))))
1021 (ignore-errors (delete-file tmp-name)))))
1023 (ert-deftest tramp-test24-file-name-completion ()
1024 "Check `file-name-completion' and `file-name-all-completions'."
1025 (skip-unless (tramp--test-enabled))
1026 (tramp-cleanup-connection
1027 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1028 nil 'keep-password)
1030 (let ((tmp-name (tramp--test-make-temp-name)))
1031 (unwind-protect
1032 (progn
1033 (make-directory tmp-name)
1034 (should (file-directory-p tmp-name))
1035 (write-region "foo" nil (expand-file-name "foo" tmp-name))
1036 (write-region "bar" nil (expand-file-name "bold" tmp-name))
1037 (make-directory (expand-file-name "boz" tmp-name))
1038 (should (equal (file-name-completion "fo" tmp-name) "foo"))
1039 (should (equal (file-name-completion "b" tmp-name) "bo"))
1040 (should
1041 (equal (file-name-completion "b" tmp-name 'file-directory-p) "boz/"))
1042 (should (equal (file-name-all-completions "fo" tmp-name) '("foo")))
1043 (should
1044 (equal (sort (file-name-all-completions "b" tmp-name) 'string-lessp)
1045 '("bold" "boz/"))))
1046 (ignore-errors (delete-directory tmp-name 'recursive)))))
1048 (ert-deftest tramp-test25-load ()
1049 "Check `load'."
1050 (skip-unless (tramp--test-enabled))
1051 (tramp-cleanup-connection
1052 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1053 nil 'keep-password)
1055 (let ((tmp-name (tramp--test-make-temp-name)))
1056 (unwind-protect
1057 (progn
1058 (load tmp-name 'noerror 'nomessage)
1059 (should-not (featurep 'tramp-test-load))
1060 (write-region "(provide 'tramp-test-load)" nil tmp-name)
1061 ;; `load' in lread.c does not pass `must-suffix'. Why?
1062 ;(should-error (load tmp-name nil 'nomessage 'nosuffix 'must-suffix))
1063 (load tmp-name nil 'nomessage 'nosuffix)
1064 (should (featurep 'tramp-test-load)))
1065 (ignore-errors
1066 (and (featurep 'tramp-test-load) (unload-feature 'tramp-test-load))
1067 (delete-file tmp-name)))))
1069 (ert-deftest tramp-test26-process-file ()
1070 "Check `process-file'."
1071 (skip-unless (tramp--test-enabled))
1072 (tramp-cleanup-connection
1073 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1074 nil 'keep-password)
1076 (let ((tmp-name (tramp--test-make-temp-name))
1077 (default-directory tramp-test-temporary-file-directory))
1078 (unwind-protect
1079 (progn
1080 ;; We cannot use "/bin/true" and "/bin/false"; those paths
1081 ;; do not exist on hydra.
1082 (should (zerop (process-file "true")))
1083 (should-not (zerop (process-file "false")))
1084 (should-not (zerop (process-file "binary-does-not-exist")))
1085 (with-temp-buffer
1086 (write-region "foo" nil tmp-name)
1087 (should (zerop (process-file "ls" nil t)))
1088 (should (> (point-max) (point-min)))))
1089 (ignore-errors (delete-file tmp-name)))))
1091 (ert-deftest tramp-test27-start-file-process ()
1092 "Check `start-file-process'."
1093 (skip-unless (tramp--test-enabled))
1094 (tramp-cleanup-connection
1095 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1096 nil 'keep-password)
1098 (let ((default-directory tramp-test-temporary-file-directory)
1099 (tmp-name (tramp--test-make-temp-name))
1100 kill-buffer-query-functions proc)
1101 (unwind-protect
1102 (with-temp-buffer
1103 (setq proc (start-file-process "test1" (current-buffer) "cat"))
1104 (should (processp proc))
1105 (should (equal (process-status proc) 'run))
1106 (process-send-string proc "foo")
1107 (process-send-eof proc)
1108 (accept-process-output proc 1)
1109 (should (string-equal (buffer-string) "foo")))
1110 (ignore-errors (delete-process proc)))
1112 (unwind-protect
1113 (with-temp-buffer
1114 (write-region "foo" nil tmp-name)
1115 (should (file-exists-p tmp-name))
1116 (setq proc
1117 (start-file-process
1118 "test2" (current-buffer)
1119 "cat" (file-name-nondirectory tmp-name)))
1120 (should (processp proc))
1121 (accept-process-output proc 1)
1122 (should (string-equal (buffer-string) "foo")))
1123 (ignore-errors
1124 (delete-process proc)
1125 (delete-file tmp-name)))
1127 (unwind-protect
1128 (progn
1129 (setq proc (start-file-process "test3" nil "cat"))
1130 (should (processp proc))
1131 (should (equal (process-status proc) 'run))
1132 (set-process-filter
1133 proc (lambda (p s) (should (string-equal s "foo"))))
1134 (process-send-string proc "foo")
1135 (process-send-eof proc)
1136 (accept-process-output proc 1))
1137 (ignore-errors (delete-process proc)))))
1139 (ert-deftest tramp-test28-shell-command ()
1140 "Check `shell-command'."
1141 (skip-unless (tramp--test-enabled))
1142 (tramp-cleanup-connection
1143 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1144 nil 'keep-password)
1146 (let ((tmp-name (tramp--test-make-temp-name))
1147 (default-directory tramp-test-temporary-file-directory))
1148 (unwind-protect
1149 (with-temp-buffer
1150 (write-region "foo" nil tmp-name)
1151 (shell-command "ls" (current-buffer))
1152 (should (> (point-max) (point-min))))
1153 (ignore-errors (delete-file tmp-name)))))
1155 (ert-deftest tramp-test29-utf8 ()
1156 "Check UTF8 encoding in file names and file contents."
1157 (skip-unless (tramp--test-enabled))
1158 (tramp-cleanup-connection
1159 (tramp-dissect-file-name tramp-test-temporary-file-directory)
1160 nil 'keep-password)
1162 (let ((tmp-name (tramp--test-make-temp-name))
1163 (arabic "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت")
1164 (chinese "银河系漫游指南系列")
1165 (russian "Автостопом по гала́ктике"))
1166 (unwind-protect
1167 (progn
1168 (make-directory tmp-name)
1169 (dolist (lang `(,arabic ,chinese ,russian))
1170 (let ((file (expand-file-name lang tmp-name)))
1171 (write-region lang nil file)
1172 (should (file-exists-p file))
1173 ;; Check file contents.
1174 (with-temp-buffer
1175 (insert-file-contents file)
1176 (should (string-equal (buffer-string) lang)))))
1177 ;; Check file names.
1178 (should (equal (directory-files
1179 tmp-name nil directory-files-no-dot-files-regexp)
1180 (sort `(,arabic ,chinese ,russian) 'string-lessp))))
1181 (ignore-errors (delete-directory tmp-name 'recursive)))))
1183 ;; TODO:
1185 ;; * dired-compress-file
1186 ;; * dired-uncache
1187 ;; * file-acl
1188 ;; * file-ownership-preserved-p
1189 ;; * file-selinux-context
1190 ;; * find-backup-file-name
1191 ;; * make-auto-save-file-name
1192 ;; * set-file-acl
1193 ;; * set-file-selinux-context
1194 ;; * vc-registered
1196 ;; * Fix `tramp-test17-insert-directory' for
1197 ;; `ls-lisp-insert-directory' ("plink" and friends).
1198 ;; * Fix `tramp-test27-start-file-process' on MS Windows
1199 ;; (`process-send-eof'?).
1200 ;; * Fix `tramp-test29-utf8' on MS Windows.
1202 (defun tramp-test-all (&optional interactive)
1203 "Run all tests for \\[tramp]."
1204 (interactive "p")
1205 (funcall
1206 (if interactive 'ert-run-tests-interactively 'ert-run-tests-batch) "^tramp"))
1208 (provide 'tramp-tests)
1209 ;;; tramp-tests.el ends here