1 ;;; tramp-tests.el --- Tests of remote file access
3 ;; Copyright (C) 2013-2014 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
7 ;; This program is free software: you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License as
9 ;; published by the Free Software Foundation, either version 3 of the
10 ;; License, or (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see `http://www.gnu.org/licenses/'.
22 ;; The tests require a recent ert.el from Emacs 24.4.
24 ;; Some of the tests require access to a remote host files. Set
25 ;; $REMOTE_TEMPORARY_FILE_DIRECTORY to a suitable value in order
26 ;; to overwrite the default value. If you want to skip tests
27 ;; accessing a remote host, set this environment variable to
28 ;; "/dev/null" or whatever is appropriate on your system.
30 ;; When running the tests in batch mode, it must NOT require an
31 ;; interactive password prompt unless the environment variable
32 ;; $REMOTE_ALLOW_PASSWORD is set.
34 ;; A whole test run can be performed calling the command `tramp-test-all'.
45 (declare-function tramp-find-executable
"tramp-sh")
46 (declare-function tramp-get-remote-path
"tramp-sh")
48 ;; There is no default value on w32 systems, which could work out of the box.
49 (defconst tramp-test-temporary-file-directory
51 ((getenv "REMOTE_TEMPORARY_FILE_DIRECTORY"))
52 ((eq system-type
'windows-nt
) null-device
)
53 (t (format "/ssh::%s" temporary-file-directory
)))
54 "Temporary directory for Tramp tests.")
56 (setq password-cache-expiry nil
58 tramp-message-show-message nil
)
60 ;; Disable interactive passwords in batch mode.
61 (when (and noninteractive
(not (getenv "REMOTE_ALLOW_PASSWORD")))
62 (defalias 'tramp-read-passwd
'ignore
))
64 ;; This shall happen on hydra only.
65 (when (getenv "NIX_STORE")
66 (add-to-list 'tramp-remote-path
'tramp-own-remote-path
))
68 (defvar tramp--test-enabled-checked nil
69 "Cached result of `tramp--test-enabled'.
70 If the function did run, the value is a cons cell, the `cdr'
73 (defun tramp--test-enabled ()
74 "Whether remote file access is enabled."
75 (unless (consp tramp--test-enabled-checked
)
77 tramp--test-enabled-checked
81 (file-remote-p tramp-test-temporary-file-directory
)
82 (file-directory-p tramp-test-temporary-file-directory
)
83 (file-writable-p tramp-test-temporary-file-directory
))))))
85 (cdr tramp--test-enabled-checked
))
87 (defun tramp--test-make-temp-name ()
88 "Create a temporary file name for test."
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
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."
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:"))
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"))
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:"))
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
)
219 (should (string-equal (file-remote-p "/method:user@:" 'localname
) ""))
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
) ""))
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
) ""))
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
) ""))
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 "/[]:")
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
) ""))
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
)
403 (file-remote-p "/method1:user1@host1|method2:user2@host2:/path/to/file")
404 (format "/%s:%s@%s:" "method2" "user2" "host2")))
408 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'method
)
413 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'user
)
418 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'host
)
423 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'localname
)
429 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file")
430 (format "/%s:%s@%s:" "method3" "user3" "host3")))
434 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
440 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
446 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
452 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/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"))
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"))
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"))
489 (substitute-in-file-name "/method:host:/path//foo") "/method:host:/foo"))
491 (string-equal (substitute-in-file-name "/method:host:/path///foo") "/foo"))
494 (substitute-in-file-name "/method:host:/path/~/foo") "/method:host:~/foo"))
496 (string-equal (substitute-in-file-name "/method:host:/path//~/foo") "~/foo"))
497 (let (process-environment)
500 (substitute-in-file-name "/method:host:/path/$FOO")
501 "/method:host:/path/$FOO"))
505 (substitute-in-file-name "/method:host:/path/$FOO")
506 "/method:host:/path/bla"))
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'."
516 (expand-file-name "/method:host:/path/./file") "/method:host:/path/file"))
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'."
527 (directory-file-name "/method:host:/path/to/file")
528 "/method:host:/path/to/file"))
531 (directory-file-name "/method:host:/path/to/file/")
532 "/method:host:/path/to/file"))
535 (file-name-as-directory "/method:host:/path/to/file")
536 "/method:host:/path/to/file/"))
539 (file-name-as-directory "/method:host:/path/to/file/")
540 "/method:host:/path/to/file/"))
543 (file-name-directory "/method:host:/path/to/file")
544 "/method:host:/path/to/"))
547 (file-name-directory "/method:host:/path/to/file/")
548 "/method:host:/path/to/file/"))
550 (string-equal (file-name-nondirectory "/method:host:/path/to/file") "file"))
552 (string-equal (file-name-nondirectory "/method:host:/path/to/file/") ""))
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
)
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
)
578 (let ((tmp-name1 (tramp--test-make-temp-name))
582 (write-region "foo" nil tmp-name1
)
583 (should (setq tmp-name2
(file-local-copy tmp-name1
)))
585 (insert-file-contents tmp-name2
)
586 (should (string-equal (buffer-string) "foo"))))
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
)
598 (let ((tmp-name (tramp--test-make-temp-name)))
601 (write-region "foo" nil tmp-name
)
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"))
608 (insert-file-contents tmp-name nil
1 3)
609 (should (string-equal (buffer-string) "oofoofoo"))
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
)
622 (let ((tmp-name (tramp--test-make-temp-name)))
627 (write-region nil nil tmp-name
))
629 (insert-file-contents tmp-name
)
630 (should (string-equal (buffer-string) "foo")))
634 (write-region nil nil tmp-name
'append
))
636 (insert-file-contents tmp-name
)
637 (should (string-equal (buffer-string) "foobla")))
639 (write-region "foo" nil tmp-name
)
641 (insert-file-contents tmp-name
)
642 (should (string-equal (buffer-string) "foo")))
646 (write-region 3 5 tmp-name
))
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
()
654 (skip-unless (tramp--test-enabled))
655 (tramp-cleanup-connection
656 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
659 (let ((tmp-name1 (tramp--test-make-temp-name))
660 (tmp-name2 (tramp--test-make-temp-name)))
663 (write-region "foo" nil tmp-name1
)
664 (copy-file tmp-name1 tmp-name2
)
665 (should (file-exists-p tmp-name2
))
667 (insert-file-contents tmp-name2
)
668 (should (string-equal (buffer-string) "foo"))))
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
)
680 (let ((tmp-name1 (tramp--test-make-temp-name))
681 (tmp-name2 (tramp--test-make-temp-name)))
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
))
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
)
701 (let ((tmp-name (tramp--test-make-temp-name)))
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
)
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
)
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
)))
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
)))
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
)
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
)))
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
)
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
)
799 (let* ((tmp-name1 (tramp--test-make-temp-name))
800 (tmp-name2 (expand-file-name "foo" tmp-name1
)))
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
))
808 (insert-directory tmp-name1 nil
)
809 (goto-char (point-min))
810 (should (looking-at-p (regexp-quote tmp-name1
))))
812 (insert-directory tmp-name1
"-al")
813 (goto-char (point-min))
814 (should (looking-at-p (format "^.+ %s$" (regexp-quote tmp-name1
)))))
816 (insert-directory (file-name-as-directory tmp-name1
) "-al")
817 (goto-char (point-min))
819 (looking-at-p (format "^.+ %s/$" (regexp-quote tmp-name1
)))))
822 (file-name-as-directory tmp-name1
) "-al" nil
'full-directory-p
)
823 (goto-char (point-min))
826 "\\(total +[[:digit:]]+\n\\)?.+ \\.\n.+ \\.\\.\n.+ foo$"))))
827 (ignore-errors (delete-directory tmp-name1
'recursive
)))))
829 (ert-deftest tramp-test18-file-attributes
()
830 "Check `file-attributes'.
831 This tests also `file-readable-p' and `file-regular-p'."
832 (skip-unless (tramp--test-enabled))
833 (tramp-cleanup-connection
834 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
837 (let ((tmp-name (tramp--test-make-temp-name))
841 (write-region "foo" nil tmp-name
)
842 (should (file-exists-p tmp-name
))
843 (setq attr
(file-attributes tmp-name
))
844 (should (consp attr
))
845 (should (file-exists-p tmp-name
))
846 (should (file-readable-p tmp-name
))
847 (should (file-regular-p tmp-name
))
848 ;; We do not test inodes and device numbers.
849 (should (null (car attr
)))
850 (should (numberp (nth 1 attr
))) ;; Link.
851 (should (numberp (nth 2 attr
))) ;; Uid.
852 (should (numberp (nth 3 attr
))) ;; Gid.
854 (should (stringp (current-time-string (nth 4 attr
))))
855 ;; Last modification time.
856 (should (stringp (current-time-string (nth 5 attr
))))
857 ;; Last status change time.
858 (should (stringp (current-time-string (nth 6 attr
))))
859 (should (numberp (nth 7 attr
))) ;; Size.
860 (should (stringp (nth 8 attr
))) ;; Modes.
862 (setq attr
(file-attributes tmp-name
'string
))
863 (should (stringp (nth 2 attr
))) ;; Uid.
864 (should (stringp (nth 3 attr
))) ;; Gid.
865 (delete-file tmp-name
)
867 (make-directory tmp-name
)
868 (should (file-exists-p tmp-name
))
869 (should (file-readable-p tmp-name
))
870 (should-not (file-regular-p tmp-name
))
871 (setq attr
(file-attributes tmp-name
))
872 (should (eq (car attr
) t
)))
873 (ignore-errors (delete-directory tmp-name
)))))
875 (ert-deftest tramp-test19-directory-files-and-attributes
()
876 "Check `directory-files-and-attributes'."
877 (skip-unless (tramp--test-enabled))
878 (tramp-cleanup-connection
879 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
882 (let ((tmp-name (tramp--test-make-temp-name))
886 (make-directory tmp-name
)
887 (should (file-directory-p tmp-name
))
888 (write-region "foo" nil
(expand-file-name "foo" tmp-name
))
889 (write-region "bar" nil
(expand-file-name "bar" tmp-name
))
890 (write-region "boz" nil
(expand-file-name "boz" tmp-name
))
891 (setq attr
(directory-files-and-attributes tmp-name
))
892 (should (consp attr
))
895 (equal (file-attributes (expand-file-name (car elt
) tmp-name
))
897 (setq attr
(directory-files-and-attributes tmp-name
'full
))
900 (equal (file-attributes (car elt
)) (cdr elt
))))
901 (setq attr
(directory-files-and-attributes tmp-name nil
"^b"))
902 (should (equal (mapcar 'car attr
) '("bar" "boz"))))
903 (ignore-errors (delete-directory tmp-name
'recursive
)))))
905 (ert-deftest tramp-test20-file-modes
()
907 This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
908 (skip-unless (tramp--test-enabled))
912 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
913 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
914 (tramp-cleanup-connection
915 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
918 (let ((tmp-name (tramp--test-make-temp-name)))
921 (write-region "foo" nil tmp-name
)
922 (should (file-exists-p tmp-name
))
923 (set-file-modes tmp-name
#o777
)
924 (should (= (file-modes tmp-name
) #o777
))
925 (should (file-executable-p tmp-name
))
926 (should (file-writable-p tmp-name
))
927 (set-file-modes tmp-name
#o444
)
928 (should (= (file-modes tmp-name
) #o444
))
929 (should-not (file-executable-p tmp-name
))
930 ;; A file is always writable for user "root".
931 (when (and (stringp (file-remote-p tmp-name
'user
))
932 (not (string-equal (file-remote-p tmp-name
'user
) "root")))
933 (should-not (file-writable-p tmp-name
))))
934 (ignore-errors (delete-file tmp-name
)))))
936 (ert-deftest tramp-test21-file-links
()
937 "Check `file-symlink-p'.
938 This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
939 (skip-unless (tramp--test-enabled))
940 (tramp-cleanup-connection
941 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
944 (let ((tmp-name1 (tramp--test-make-temp-name))
945 (tmp-name2 (tramp--test-make-temp-name))
946 (tmp-name3 (make-temp-name "tramp-")))
949 (write-region "foo" nil tmp-name1
)
950 (should (file-exists-p tmp-name1
))
951 ;; Method "smb" supports `make-symbolic-link' only if the
952 ;; remote host has CIFS capabilities. tramp-adb.el and
953 ;; tramp-gvfs.el do not support symbolic links at all.
955 (make-symbolic-link tmp-name1 tmp-name2
)
958 (not (string-equal (error-message-string err
)
959 "make-symbolic-link not supported")))))
960 (should (file-symlink-p tmp-name2
))
961 (should-error (make-symbolic-link tmp-name1 tmp-name2
))
962 (make-symbolic-link tmp-name1 tmp-name2
'ok-if-already-exists
)
963 (should (file-symlink-p tmp-name2
))
964 ;; `tmp-name3' is a local file name.
965 (should-error (make-symbolic-link tmp-name1 tmp-name3
)))
967 (delete-file tmp-name1
)
968 (delete-file tmp-name2
)))
972 (write-region "foo" nil tmp-name1
)
973 (should (file-exists-p tmp-name1
))
974 (add-name-to-file tmp-name1 tmp-name2
)
975 (should-not (file-symlink-p tmp-name2
))
976 (should-error (add-name-to-file tmp-name1 tmp-name2
))
977 (add-name-to-file tmp-name1 tmp-name2
'ok-if-already-exists
)
978 (should-not (file-symlink-p tmp-name2
))
979 ;; `tmp-name3' is a local file name.
980 (should-error (add-name-to-file tmp-name1 tmp-name3
)))
982 (delete-file tmp-name1
)
983 (delete-file tmp-name2
)))
987 (write-region "foo" nil tmp-name1
)
988 (should (file-exists-p tmp-name1
))
989 (make-symbolic-link tmp-name1 tmp-name2
)
990 (should (file-symlink-p tmp-name2
))
991 (should-not (string-equal tmp-name2
(file-truename tmp-name2
)))
993 (string-equal (file-truename tmp-name1
) (file-truename tmp-name2
))))
995 (delete-file tmp-name1
)
996 (delete-file tmp-name2
)))))
998 (ert-deftest tramp-test22-file-times
()
999 "Check `set-file-times' and `file-newer-than-file-p'."
1000 (skip-unless (tramp--test-enabled))
1004 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1005 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
1006 (tramp-cleanup-connection
1007 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1010 (let ((tmp-name1 (tramp--test-make-temp-name))
1011 (tmp-name2 (tramp--test-make-temp-name))
1012 (tmp-name3 (tramp--test-make-temp-name)))
1015 (write-region "foo" nil tmp-name1
)
1016 (should (file-exists-p tmp-name1
))
1017 (should (consp (nth 5 (file-attributes tmp-name1
))))
1018 ;; '(0 0) means don't know, and will be replaced by `current-time'.
1019 (set-file-times tmp-name1
'(0 1))
1020 ;; Dumb busyboxes are not able to return the date correctly.
1021 ;; They say "don't know.
1022 (skip-unless (not (equal (nth 5 (file-attributes tmp-name1
)) '(0 0))))
1023 (should (equal (nth 5 (file-attributes tmp-name1
)) '(0 1)))
1024 (write-region "bla" nil tmp-name2
)
1025 (should (file-exists-p tmp-name2
))
1026 (should (file-newer-than-file-p tmp-name2 tmp-name1
))
1027 ;; `tmp-name3' does not exist.
1028 (should (file-newer-than-file-p tmp-name2 tmp-name3
))
1029 (should-not (file-newer-than-file-p tmp-name3 tmp-name1
)))
1031 (delete-file tmp-name1
)
1032 (delete-file tmp-name2
)))))
1034 (ert-deftest tramp-test23-visited-file-modtime
()
1035 "Check `set-visited-file-modtime' and `verify-visited-file-modtime'."
1036 (skip-unless (tramp--test-enabled))
1037 (tramp-cleanup-connection
1038 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1041 (let ((tmp-name (tramp--test-make-temp-name)))
1044 (write-region "foo" nil tmp-name
)
1045 (should (file-exists-p tmp-name
))
1047 (insert-file-contents tmp-name
)
1048 (should (verify-visited-file-modtime))
1049 (set-visited-file-modtime '(0 1))
1050 (should (verify-visited-file-modtime))
1051 (should (equal (visited-file-modtime) '(0 1 0 0)))))
1052 (ignore-errors (delete-file tmp-name
)))))
1054 (ert-deftest tramp-test24-file-name-completion
()
1055 "Check `file-name-completion' and `file-name-all-completions'."
1056 (skip-unless (tramp--test-enabled))
1057 (tramp-cleanup-connection
1058 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1061 (let ((tmp-name (tramp--test-make-temp-name)))
1064 (make-directory tmp-name
)
1065 (should (file-directory-p tmp-name
))
1066 (write-region "foo" nil
(expand-file-name "foo" tmp-name
))
1067 (write-region "bar" nil
(expand-file-name "bold" tmp-name
))
1068 (make-directory (expand-file-name "boz" tmp-name
))
1069 (should (equal (file-name-completion "fo" tmp-name
) "foo"))
1070 (should (equal (file-name-completion "b" tmp-name
) "bo"))
1072 (equal (file-name-completion "b" tmp-name
'file-directory-p
) "boz/"))
1073 (should (equal (file-name-all-completions "fo" tmp-name
) '("foo")))
1075 (equal (sort (file-name-all-completions "b" tmp-name
) 'string-lessp
)
1077 (ignore-errors (delete-directory tmp-name
'recursive
)))))
1079 (ert-deftest tramp-test25-load
()
1081 (skip-unless (tramp--test-enabled))
1082 (tramp-cleanup-connection
1083 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1086 (let ((tmp-name (tramp--test-make-temp-name)))
1089 (load tmp-name
'noerror
'nomessage
)
1090 (should-not (featurep 'tramp-test-load
))
1091 (write-region "(provide 'tramp-test-load)" nil tmp-name
)
1092 ;; `load' in lread.c does not pass `must-suffix'. Why?
1093 ;(should-error (load tmp-name nil 'nomessage 'nosuffix 'must-suffix))
1094 (load tmp-name nil
'nomessage
'nosuffix
)
1095 (should (featurep 'tramp-test-load
)))
1097 (and (featurep 'tramp-test-load
) (unload-feature 'tramp-test-load
))
1098 (delete-file tmp-name
)))))
1100 (ert-deftest tramp-test26-process-file
()
1101 "Check `process-file'."
1102 (skip-unless (tramp--test-enabled))
1106 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1107 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
1108 (tramp-cleanup-connection
1109 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1112 (let ((tmp-name (tramp--test-make-temp-name))
1113 (default-directory tramp-test-temporary-file-directory
))
1116 ;; We cannot use "/bin/true" and "/bin/false"; those paths
1117 ;; do not exist on hydra.
1118 (should (zerop (process-file "true")))
1119 (should-not (zerop (process-file "false")))
1120 (should-not (zerop (process-file "binary-does-not-exist")))
1122 (write-region "foo" nil tmp-name
)
1123 (should (file-exists-p tmp-name
))
1126 (process-file "ls" nil t nil
(file-name-nondirectory tmp-name
))))
1127 ;; `ls' could produce colorized output.
1128 (goto-char (point-min))
1129 (while (re-search-forward tramp-color-escape-sequence-regexp nil t
)
1130 (replace-match "" nil nil
))
1133 (format "%s\n" (file-name-nondirectory tmp-name
))
1135 (ignore-errors (delete-file tmp-name
)))))
1137 (ert-deftest tramp-test27-start-file-process
()
1138 "Check `start-file-process'."
1139 (skip-unless (tramp--test-enabled))
1143 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1144 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
1145 (tramp-cleanup-connection
1146 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1149 (let ((default-directory tramp-test-temporary-file-directory
)
1150 (tmp-name (tramp--test-make-temp-name))
1151 kill-buffer-query-functions proc
)
1154 (setq proc
(start-file-process "test1" (current-buffer) "cat"))
1155 (should (processp proc
))
1156 (should (equal (process-status proc
) 'run
))
1157 (process-send-string proc
"foo")
1158 (process-send-eof proc
)
1159 (accept-process-output proc
1)
1160 (should (string-equal (buffer-string) "foo")))
1161 (ignore-errors (delete-process proc
)))
1165 (write-region "foo" nil tmp-name
)
1166 (should (file-exists-p tmp-name
))
1169 "test2" (current-buffer)
1170 "cat" (file-name-nondirectory tmp-name
)))
1171 (should (processp proc
))
1172 (accept-process-output proc
1)
1173 (should (string-equal (buffer-string) "foo")))
1175 (delete-process proc
)
1176 (delete-file tmp-name
)))
1180 (setq proc
(start-file-process "test3" nil
"cat"))
1181 (should (processp proc
))
1182 (should (equal (process-status proc
) 'run
))
1184 proc
(lambda (_p s
) (should (string-equal s
"foo"))))
1185 (process-send-string proc
"foo")
1186 (process-send-eof proc
)
1187 (accept-process-output proc
1))
1188 (ignore-errors (delete-process proc
)))))
1190 (ert-deftest tramp-test28-shell-command
()
1191 "Check `shell-command'."
1192 (skip-unless (tramp--test-enabled))
1196 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1197 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
1198 (tramp-cleanup-connection
1199 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1202 (let ((tmp-name (tramp--test-make-temp-name))
1203 (default-directory tramp-test-temporary-file-directory
))
1206 (write-region "foo" nil tmp-name
)
1207 (should (file-exists-p tmp-name
))
1209 (format "ls %s" (file-name-nondirectory tmp-name
)) (current-buffer))
1210 ;; `ls' could produce colorized output.
1211 (goto-char (point-min))
1212 (while (re-search-forward tramp-color-escape-sequence-regexp nil t
)
1213 (replace-match "" nil nil
))
1216 (format "%s\n" (file-name-nondirectory tmp-name
)) (buffer-string))))
1217 (ignore-errors (delete-file tmp-name
)))
1221 (write-region "foo" nil tmp-name
)
1222 (should (file-exists-p tmp-name
))
1223 (async-shell-command
1224 (format "ls %s" (file-name-nondirectory tmp-name
)) (current-buffer))
1225 (accept-process-output (get-buffer-process (current-buffer)) 1)
1226 (while (ignore-errors
1227 (memq (process-status (get-buffer-process (current-buffer)))
1229 (accept-process-output (get-buffer-process (current-buffer)) 1))
1230 ;; `ls' could produce colorized output.
1231 (goto-char (point-min))
1232 (while (re-search-forward tramp-color-escape-sequence-regexp nil t
)
1233 (replace-match "" nil nil
))
1236 (format "%s\n" (file-name-nondirectory tmp-name
)) (buffer-string))))
1237 (ignore-errors (delete-file tmp-name
)))
1241 (write-region "foo" nil tmp-name
)
1242 (should (file-exists-p tmp-name
))
1243 (async-shell-command "read line; ls $line" (current-buffer))
1244 (process-send-string
1245 (get-buffer-process (current-buffer))
1246 (format "%s\n" (file-name-nondirectory tmp-name
)))
1247 (accept-process-output (get-buffer-process (current-buffer)) 1)
1248 (while (ignore-errors
1249 (memq (process-status (get-buffer-process (current-buffer)))
1251 (accept-process-output (get-buffer-process (current-buffer)) 1))
1254 (format "%s\n" (file-name-nondirectory tmp-name
)) (buffer-string))))
1255 (ignore-errors (delete-file tmp-name
)))))
1257 (ert-deftest tramp-test29-vc-registered
()
1258 "Check `vc-registered'."
1259 (skip-unless (tramp--test-enabled))
1262 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1263 'tramp-sh-file-name-handler
))
1264 (tramp-cleanup-connection
1265 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1268 (let* ((default-directory tramp-test-temporary-file-directory
)
1269 (tmp-name1 (tramp--test-make-temp-name))
1270 (tmp-name2 (expand-file-name "foo" tmp-name1
))
1271 (vc-handled-backends
1272 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
1274 ((tramp-find-executable v vc-bzr-program
(tramp-get-remote-path v
))
1276 ((tramp-find-executable v vc-git-program
(tramp-get-remote-path v
))
1278 ((tramp-find-executable v vc-hg-program
(tramp-get-remote-path v
))
1281 (skip-unless vc-handled-backends
)
1282 (message "%s" vc-handled-backends
)
1286 (make-directory tmp-name1
)
1287 (write-region "foo" nil tmp-name2
)
1288 (should (file-directory-p tmp-name1
))
1289 (should (file-exists-p tmp-name2
))
1290 (should-not (vc-registered tmp-name1
))
1291 (should-not (vc-registered tmp-name2
))
1293 (let ((default-directory tmp-name1
))
1294 ;; Create empty repository, and register the file.
1295 (vc-create-repo (car vc-handled-backends
))
1296 ;; The structure of VC-FILESET is not documented. Let's
1297 ;; hope it won't change.
1299 nil
(list (car vc-handled-backends
)
1300 (list (file-name-nondirectory tmp-name2
)))))
1301 (should (vc-registered tmp-name2
)))
1303 (ignore-errors (delete-directory tmp-name1
'recursive
)))))
1305 (ert-deftest tramp-test30-utf8
()
1306 "Check UTF8 encoding in file names and file contents."
1307 (skip-unless (tramp--test-enabled))
1308 (tramp-cleanup-connection
1309 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1312 (let ((tmp-name (tramp--test-make-temp-name))
1313 (coding-system-for-read 'utf-8
)
1314 (coding-system-for-write 'utf-8
)
1315 (arabic "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت")
1316 (chinese "银河系漫游指南系列")
1317 (russian "Автостопом по гала́ктике"))
1320 (make-directory tmp-name
)
1321 (dolist (lang `(,arabic
,chinese
,russian
))
1322 (let ((file (expand-file-name lang tmp-name
)))
1323 (write-region lang nil file
)
1324 (should (file-exists-p file
))
1325 ;; Check file contents.
1327 (insert-file-contents file
)
1328 (should (string-equal (buffer-string) lang
)))))
1329 ;; Check file names.
1330 (should (equal (directory-files
1331 tmp-name nil directory-files-no-dot-files-regexp
)
1332 (sort `(,arabic
,chinese
,russian
) 'string-lessp
))))
1333 (ignore-errors (delete-directory tmp-name
'recursive
)))))
1337 ;; * dired-compress-file
1340 ;; * file-ownership-preserved-p
1341 ;; * file-selinux-context
1342 ;; * find-backup-file-name
1343 ;; * make-auto-save-file-name
1345 ;; * set-file-selinux-context
1347 ;; * Fix `tramp-test17-insert-directory' for
1348 ;; `ls-lisp-insert-directory' ("plink" and friends, tramp-gvfs.el).
1349 ;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?).
1350 ;; * Fix `tramp-test28-shell-command' on MS Windows (`process-send-eof'?).
1351 ;; * Fix `tramp-test30-utf8' on MS Windows. Seems to be in `directory-files'.
1353 (defun tramp-test-all (&optional interactive
)
1354 "Run all tests for \\[tramp]."
1357 (if interactive
'ert-run-tests-interactively
'ert-run-tests-batch
) "^tramp"))
1359 (provide 'tramp-tests
)
1360 ;;; tramp-tests.el ends here