* automated/tramp-tests.el (tramp-test29-utf8): Comment last test
[bpt/emacs.git] / test / automated / tramp-tests.el
1 ;;; tramp-tests.el --- Tests of remote file access
2
3 ;; Copyright (C) 2013 Free Software Foundation, Inc.
4
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
6
7 ;; This program is free software: you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License as
9 ;; published by the Free Software Foundation, either version 3 of the
10 ;; License, or (at your option) any later version.
11 ;;
12 ;; This program is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see `http://www.gnu.org/licenses/'.
19
20 ;;; Commentary:
21
22 ;; The tests require a recent ert.el from Emacs 24.4.
23
24 ;; Some of the tests require access to a remote host files. Set
25 ;; $TRAMP_TEST_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.
29
30 ;; When running the tests in batch mode, it must NOT require an
31 ;; interactive password prompt unless the environment variable
32 ;; $TRAMP_TEST_ALLOW_PASSWORD is set.
33
34 ;; A whole test run can be performed calling the command `tramp-test-all'.
35
36 ;;; Code:
37
38 (require 'ert)
39 (require 'tramp)
40
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 "TRAMP_TEST_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.")
48
49 (setq tramp-verbose 0
50 tramp-message-show-message nil)
51
52 ;; Disable interactive passwords in batch mode.
53 (when (and noninteractive (not (getenv "TRAMP_TEST_ALLOW_PASSWORD")))
54 (defalias 'tramp-read-passwd 'ignore))
55
56 ;; This shall happen on hydra only.
57 (when (getenv "NIX_STORE")
58 (add-to-list 'tramp-remote-path 'tramp-own-remote-path))
59
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.")
64
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))
78
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))
83
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)))))
92
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:"))
104
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:"))
110
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:"))
116
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]:"))
123
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"))
129
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:"))
137
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"))))
151
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) ""))
165
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) ""))
174
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) ""))
183
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) ""))
193
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) ""))
202
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) ""))
212
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) ""))
222
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) ""))
235
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) ""))
245
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) ""))
255
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) ""))
267
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) ""))
280
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) ""))
289
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) ""))
299
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) ""))
309
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) ""))
321
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) ""))
332
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) "")))
342
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) ""))
351
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) ""))
361
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) ""))
371
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) ""))
382
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"))
391
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"))
417
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"))))
447
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)))
475
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"))))
503
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")))
512
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"))))
548
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 (let ((tmp-name (tramp--test-make-temp-name)))
553 (should-not (file-exists-p tmp-name))
554 (write-region "foo" nil tmp-name)
555 (should (file-exists-p tmp-name))
556 (delete-file tmp-name)
557 (should-not (file-exists-p tmp-name))))
558
559 (ert-deftest tramp-test08-file-local-copy ()
560 "Check `file-local-copy'."
561 (skip-unless (tramp--test-enabled))
562 (let ((tmp-name1 (tramp--test-make-temp-name))
563 tmp-name2)
564 (unwind-protect
565 (progn
566 (write-region "foo" nil tmp-name1)
567 (should (setq tmp-name2 (file-local-copy tmp-name1)))
568 (with-temp-buffer
569 (insert-file-contents tmp-name2)
570 (should (string-equal (buffer-string) "foo"))))
571 (ignore-errors
572 (delete-file tmp-name1)
573 (delete-file tmp-name2)))))
574
575 (ert-deftest tramp-test09-insert-file-contents ()
576 "Check `insert-file-contents'."
577 (skip-unless (tramp--test-enabled))
578 (let ((tmp-name (tramp--test-make-temp-name)))
579 (unwind-protect
580 (progn
581 (write-region "foo" nil tmp-name)
582 (with-temp-buffer
583 (insert-file-contents tmp-name)
584 (should (string-equal (buffer-string) "foo"))
585 (insert-file-contents tmp-name)
586 (should (string-equal (buffer-string) "foofoo"))
587 ;; Insert partly.
588 (insert-file-contents tmp-name nil 1 3)
589 (should (string-equal (buffer-string) "oofoofoo"))
590 ;; Replace.
591 (insert-file-contents tmp-name nil nil nil 'replace)
592 (should (string-equal (buffer-string) "foo"))))
593 (ignore-errors (delete-file tmp-name)))))
594
595 (ert-deftest tramp-test10-write-region ()
596 "Check `write-region'."
597 (skip-unless (tramp--test-enabled))
598 (let ((tmp-name (tramp--test-make-temp-name)))
599 (unwind-protect
600 (progn
601 (with-temp-buffer
602 (insert "foo")
603 (write-region nil nil tmp-name))
604 (with-temp-buffer
605 (insert-file-contents tmp-name)
606 (should (string-equal (buffer-string) "foo")))
607 ;; Append.
608 (with-temp-buffer
609 (insert "bla")
610 (write-region nil nil tmp-name 'append))
611 (with-temp-buffer
612 (insert-file-contents tmp-name)
613 (should (string-equal (buffer-string) "foobla")))
614 ;; Write string.
615 (write-region "foo" nil tmp-name)
616 (with-temp-buffer
617 (insert-file-contents tmp-name)
618 (should (string-equal (buffer-string) "foo")))
619 ;; Write partly.
620 (with-temp-buffer
621 (insert "123456789")
622 (write-region 3 5 tmp-name))
623 (with-temp-buffer
624 (insert-file-contents tmp-name)
625 (should (string-equal (buffer-string) "34"))))
626 (ignore-errors (delete-file tmp-name)))))
627
628 (ert-deftest tramp-test11-copy-file ()
629 "Check `copy-file'."
630 (skip-unless (tramp--test-enabled))
631 (let ((tmp-name1 (tramp--test-make-temp-name))
632 (tmp-name2 (tramp--test-make-temp-name)))
633 (unwind-protect
634 (progn
635 (write-region "foo" nil tmp-name1)
636 (copy-file tmp-name1 tmp-name2)
637 (should (file-exists-p tmp-name2))
638 (with-temp-buffer
639 (insert-file-contents tmp-name2)
640 (should (string-equal (buffer-string) "foo"))))
641 (ignore-errors
642 (delete-file tmp-name1)
643 (delete-file tmp-name2)))))
644
645 (ert-deftest tramp-test12-rename-file ()
646 "Check `rename-file'."
647 (skip-unless (tramp--test-enabled))
648 (let ((tmp-name1 (tramp--test-make-temp-name))
649 (tmp-name2 (tramp--test-make-temp-name)))
650 (unwind-protect
651 (progn
652 (write-region "foo" nil tmp-name1)
653 (rename-file tmp-name1 tmp-name2)
654 (should-not (file-exists-p tmp-name1))
655 (should (file-exists-p tmp-name2))
656 (with-temp-buffer
657 (insert-file-contents tmp-name2)
658 (should (string-equal (buffer-string) "foo"))))
659 (ignore-errors (delete-file tmp-name2)))))
660
661 (ert-deftest tramp-test13-make-directory ()
662 "Check `make-directory'.
663 This tests also `file-directory-p' and `file-accessible-directory-p'."
664 (skip-unless (tramp--test-enabled))
665 (let ((tmp-name (tramp--test-make-temp-name)))
666 (unwind-protect
667 (progn
668 (make-directory tmp-name)
669 (should (file-directory-p tmp-name))
670 (should (file-accessible-directory-p tmp-name)))
671 (ignore-errors (delete-directory tmp-name)))))
672
673 (ert-deftest tramp-test14-delete-directory ()
674 "Check `delete-directory'."
675 (skip-unless (tramp--test-enabled))
676 (let ((tmp-name (tramp--test-make-temp-name)))
677 ;; Delete empty directory.
678 (make-directory tmp-name)
679 (should (file-directory-p tmp-name))
680 (delete-directory tmp-name)
681 (should-not (file-directory-p tmp-name))
682 ;; Delete non-empty directory.
683 (make-directory tmp-name)
684 (write-region "foo" nil (expand-file-name "bla" tmp-name))
685 (should-error (delete-directory tmp-name))
686 (delete-directory tmp-name 'recursive)
687 (should-not (file-directory-p tmp-name))))
688
689 (ert-deftest tramp-test15-copy-directory ()
690 "Check `copy-directory'."
691 (skip-unless (tramp--test-enabled))
692 (let* ((tmp-name1 (tramp--test-make-temp-name))
693 (tmp-name2 (tramp--test-make-temp-name))
694 (tmp-name3 (expand-file-name
695 (file-name-nondirectory tmp-name1) tmp-name2))
696 (tmp-name4 (expand-file-name "foo" tmp-name1))
697 (tmp-name5 (expand-file-name "foo" tmp-name2))
698 (tmp-name6 (expand-file-name "foo" tmp-name3)))
699 (unwind-protect
700 (progn
701 ;; Copy empty directory.
702 (make-directory tmp-name1)
703 (write-region "foo" nil tmp-name4)
704 (should (file-directory-p tmp-name1))
705 (should (file-exists-p tmp-name4))
706 (copy-directory tmp-name1 tmp-name2)
707 (should (file-directory-p tmp-name2))
708 (should (file-exists-p tmp-name5))
709 ;; Target directory does exist already.
710 (copy-directory tmp-name1 tmp-name2)
711 (should (file-directory-p tmp-name3))
712 (should (file-exists-p tmp-name6)))
713 (ignore-errors
714 (delete-directory tmp-name1 'recursive)
715 (delete-directory tmp-name2 'recursive)))))
716
717 (ert-deftest tramp-test16-directory-files ()
718 "Check `directory-files'."
719 (skip-unless (tramp--test-enabled))
720 (let* ((tmp-name1 (tramp--test-make-temp-name))
721 (tmp-name2 (expand-file-name "bla" tmp-name1))
722 (tmp-name3 (expand-file-name "foo" tmp-name1)))
723 (unwind-protect
724 (progn
725 (make-directory tmp-name1)
726 (write-region "foo" nil tmp-name2)
727 (write-region "bla" nil tmp-name3)
728 (should (file-directory-p tmp-name1))
729 (should (file-exists-p tmp-name2))
730 (should (file-exists-p tmp-name3))
731 (should (equal (directory-files tmp-name1) '("." ".." "bla" "foo")))
732 (should (equal (directory-files tmp-name1 'full)
733 `(,(concat tmp-name1 "/.")
734 ,(concat tmp-name1 "/..")
735 ,tmp-name2 ,tmp-name3)))
736 (should (equal (directory-files
737 tmp-name1 nil directory-files-no-dot-files-regexp)
738 '("bla" "foo")))
739 (should (equal (directory-files
740 tmp-name1 'full directory-files-no-dot-files-regexp)
741 `(,tmp-name2 ,tmp-name3))))
742 (ignore-errors (delete-directory tmp-name1 'recursive)))))
743
744 (ert-deftest tramp-test17-insert-directory ()
745 "Check `insert-directory'."
746 (skip-unless (tramp--test-enabled))
747 (let* ((tmp-name1 (tramp--test-make-temp-name))
748 (tmp-name2 (expand-file-name "foo" tmp-name1)))
749 (unwind-protect
750 (progn
751 (make-directory tmp-name1)
752 (write-region "foo" nil tmp-name2)
753 (should (file-directory-p tmp-name1))
754 (should (file-exists-p tmp-name2))
755 (with-temp-buffer
756 (insert-directory tmp-name1 nil)
757 (goto-char (point-min))
758 (should (looking-at-p (regexp-quote tmp-name1))))
759 (with-temp-buffer
760 (insert-directory tmp-name1 "-al")
761 (goto-char (point-min))
762 (should (looking-at-p (format "^.+ %s$" (regexp-quote tmp-name1)))))
763 (with-temp-buffer
764 (insert-directory (file-name-as-directory tmp-name1) "-al")
765 (goto-char (point-min))
766 (should
767 (looking-at-p (format "^.+ %s/$" (regexp-quote tmp-name1)))))
768 (with-temp-buffer
769 (insert-directory
770 (file-name-as-directory tmp-name1) "-al" nil 'full-directory-p)
771 (goto-char (point-min))
772 (should
773 (looking-at-p "total +[[:digit:]]+\n.+ \\.\n.+ \\.\\.\n.+ foo$"))))
774 (ignore-errors (delete-directory tmp-name1 'recursive)))))
775
776 (ert-deftest tramp-test18-file-attributes ()
777 "Check `file-attributes'.
778 This tests also `file-readable-p' and `file-regular-p'."
779 (skip-unless (tramp--test-enabled))
780 (let ((tmp-name (tramp--test-make-temp-name))
781 attr)
782 (unwind-protect
783 (progn
784 (write-region "foo" nil tmp-name)
785 (should (file-exists-p tmp-name))
786 (setq attr (file-attributes tmp-name))
787 (should (consp attr))
788 (should (file-exists-p tmp-name))
789 (should (file-readable-p tmp-name))
790 (should (file-regular-p tmp-name))
791 ;; We do not test inodes and device numbers.
792 (should (null (car attr)))
793 (should (numberp (nth 1 attr))) ;; Link.
794 (should (numberp (nth 2 attr))) ;; Uid.
795 (should (numberp (nth 3 attr))) ;; Gid.
796 ;; Last access time.
797 (should (stringp (current-time-string (nth 4 attr))))
798 ;; Last modification time.
799 (should (stringp (current-time-string (nth 5 attr))))
800 ;; Last status change time.
801 (should (stringp (current-time-string (nth 6 attr))))
802 (should (numberp (nth 7 attr))) ;; Size.
803 (should (stringp (nth 8 attr))) ;; Modes.
804
805 (setq attr (file-attributes tmp-name 'string))
806 (should (stringp (nth 2 attr))) ;; Uid.
807 (should (stringp (nth 3 attr))) ;; Gid.
808 (delete-file tmp-name)
809
810 (make-directory tmp-name)
811 (should (file-exists-p tmp-name))
812 (should (file-readable-p tmp-name))
813 (should-not (file-regular-p tmp-name))
814 (setq attr (file-attributes tmp-name))
815 (should (eq (car attr) t)))
816 (ignore-errors (delete-directory tmp-name)))))
817
818 (ert-deftest tramp-test19-directory-files-and-attributes ()
819 "Check `directory-files-and-attributes'."
820 (skip-unless (tramp--test-enabled))
821 (let ((tmp-name (tramp--test-make-temp-name))
822 attr)
823 (unwind-protect
824 (progn
825 (make-directory tmp-name)
826 (should (file-directory-p tmp-name))
827 (write-region "foo" nil (expand-file-name "foo" tmp-name))
828 (write-region "bar" nil (expand-file-name "bar" tmp-name))
829 (write-region "boz" nil (expand-file-name "boz" tmp-name))
830 (setq attr (directory-files-and-attributes tmp-name))
831 (should (consp attr))
832 (dolist (elt attr)
833 (should
834 (equal (file-attributes (expand-file-name (car elt) tmp-name))
835 (cdr elt))))
836 (setq attr (directory-files-and-attributes tmp-name 'full))
837 (dolist (elt attr)
838 (should
839 (equal (file-attributes (car elt)) (cdr elt))))
840 (setq attr (directory-files-and-attributes tmp-name nil "^b"))
841 (should (equal (mapcar 'car attr) '("bar" "boz"))))
842 (ignore-errors (delete-directory tmp-name 'recursive)))))
843
844 (ert-deftest tramp-test20-file-modes ()
845 "Check `file-modes'.
846 This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
847 (skip-unless (tramp--test-enabled))
848 (let ((tmp-name (tramp--test-make-temp-name)))
849 (unwind-protect
850 (progn
851 (write-region "foo" nil tmp-name)
852 (should (file-exists-p tmp-name))
853 (set-file-modes tmp-name #o777)
854 (should (= (file-modes tmp-name) #o777))
855 (should (file-executable-p tmp-name))
856 (should (file-writable-p tmp-name))
857 (set-file-modes tmp-name #o444)
858 (should (= (file-modes tmp-name) #o444))
859 (should-not (file-executable-p tmp-name))
860 ;; A file is always writable for user "root".
861 (unless (string-equal (file-remote-p tmp-name 'user) "root")
862 (should-not (file-writable-p tmp-name))))
863 (ignore-errors (delete-file tmp-name)))))
864
865 (ert-deftest tramp-test21-file-links ()
866 "Check `file-symlink-p'.
867 This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
868 (skip-unless (tramp--test-enabled))
869 (let ((tmp-name1 (tramp--test-make-temp-name))
870 (tmp-name2 (tramp--test-make-temp-name))
871 (tmp-name3 (make-temp-name "tramp-")))
872 (unwind-protect
873 (progn
874 (write-region "foo" nil tmp-name1)
875 (should (file-exists-p tmp-name1))
876 (make-symbolic-link tmp-name1 tmp-name2)
877 (should (file-symlink-p tmp-name2))
878 (should-error (make-symbolic-link tmp-name1 tmp-name2))
879 (make-symbolic-link tmp-name1 tmp-name2 'ok-if-already-exists)
880 (should (file-symlink-p tmp-name2))
881 ;; `tmp-name3' is a local file name.
882 (should-error (make-symbolic-link tmp-name1 tmp-name3)))
883 (ignore-errors
884 (delete-file tmp-name1)
885 (delete-file tmp-name2)))
886
887 (unwind-protect
888 (progn
889 (write-region "foo" nil tmp-name1)
890 (should (file-exists-p tmp-name1))
891 (add-name-to-file tmp-name1 tmp-name2)
892 (should-not (file-symlink-p tmp-name2))
893 (should-error (add-name-to-file tmp-name1 tmp-name2))
894 (add-name-to-file tmp-name1 tmp-name2 'ok-if-already-exists)
895 (should-not (file-symlink-p tmp-name2))
896 ;; `tmp-name3' is a local file name.
897 (should-error (add-name-to-file tmp-name1 tmp-name3)))
898 (ignore-errors
899 (delete-file tmp-name1)
900 (delete-file tmp-name2)))
901
902 (unwind-protect
903 (progn
904 (write-region "foo" nil tmp-name1)
905 (should (file-exists-p tmp-name1))
906 (make-symbolic-link tmp-name1 tmp-name2)
907 (should (file-symlink-p tmp-name2))
908 (should-not (string-equal tmp-name2 (file-truename tmp-name2)))
909 (should
910 (string-equal (file-truename tmp-name1) (file-truename tmp-name2))))
911 (ignore-errors
912 (delete-file tmp-name1)
913 (delete-file tmp-name2)))))
914
915 (ert-deftest tramp-test22-file-times ()
916 "Check `set-file-times' and `file-newer-than-file-p'."
917 (skip-unless (tramp--test-enabled))
918 (let ((tmp-name1 (tramp--test-make-temp-name))
919 (tmp-name2 (tramp--test-make-temp-name))
920 (tmp-name3 (tramp--test-make-temp-name)))
921 (unwind-protect
922 (progn
923 (write-region "foo" nil tmp-name1)
924 (should (file-exists-p tmp-name1))
925 (should (consp (nth 5 (file-attributes tmp-name1))))
926 ;; '(0 0) means don't know, and will be replaced by `current-time'.
927 (set-file-times tmp-name1 '(0 1))
928 (should (equal (nth 5 (file-attributes tmp-name1)) '(0 1)))
929 (write-region "bla" nil tmp-name2)
930 (should (file-exists-p tmp-name2))
931 (should (file-newer-than-file-p tmp-name2 tmp-name1))
932 ;; `tmp-name3' does not exist.
933 (should (file-newer-than-file-p tmp-name2 tmp-name3))
934 (should-not (file-newer-than-file-p tmp-name3 tmp-name1)))
935 (ignore-errors
936 (delete-file tmp-name1)
937 (delete-file tmp-name2)))))
938
939 (ert-deftest tramp-test23-visited-file-modtime ()
940 "Check `set-visited-file-modtime' and `verify-visited-file-modtime'."
941 (skip-unless (tramp--test-enabled))
942 (let ((tmp-name (tramp--test-make-temp-name)))
943 (unwind-protect
944 (progn
945 (write-region "foo" nil tmp-name)
946 (should (file-exists-p tmp-name))
947 (with-temp-buffer
948 (insert-file-contents tmp-name)
949 (should (verify-visited-file-modtime))
950 (set-visited-file-modtime '(0 1))
951 (should (verify-visited-file-modtime))
952 (should (equal (visited-file-modtime) '(0 1 0 0)))))
953 (ignore-errors (delete-file tmp-name)))))
954
955 (ert-deftest tramp-test24-file-name-completion ()
956 "Check `file-name-completion' and `file-name-all-completions'."
957 (skip-unless (tramp--test-enabled))
958 (let ((tmp-name (tramp--test-make-temp-name)))
959 (unwind-protect
960 (progn
961 (make-directory tmp-name)
962 (should (file-directory-p tmp-name))
963 (write-region "foo" nil (expand-file-name "foo" tmp-name))
964 (write-region "bar" nil (expand-file-name "bold" tmp-name))
965 (make-directory (expand-file-name "boz" tmp-name))
966 (should (equal (file-name-completion "fo" tmp-name) "foo"))
967 (should (equal (file-name-completion "b" tmp-name) "bo"))
968 (should
969 (equal (file-name-completion "b" tmp-name 'file-directory-p) "boz/"))
970 (should (equal (file-name-all-completions "fo" tmp-name) '("foo")))
971 (should
972 (equal (sort (file-name-all-completions "b" tmp-name) 'string-lessp)
973 '("bold" "boz/"))))
974 (ignore-errors (delete-directory tmp-name 'recursive)))))
975
976 (ert-deftest tramp-test25-load ()
977 "Check `load'."
978 (skip-unless (tramp--test-enabled))
979 (let ((tmp-name (tramp--test-make-temp-name)))
980 (unwind-protect
981 (progn
982 (load tmp-name 'noerror 'nomessage)
983 (should-not (featurep 'tramp-test-load))
984 (write-region "(provide 'tramp-test-load)" nil tmp-name)
985 ;; `load' in lread.c does not pass `must-suffix'. Why?
986 ;(should-error (load tmp-name nil 'nomessage 'nosuffix 'must-suffix))
987 (load tmp-name nil 'nomessage 'nosuffix)
988 (should (featurep 'tramp-test-load)))
989 (ignore-errors
990 (and (featurep 'tramp-test-load) (unload-feature 'tramp-test-load))
991 (delete-file tmp-name)))))
992
993 (ert-deftest tramp-test26-process-file ()
994 "Check `process-file'."
995 (skip-unless (tramp--test-enabled))
996 (let ((tmp-name (tramp--test-make-temp-name))
997 (default-directory tramp-test-temporary-file-directory))
998 (unwind-protect
999 (progn
1000 ;; We cannot use "/bin/true" and "/bin/false"; those paths
1001 ;; do not exist on hydra.
1002 (should (zerop (process-file "true")))
1003 (should-not (zerop (process-file "false")))
1004 (should-not (zerop (process-file "binary-does-not-exist")))
1005 (with-temp-buffer
1006 (write-region "foo" nil tmp-name)
1007 (should (zerop (process-file "ls" nil t)))
1008 (should (> (point-max) (point-min)))))
1009 (ignore-errors (delete-file tmp-name)))))
1010
1011 (ert-deftest tramp-test27-start-file-process ()
1012 "Check `start-file-process'."
1013 (skip-unless (tramp--test-enabled))
1014 (let ((default-directory tramp-test-temporary-file-directory)
1015 (tmp-name (tramp--test-make-temp-name))
1016 kill-buffer-query-functions proc)
1017 (unwind-protect
1018 (with-temp-buffer
1019 (setq proc (start-file-process "test1" (current-buffer) "cat"))
1020 (should (processp proc))
1021 (should (equal (process-status proc) 'run))
1022 (process-send-string proc "foo")
1023 (process-send-eof proc)
1024 (accept-process-output proc 1)
1025 (should (string-equal (buffer-string) "foo")))
1026 (ignore-errors (delete-process proc)))
1027
1028 (unwind-protect
1029 (with-temp-buffer
1030 (write-region "foo" nil tmp-name)
1031 (should (file-exists-p tmp-name))
1032 (setq proc
1033 (start-file-process
1034 "test2" (current-buffer)
1035 "cat" (file-name-nondirectory tmp-name)))
1036 (should (processp proc))
1037 (accept-process-output proc 1)
1038 (should (string-equal (buffer-string) "foo")))
1039 (ignore-errors
1040 (delete-process proc)
1041 (delete-file tmp-name)))
1042
1043 (unwind-protect
1044 (progn
1045 (setq proc (start-file-process "test3" nil "cat"))
1046 (should (processp proc))
1047 (should (equal (process-status proc) 'run))
1048 (set-process-filter
1049 proc (lambda (p s) (should (string-equal s "foo"))))
1050 (process-send-string proc "foo")
1051 (process-send-eof proc)
1052 (accept-process-output proc 1))
1053 (ignore-errors (delete-process proc)))))
1054
1055 (ert-deftest tramp-test28-shell-command ()
1056 "Check `shell-command'."
1057 (skip-unless (tramp--test-enabled))
1058 (let ((tmp-name (tramp--test-make-temp-name))
1059 (default-directory tramp-test-temporary-file-directory))
1060 (unwind-protect
1061 (with-temp-buffer
1062 (write-region "foo" nil tmp-name)
1063 (shell-command "ls" (current-buffer))
1064 (should (> (point-max) (point-min))))
1065 (ignore-errors (delete-file tmp-name)))))
1066
1067 (ert-deftest tramp-test29-utf8 ()
1068 "Check UTF8 encoding in file names and file contents."
1069 (skip-unless (tramp--test-enabled))
1070 (let ((tmp-name (tramp--test-make-temp-name))
1071 (arabic "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت.")
1072 (chinese "银河系漫游指南系列")
1073 (russian "Автостопом по гала́ктике"))
1074 (unwind-protect
1075 (progn
1076 (make-directory tmp-name)
1077 (dolist (lang `(,arabic ,chinese ,russian))
1078 (let ((file (expand-file-name lang tmp-name)))
1079 (write-region lang nil file)
1080 (should (file-exists-p file))
1081 ;; Check file contents.
1082 (with-temp-buffer
1083 (insert-file-contents file)
1084 (should (string-equal (buffer-string) lang)))))
1085 ;; Check file name.
1086 ; (should (equal (directory-files
1087 ; tmp-name nil directory-files-no-dot-files-regexp)
1088 ); (sort `(,arabic ,chinese ,russian) 'string-lessp))))
1089 (ignore-errors (delete-directory tmp-name 'recursive)))))
1090
1091 ;; TODO:
1092
1093 ;; * dired-compress-file
1094 ;; * dired-uncache
1095 ;; * file-acl
1096 ;; * file-ownership-preserved-p
1097 ;; * file-selinux-context
1098 ;; * find-backup-file-name
1099 ;; * make-auto-save-file-name
1100 ;; * set-file-acl
1101 ;; * set-file-selinux-context
1102 ;; * vc-registered
1103
1104 (defun tramp-test-all (&optional interactive)
1105 "Run all tests for \\[tramp]."
1106 (interactive "p")
1107 (funcall
1108 (if interactive 'ert-run-tests-interactively 'ert-run-tests-batch) "^tramp"))
1109
1110 (provide 'tramp-tests)
1111 ;;; tramp-tests.el ends here