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 (defmacro tramp--instrument-test-case
(verbose &rest body
)
93 "Run BODY with `tramp-verbose' equal VERBOSE.
94 Print the the content of the Tramp debug buffer, if BODY does not
95 eval properly in `should', `should-not' or `should-error'."
96 `(let ((tramp-verbose ,verbose
))
100 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
101 (with-current-buffer (tramp-get-debug-buffer v
)
102 (message "%s" (buffer-string))))
103 (signal (car err
) (cdr err
))))))
104 (put 'tramp--instrument-test-case
'lisp-indent-function
1)
106 (ert-deftest tramp-test00-availability
()
107 "Test availability of Tramp functions."
108 :expected-result
(if (tramp--test-enabled) :passed
:failed
)
109 (should (ignore-errors
111 (file-remote-p tramp-test-temporary-file-directory
)
112 (file-directory-p tramp-test-temporary-file-directory
)
113 (file-writable-p tramp-test-temporary-file-directory
)))))
115 (ert-deftest tramp-test01-file-name-syntax
()
116 "Check remote file name syntax."
118 (should (tramp-tramp-file-p "/method::"))
119 (should (tramp-tramp-file-p "/host:"))
120 (should (tramp-tramp-file-p "/user@:"))
121 (should (tramp-tramp-file-p "/user@host:"))
122 (should (tramp-tramp-file-p "/method:host:"))
123 (should (tramp-tramp-file-p "/method:user@:"))
124 (should (tramp-tramp-file-p "/method:user@host:"))
125 (should (tramp-tramp-file-p "/method:user@email@host:"))
128 (should (tramp-tramp-file-p "/host#1234:"))
129 (should (tramp-tramp-file-p "/user@host#1234:"))
130 (should (tramp-tramp-file-p "/method:host#1234:"))
131 (should (tramp-tramp-file-p "/method:user@host#1234:"))
133 ;; Using an IPv4 address.
134 (should (tramp-tramp-file-p "/1.2.3.4:"))
135 (should (tramp-tramp-file-p "/user@1.2.3.4:"))
136 (should (tramp-tramp-file-p "/method:1.2.3.4:"))
137 (should (tramp-tramp-file-p "/method:user@1.2.3.4:"))
139 ;; Using an IPv6 address.
140 (should (tramp-tramp-file-p "/[]:"))
141 (should (tramp-tramp-file-p "/[::1]:"))
142 (should (tramp-tramp-file-p "/user@[::1]:"))
143 (should (tramp-tramp-file-p "/method:[::1]:"))
144 (should (tramp-tramp-file-p "/method:user@[::1]:"))
146 ;; Local file name part.
147 (should (tramp-tramp-file-p "/host:/:"))
148 (should (tramp-tramp-file-p "/method:::"))
149 (should (tramp-tramp-file-p "/method::/path/to/file"))
150 (should (tramp-tramp-file-p "/method::file"))
153 (should (tramp-tramp-file-p "/method1:|method2::"))
154 (should (tramp-tramp-file-p "/method1:host1|host2:"))
155 (should (tramp-tramp-file-p "/method1:host1|method2:host2:"))
156 (should (tramp-tramp-file-p "/method1:user1@host1|method2:user2@host2:"))
157 (should (tramp-tramp-file-p
158 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:"))
161 (should-not (tramp-tramp-file-p nil
))
162 (should-not (tramp-tramp-file-p 'symbol
))
163 ;; "/:" suppresses file name handlers.
164 (should-not (tramp-tramp-file-p "/::"))
165 (should-not (tramp-tramp-file-p "/:@:"))
166 (should-not (tramp-tramp-file-p "/:[]:"))
167 ;; Multihops require a method.
168 (should-not (tramp-tramp-file-p "/host1|host2:"))
169 ;; Methods or hostnames shall be at least two characters on MS Windows.
170 (when (memq system-type
'(cygwin windows-nt
))
171 (should-not (tramp-tramp-file-p "/c:/path/to/file"))
172 (should-not (tramp-tramp-file-p "/c::/path/to/file"))))
174 (ert-deftest tramp-test02-file-name-dissect
()
175 "Check remote file name components."
176 (let ((tramp-default-method "default-method")
177 (tramp-default-user "default-user")
178 (tramp-default-host "default-host"))
179 ;; Expand `tramp-default-user' and `tramp-default-host'.
180 (should (string-equal
181 (file-remote-p "/method::")
182 (format "/%s:%s@%s:" "method" "default-user" "default-host")))
183 (should (string-equal (file-remote-p "/method::" 'method
) "method"))
184 (should (string-equal (file-remote-p "/method::" 'user
) "default-user"))
185 (should (string-equal (file-remote-p "/method::" 'host
) "default-host"))
186 (should (string-equal (file-remote-p "/method::" 'localname
) ""))
188 ;; Expand `tramp-default-method' and `tramp-default-user'.
189 (should (string-equal
190 (file-remote-p "/host:")
191 (format "/%s:%s@%s:" "default-method" "default-user" "host")))
192 (should (string-equal (file-remote-p "/host:" 'method
) "default-method"))
193 (should (string-equal (file-remote-p "/host:" 'user
) "default-user"))
194 (should (string-equal (file-remote-p "/host:" 'host
) "host"))
195 (should (string-equal (file-remote-p "/host:" 'localname
) ""))
197 ;; Expand `tramp-default-method' and `tramp-default-host'.
198 (should (string-equal
199 (file-remote-p "/user@:")
200 (format "/%s:%s@%s:" "default-method""user" "default-host")))
201 (should (string-equal (file-remote-p "/user@:" 'method
) "default-method"))
202 (should (string-equal (file-remote-p "/user@:" 'user
) "user"))
203 (should (string-equal (file-remote-p "/user@:" 'host
) "default-host"))
204 (should (string-equal (file-remote-p "/user@:" 'localname
) ""))
206 ;; Expand `tramp-default-method'.
207 (should (string-equal
208 (file-remote-p "/user@host:")
209 (format "/%s:%s@%s:" "default-method" "user" "host")))
210 (should (string-equal
211 (file-remote-p "/user@host:" 'method
) "default-method"))
212 (should (string-equal (file-remote-p "/user@host:" 'user
) "user"))
213 (should (string-equal (file-remote-p "/user@host:" 'host
) "host"))
214 (should (string-equal (file-remote-p "/user@host:" 'localname
) ""))
216 ;; Expand `tramp-default-user'.
217 (should (string-equal
218 (file-remote-p "/method:host:")
219 (format "/%s:%s@%s:" "method" "default-user" "host")))
220 (should (string-equal (file-remote-p "/method:host:" 'method
) "method"))
221 (should (string-equal (file-remote-p "/method:host:" 'user
) "default-user"))
222 (should (string-equal (file-remote-p "/method:host:" 'host
) "host"))
223 (should (string-equal (file-remote-p "/method:host:" 'localname
) ""))
225 ;; Expand `tramp-default-host'.
226 (should (string-equal
227 (file-remote-p "/method:user@:")
228 (format "/%s:%s@%s:" "method" "user" "default-host")))
229 (should (string-equal (file-remote-p "/method:user@:" 'method
) "method"))
230 (should (string-equal (file-remote-p "/method:user@:" 'user
) "user"))
231 (should (string-equal (file-remote-p "/method:user@:" 'host
)
233 (should (string-equal (file-remote-p "/method:user@:" 'localname
) ""))
236 (should (string-equal
237 (file-remote-p "/method:user@host:")
238 (format "/%s:%s@%s:" "method" "user" "host")))
239 (should (string-equal
240 (file-remote-p "/method:user@host:" 'method
) "method"))
241 (should (string-equal (file-remote-p "/method:user@host:" 'user
) "user"))
242 (should (string-equal (file-remote-p "/method:user@host:" 'host
) "host"))
243 (should (string-equal (file-remote-p "/method:user@host:" 'localname
) ""))
246 (should (string-equal
247 (file-remote-p "/method:user@email@host:")
248 (format "/%s:%s@%s:" "method" "user@email" "host")))
249 (should (string-equal
250 (file-remote-p "/method:user@email@host:" 'method
) "method"))
251 (should (string-equal
252 (file-remote-p "/method:user@email@host:" 'user
) "user@email"))
253 (should (string-equal
254 (file-remote-p "/method:user@email@host:" 'host
) "host"))
255 (should (string-equal
256 (file-remote-p "/method:user@email@host:" 'localname
) ""))
258 ;; Expand `tramp-default-method' and `tramp-default-user'.
259 (should (string-equal
260 (file-remote-p "/host#1234:")
261 (format "/%s:%s@%s:" "default-method" "default-user" "host#1234")))
262 (should (string-equal
263 (file-remote-p "/host#1234:" 'method
) "default-method"))
264 (should (string-equal (file-remote-p "/host#1234:" 'user
) "default-user"))
265 (should (string-equal (file-remote-p "/host#1234:" 'host
) "host#1234"))
266 (should (string-equal (file-remote-p "/host#1234:" 'localname
) ""))
268 ;; Expand `tramp-default-method'.
269 (should (string-equal
270 (file-remote-p "/user@host#1234:")
271 (format "/%s:%s@%s:" "default-method" "user" "host#1234")))
272 (should (string-equal
273 (file-remote-p "/user@host#1234:" 'method
) "default-method"))
274 (should (string-equal (file-remote-p "/user@host#1234:" 'user
) "user"))
275 (should (string-equal (file-remote-p "/user@host#1234:" 'host
) "host#1234"))
276 (should (string-equal (file-remote-p "/user@host#1234:" 'localname
) ""))
278 ;; Expand `tramp-default-user'.
279 (should (string-equal
280 (file-remote-p "/method:host#1234:")
281 (format "/%s:%s@%s:" "method" "default-user" "host#1234")))
282 (should (string-equal
283 (file-remote-p "/method:host#1234:" 'method
) "method"))
284 (should (string-equal
285 (file-remote-p "/method:host#1234:" 'user
) "default-user"))
286 (should (string-equal
287 (file-remote-p "/method:host#1234:" 'host
) "host#1234"))
288 (should (string-equal (file-remote-p "/method:host#1234:" 'localname
) ""))
291 (should (string-equal
292 (file-remote-p "/method:user@host#1234:")
293 (format "/%s:%s@%s:" "method" "user" "host#1234")))
294 (should (string-equal
295 (file-remote-p "/method:user@host#1234:" 'method
) "method"))
296 (should (string-equal
297 (file-remote-p "/method:user@host#1234:" 'user
) "user"))
298 (should (string-equal
299 (file-remote-p "/method:user@host#1234:" 'host
) "host#1234"))
300 (should (string-equal
301 (file-remote-p "/method:user@host#1234:" 'localname
) ""))
303 ;; Expand `tramp-default-method' and `tramp-default-user'.
304 (should (string-equal
305 (file-remote-p "/1.2.3.4:")
306 (format "/%s:%s@%s:" "default-method" "default-user" "1.2.3.4")))
307 (should (string-equal (file-remote-p "/1.2.3.4:" 'method
) "default-method"))
308 (should (string-equal (file-remote-p "/1.2.3.4:" 'user
) "default-user"))
309 (should (string-equal (file-remote-p "/1.2.3.4:" 'host
) "1.2.3.4"))
310 (should (string-equal (file-remote-p "/1.2.3.4:" 'localname
) ""))
312 ;; Expand `tramp-default-method'.
313 (should (string-equal
314 (file-remote-p "/user@1.2.3.4:")
315 (format "/%s:%s@%s:" "default-method" "user" "1.2.3.4")))
316 (should (string-equal
317 (file-remote-p "/user@1.2.3.4:" 'method
) "default-method"))
318 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'user
) "user"))
319 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'host
) "1.2.3.4"))
320 (should (string-equal (file-remote-p "/user@1.2.3.4:" 'localname
) ""))
322 ;; Expand `tramp-default-user'.
323 (should (string-equal
324 (file-remote-p "/method:1.2.3.4:")
325 (format "/%s:%s@%s:" "method" "default-user" "1.2.3.4")))
326 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'method
) "method"))
327 (should (string-equal
328 (file-remote-p "/method:1.2.3.4:" 'user
) "default-user"))
329 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'host
) "1.2.3.4"))
330 (should (string-equal (file-remote-p "/method:1.2.3.4:" 'localname
) ""))
333 (should (string-equal
334 (file-remote-p "/method:user@1.2.3.4:")
335 (format "/%s:%s@%s:" "method" "user" "1.2.3.4")))
336 (should (string-equal
337 (file-remote-p "/method:user@1.2.3.4:" 'method
) "method"))
338 (should (string-equal (file-remote-p "/method:user@1.2.3.4:" 'user
) "user"))
339 (should (string-equal
340 (file-remote-p "/method:user@1.2.3.4:" 'host
) "1.2.3.4"))
341 (should (string-equal
342 (file-remote-p "/method:user@1.2.3.4:" 'localname
) ""))
344 ;; Expand `tramp-default-method', `tramp-default-user' and
345 ;; `tramp-default-host'.
346 (should (string-equal
347 (file-remote-p "/[]:")
349 "/%s:%s@%s:" "default-method" "default-user" "default-host")))
350 (should (string-equal (file-remote-p "/[]:" 'method
) "default-method"))
351 (should (string-equal (file-remote-p "/[]:" 'user
) "default-user"))
352 (should (string-equal (file-remote-p "/[]:" 'host
) "default-host"))
353 (should (string-equal (file-remote-p "/[]:" 'localname
) ""))
355 ;; Expand `tramp-default-method' and `tramp-default-user'.
356 (let ((tramp-default-host "::1"))
357 (should (string-equal
358 (file-remote-p "/[]:")
359 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
360 (should (string-equal (file-remote-p "/[]:" 'method
) "default-method"))
361 (should (string-equal (file-remote-p "/[]:" 'user
) "default-user"))
362 (should (string-equal (file-remote-p "/[]:" 'host
) "::1"))
363 (should (string-equal (file-remote-p "/[]:" 'localname
) "")))
365 ;; Expand `tramp-default-method' and `tramp-default-user'.
366 (should (string-equal
367 (file-remote-p "/[::1]:")
368 (format "/%s:%s@%s:" "default-method" "default-user" "[::1]")))
369 (should (string-equal (file-remote-p "/[::1]:" 'method
) "default-method"))
370 (should (string-equal (file-remote-p "/[::1]:" 'user
) "default-user"))
371 (should (string-equal (file-remote-p "/[::1]:" 'host
) "::1"))
372 (should (string-equal (file-remote-p "/[::1]:" 'localname
) ""))
374 ;; Expand `tramp-default-method'.
375 (should (string-equal
376 (file-remote-p "/user@[::1]:")
377 (format "/%s:%s@%s:" "default-method" "user" "[::1]")))
378 (should (string-equal
379 (file-remote-p "/user@[::1]:" 'method
) "default-method"))
380 (should (string-equal (file-remote-p "/user@[::1]:" 'user
) "user"))
381 (should (string-equal (file-remote-p "/user@[::1]:" 'host
) "::1"))
382 (should (string-equal (file-remote-p "/user@[::1]:" 'localname
) ""))
384 ;; Expand `tramp-default-user'.
385 (should (string-equal
386 (file-remote-p "/method:[::1]:")
387 (format "/%s:%s@%s:" "method" "default-user" "[::1]")))
388 (should (string-equal (file-remote-p "/method:[::1]:" 'method
) "method"))
389 (should (string-equal
390 (file-remote-p "/method:[::1]:" 'user
) "default-user"))
391 (should (string-equal (file-remote-p "/method:[::1]:" 'host
) "::1"))
392 (should (string-equal (file-remote-p "/method:[::1]:" 'localname
) ""))
395 (should (string-equal
396 (file-remote-p "/method:user@[::1]:")
397 (format "/%s:%s@%s:" "method" "user" "[::1]")))
398 (should (string-equal
399 (file-remote-p "/method:user@[::1]:" 'method
) "method"))
400 (should (string-equal (file-remote-p "/method:user@[::1]:" 'user
) "user"))
401 (should (string-equal (file-remote-p "/method:user@[::1]:" 'host
) "::1"))
402 (should (string-equal
403 (file-remote-p "/method:user@[::1]:" 'localname
) ""))
405 ;; Local file name part.
406 (should (string-equal (file-remote-p "/host:/:" 'localname
) "/:"))
407 (should (string-equal (file-remote-p "/method:::" 'localname
) ":"))
408 (should (string-equal (file-remote-p "/method:: " 'localname
) " "))
409 (should (string-equal (file-remote-p "/method::file" 'localname
) "file"))
410 (should (string-equal
411 (file-remote-p "/method::/path/to/file" 'localname
)
417 (file-remote-p "/method1:user1@host1|method2:user2@host2:/path/to/file")
418 (format "/%s:%s@%s:" "method2" "user2" "host2")))
422 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'method
)
427 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'user
)
432 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'host
)
437 "/method1:user1@host1|method2:user2@host2:/path/to/file" 'localname
)
443 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file")
444 (format "/%s:%s@%s:" "method3" "user3" "host3")))
448 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
454 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
460 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
466 "/method1:user1@host1|method2:user2@host2|method3:user3@host3:/path/to/file"
470 (ert-deftest tramp-test03-file-name-defaults
()
471 "Check default values for some methods."
472 ;; Default values in tramp-adb.el.
473 (should (string-equal (file-remote-p "/adb::" 'host
) ""))
474 ;; Default values in tramp-ftp.el.
475 (should (string-equal (file-remote-p "/ftp.host:" 'method
) "ftp"))
476 (dolist (u '("ftp" "anonymous"))
477 (should (string-equal (file-remote-p (format "/%s@:" u
) 'method
) "ftp")))
478 ;; Default values in tramp-gvfs.el.
479 (when (and (load "tramp-gvfs" 'noerror
'nomessage
)
480 (symbol-value 'tramp-gvfs-enabled
))
481 (should (string-equal (file-remote-p "/synce::" 'user
) nil
)))
482 ;; Default values in tramp-gw.el.
483 (dolist (m '("tunnel" "socks"))
485 (string-equal (file-remote-p (format "/%s::" m
) 'user
) (user-login-name))))
486 ;; Default values in tramp-sh.el.
487 (dolist (h `("127.0.0.1" "[::1]" "localhost" "localhost6" ,(system-name)))
488 (should (string-equal (file-remote-p (format "/root@%s:" h
) 'method
) "su")))
489 (dolist (m '("su" "sudo" "ksu"))
490 (should (string-equal (file-remote-p (format "/%s::" m
) 'user
) "root")))
491 (dolist (m '("rcp" "remcp" "rsh" "telnet" "krlogin" "fcp"))
493 (string-equal (file-remote-p (format "/%s::" m
) 'user
) (user-login-name))))
494 ;; Default values in tramp-smb.el.
495 (should (string-equal (file-remote-p "/user%domain@host:" 'method
) "smb"))
496 (should (string-equal (file-remote-p "/smb::" 'user
) nil
)))
498 (ert-deftest tramp-test04-substitute-in-file-name
()
499 "Check `substitute-in-file-name'."
500 (should (string-equal (substitute-in-file-name "/method:host://foo") "/foo"))
503 (substitute-in-file-name "/method:host:/path//foo") "/method:host:/foo"))
505 (string-equal (substitute-in-file-name "/method:host:/path///foo") "/foo"))
508 (substitute-in-file-name "/method:host:/path/~/foo") "/method:host:~/foo"))
510 (string-equal (substitute-in-file-name "/method:host:/path//~/foo") "~/foo"))
511 (let (process-environment)
514 (substitute-in-file-name "/method:host:/path/$FOO")
515 "/method:host:/path/$FOO"))
519 (substitute-in-file-name "/method:host:/path/$FOO")
520 "/method:host:/path/bla"))
523 (substitute-in-file-name "/method:host:/path/$$FOO")
524 "/method:host:/path/$FOO"))))
526 (ert-deftest tramp-test05-expand-file-name
()
527 "Check `expand-file-name'."
530 (expand-file-name "/method:host:/path/./file") "/method:host:/path/file"))
533 (expand-file-name "/method:host:/path/../file") "/method:host:/file")))
535 (ert-deftest tramp-test06-directory-file-name
()
536 "Check `directory-file-name'.
537 This checks also `file-name-as-directory', `file-name-directory'
538 and `file-name-nondirectory'."
541 (directory-file-name "/method:host:/path/to/file")
542 "/method:host:/path/to/file"))
545 (directory-file-name "/method:host:/path/to/file/")
546 "/method:host:/path/to/file"))
549 (file-name-as-directory "/method:host:/path/to/file")
550 "/method:host:/path/to/file/"))
553 (file-name-as-directory "/method:host:/path/to/file/")
554 "/method:host:/path/to/file/"))
557 (file-name-directory "/method:host:/path/to/file")
558 "/method:host:/path/to/"))
561 (file-name-directory "/method:host:/path/to/file/")
562 "/method:host:/path/to/file/"))
564 (string-equal (file-name-nondirectory "/method:host:/path/to/file") "file"))
566 (string-equal (file-name-nondirectory "/method:host:/path/to/file/") ""))
569 (unhandled-file-name-directory "/method:host:/path/to/file"))))
571 (ert-deftest tramp-test07-file-exists-p
()
572 "Check `file-exist-p', `write-region' and `delete-file'."
573 (skip-unless (tramp--test-enabled))
574 (tramp-cleanup-connection
575 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
578 (let ((tmp-name (tramp--test-make-temp-name)))
579 (should-not (file-exists-p tmp-name
))
580 (write-region "foo" nil tmp-name
)
581 (should (file-exists-p tmp-name
))
582 (delete-file tmp-name
)
583 (should-not (file-exists-p tmp-name
))))
585 (ert-deftest tramp-test08-file-local-copy
()
586 "Check `file-local-copy'."
587 (skip-unless (tramp--test-enabled))
588 (tramp-cleanup-connection
589 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
592 (let ((tmp-name1 (tramp--test-make-temp-name))
596 (write-region "foo" nil tmp-name1
)
597 (should (setq tmp-name2
(file-local-copy tmp-name1
)))
599 (insert-file-contents tmp-name2
)
600 (should (string-equal (buffer-string) "foo"))))
602 (delete-file tmp-name1
)
603 (delete-file tmp-name2
)))))
605 (ert-deftest tramp-test09-insert-file-contents
()
606 "Check `insert-file-contents'."
607 (skip-unless (tramp--test-enabled))
608 (tramp-cleanup-connection
609 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
612 (let ((tmp-name (tramp--test-make-temp-name)))
615 (write-region "foo" nil tmp-name
)
617 (insert-file-contents tmp-name
)
618 (should (string-equal (buffer-string) "foo"))
619 (insert-file-contents tmp-name
)
620 (should (string-equal (buffer-string) "foofoo"))
622 (insert-file-contents tmp-name nil
1 3)
623 (should (string-equal (buffer-string) "oofoofoo"))
625 (insert-file-contents tmp-name nil nil nil
'replace
)
626 (should (string-equal (buffer-string) "foo"))))
627 (ignore-errors (delete-file tmp-name
)))))
629 (ert-deftest tramp-test10-write-region
()
630 "Check `write-region'."
631 (skip-unless (tramp--test-enabled))
632 (tramp-cleanup-connection
633 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
636 (let ((tmp-name (tramp--test-make-temp-name)))
641 (write-region nil nil tmp-name
))
643 (insert-file-contents tmp-name
)
644 (should (string-equal (buffer-string) "foo")))
648 (write-region nil nil tmp-name
'append
))
650 (insert-file-contents tmp-name
)
651 (should (string-equal (buffer-string) "foobla")))
653 (write-region "foo" nil tmp-name
)
655 (insert-file-contents tmp-name
)
656 (should (string-equal (buffer-string) "foo")))
660 (write-region 3 5 tmp-name
))
662 (insert-file-contents tmp-name
)
663 (should (string-equal (buffer-string) "34"))))
664 (ignore-errors (delete-file tmp-name
)))))
666 (ert-deftest tramp-test11-copy-file
()
668 (skip-unless (tramp--test-enabled))
669 (tramp-cleanup-connection
670 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
673 (let ((tmp-name1 (tramp--test-make-temp-name))
674 (tmp-name2 (tramp--test-make-temp-name)))
677 (write-region "foo" nil tmp-name1
)
678 (copy-file tmp-name1 tmp-name2
)
679 (should (file-exists-p tmp-name2
))
681 (insert-file-contents tmp-name2
)
682 (should (string-equal (buffer-string) "foo"))))
684 (delete-file tmp-name1
)
685 (delete-file tmp-name2
)))))
687 (ert-deftest tramp-test12-rename-file
()
688 "Check `rename-file'."
689 (skip-unless (tramp--test-enabled))
690 (tramp-cleanup-connection
691 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
694 (let ((tmp-name1 (tramp--test-make-temp-name))
695 (tmp-name2 (tramp--test-make-temp-name)))
698 (write-region "foo" nil tmp-name1
)
699 (rename-file tmp-name1 tmp-name2
)
700 (should-not (file-exists-p tmp-name1
))
701 (should (file-exists-p tmp-name2
))
703 (insert-file-contents tmp-name2
)
704 (should (string-equal (buffer-string) "foo"))))
705 (ignore-errors (delete-file tmp-name2
)))))
707 (ert-deftest tramp-test13-make-directory
()
708 "Check `make-directory'.
709 This tests also `file-directory-p' and `file-accessible-directory-p'."
710 (skip-unless (tramp--test-enabled))
711 (tramp-cleanup-connection
712 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
715 (let ((tmp-name (tramp--test-make-temp-name)))
718 (make-directory tmp-name
)
719 (should (file-directory-p tmp-name
))
720 (should (file-accessible-directory-p tmp-name
)))
721 (ignore-errors (delete-directory tmp-name
)))))
723 (ert-deftest tramp-test14-delete-directory
()
724 "Check `delete-directory'."
725 (skip-unless (tramp--test-enabled))
726 (tramp-cleanup-connection
727 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
730 (let ((tmp-name (tramp--test-make-temp-name)))
731 ;; Delete empty directory.
732 (make-directory tmp-name
)
733 (should (file-directory-p tmp-name
))
734 (delete-directory tmp-name
)
735 (should-not (file-directory-p tmp-name
))
736 ;; Delete non-empty directory.
737 (make-directory tmp-name
)
738 (write-region "foo" nil
(expand-file-name "bla" tmp-name
))
739 (should-error (delete-directory tmp-name
))
740 (delete-directory tmp-name
'recursive
)
741 (should-not (file-directory-p tmp-name
))))
743 (ert-deftest tramp-test15-copy-directory
()
744 "Check `copy-directory'."
745 (skip-unless (tramp--test-enabled))
746 (tramp-cleanup-connection
747 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
750 (let* ((tmp-name1 (tramp--test-make-temp-name))
751 (tmp-name2 (tramp--test-make-temp-name))
752 (tmp-name3 (expand-file-name
753 (file-name-nondirectory tmp-name1
) tmp-name2
))
754 (tmp-name4 (expand-file-name "foo" tmp-name1
))
755 (tmp-name5 (expand-file-name "foo" tmp-name2
))
756 (tmp-name6 (expand-file-name "foo" tmp-name3
)))
759 ;; Copy empty directory.
760 (make-directory tmp-name1
)
761 (write-region "foo" nil tmp-name4
)
762 (should (file-directory-p tmp-name1
))
763 (should (file-exists-p tmp-name4
))
764 (copy-directory tmp-name1 tmp-name2
)
765 (should (file-directory-p tmp-name2
))
766 (should (file-exists-p tmp-name5
))
767 ;; Target directory does exist already.
768 (copy-directory tmp-name1 tmp-name2
)
769 (should (file-directory-p tmp-name3
))
770 (should (file-exists-p tmp-name6
)))
772 (delete-directory tmp-name1
'recursive
)
773 (delete-directory tmp-name2
'recursive
)))))
775 (ert-deftest tramp-test16-directory-files
()
776 "Check `directory-files'."
777 (skip-unless (tramp--test-enabled))
778 (tramp-cleanup-connection
779 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
782 (let* ((tmp-name1 (tramp--test-make-temp-name))
783 (tmp-name2 (expand-file-name "bla" tmp-name1
))
784 (tmp-name3 (expand-file-name "foo" tmp-name1
)))
787 (make-directory tmp-name1
)
788 (write-region "foo" nil tmp-name2
)
789 (write-region "bla" nil tmp-name3
)
790 (should (file-directory-p tmp-name1
))
791 (should (file-exists-p tmp-name2
))
792 (should (file-exists-p tmp-name3
))
793 (should (equal (directory-files tmp-name1
) '("." ".." "bla" "foo")))
794 (should (equal (directory-files tmp-name1
'full
)
795 `(,(concat tmp-name1
"/.")
796 ,(concat tmp-name1
"/..")
797 ,tmp-name2
,tmp-name3
)))
798 (should (equal (directory-files
799 tmp-name1 nil directory-files-no-dot-files-regexp
)
801 (should (equal (directory-files
802 tmp-name1
'full directory-files-no-dot-files-regexp
)
803 `(,tmp-name2
,tmp-name3
))))
804 (ignore-errors (delete-directory tmp-name1
'recursive
)))))
806 (ert-deftest tramp-test17-insert-directory
()
807 "Check `insert-directory'."
808 (skip-unless (tramp--test-enabled))
809 (tramp-cleanup-connection
810 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
813 (let* ((tmp-name1 (tramp--test-make-temp-name))
814 (tmp-name2 (expand-file-name "foo" tmp-name1
)))
817 (make-directory tmp-name1
)
818 (write-region "foo" nil tmp-name2
)
819 (should (file-directory-p tmp-name1
))
820 (should (file-exists-p tmp-name2
))
822 (insert-directory tmp-name1 nil
)
823 (goto-char (point-min))
824 (should (looking-at-p (regexp-quote tmp-name1
))))
826 (insert-directory tmp-name1
"-al")
827 (goto-char (point-min))
828 (should (looking-at-p (format "^.+ %s$" (regexp-quote tmp-name1
)))))
830 (insert-directory (file-name-as-directory tmp-name1
) "-al")
831 (goto-char (point-min))
833 (looking-at-p (format "^.+ %s/$" (regexp-quote tmp-name1
)))))
836 (file-name-as-directory tmp-name1
) "-al" nil
'full-directory-p
)
837 (goto-char (point-min))
840 "\\(total.+[[:digit:]]+\n\\)?.+ \\.\n.+ \\.\\.\n.+ foo$"))))
841 (ignore-errors (delete-directory tmp-name1
'recursive
)))))
843 (ert-deftest tramp-test18-file-attributes
()
844 "Check `file-attributes'.
845 This tests also `file-readable-p' and `file-regular-p'."
846 (skip-unless (tramp--test-enabled))
847 (tramp-cleanup-connection
848 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
851 (let ((tmp-name (tramp--test-make-temp-name))
855 (write-region "foo" nil tmp-name
)
856 (should (file-exists-p tmp-name
))
857 (setq attr
(file-attributes tmp-name
))
858 (should (consp attr
))
859 (should (file-exists-p tmp-name
))
860 (should (file-readable-p tmp-name
))
861 (should (file-regular-p tmp-name
))
862 ;; We do not test inodes and device numbers.
863 (should (null (car attr
)))
864 (should (numberp (nth 1 attr
))) ;; Link.
865 (should (numberp (nth 2 attr
))) ;; Uid.
866 (should (numberp (nth 3 attr
))) ;; Gid.
868 (should (stringp (current-time-string (nth 4 attr
))))
869 ;; Last modification time.
870 (should (stringp (current-time-string (nth 5 attr
))))
871 ;; Last status change time.
872 (should (stringp (current-time-string (nth 6 attr
))))
873 (should (numberp (nth 7 attr
))) ;; Size.
874 (should (stringp (nth 8 attr
))) ;; Modes.
876 (setq attr
(file-attributes tmp-name
'string
))
877 (should (stringp (nth 2 attr
))) ;; Uid.
878 (should (stringp (nth 3 attr
))) ;; Gid.
879 (delete-file tmp-name
)
881 (make-directory tmp-name
)
882 (should (file-exists-p tmp-name
))
883 (should (file-readable-p tmp-name
))
884 (should-not (file-regular-p tmp-name
))
885 (setq attr
(file-attributes tmp-name
))
886 (should (eq (car attr
) t
)))
887 (ignore-errors (delete-directory tmp-name
)))))
889 (ert-deftest tramp-test19-directory-files-and-attributes
()
890 "Check `directory-files-and-attributes'."
891 (skip-unless (tramp--test-enabled))
892 (tramp-cleanup-connection
893 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
896 (tramp--instrument-test-case 10
897 (let ((tmp-name (tramp--test-make-temp-name))
901 (make-directory tmp-name
)
902 (should (file-directory-p tmp-name
))
903 (write-region "foo" nil
(expand-file-name "foo" tmp-name
))
904 (write-region "bar" nil
(expand-file-name "bar" tmp-name
))
905 (write-region "boz" nil
(expand-file-name "boz" tmp-name
))
906 (setq attr
(directory-files-and-attributes tmp-name
))
907 (should (consp attr
))
909 ;; We cannot include "." and "..". They might have
910 ;; changed their timestamp already.
911 (when (string-match "foo$\\|bar$\\|baz$" (car elt
))
913 (equal (file-attributes (expand-file-name (car elt
) tmp-name
))
915 (setq attr
(directory-files-and-attributes tmp-name
'full
))
917 ;; We cannot include "." and "..". They might have
918 ;; changed their timestamp already.
919 (when (string-match "foo$\\|bar$\\|baz$" (car elt
))
921 (equal (file-attributes (car elt
)) (cdr elt
)))))
922 (setq attr
(directory-files-and-attributes tmp-name nil
"^b"))
923 (should (equal (mapcar 'car attr
) '("bar" "boz"))))
924 (ignore-errors (delete-directory tmp-name
'recursive
))))))
926 (ert-deftest tramp-test20-file-modes
()
928 This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
929 (skip-unless (tramp--test-enabled))
933 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
934 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
935 (tramp-cleanup-connection
936 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
939 (let ((tmp-name (tramp--test-make-temp-name)))
942 (write-region "foo" nil tmp-name
)
943 (should (file-exists-p tmp-name
))
944 (set-file-modes tmp-name
#o777
)
945 (should (= (file-modes tmp-name
) #o777
))
946 (should (file-executable-p tmp-name
))
947 (should (file-writable-p tmp-name
))
948 (set-file-modes tmp-name
#o444
)
949 (should (= (file-modes tmp-name
) #o444
))
950 (should-not (file-executable-p tmp-name
))
951 ;; A file is always writable for user "root".
952 (when (and (stringp (file-remote-p tmp-name
'user
))
953 (not (string-equal (file-remote-p tmp-name
'user
) "root")))
954 (should-not (file-writable-p tmp-name
))))
955 (ignore-errors (delete-file tmp-name
)))))
957 (ert-deftest tramp-test21-file-links
()
958 "Check `file-symlink-p'.
959 This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
960 (skip-unless (tramp--test-enabled))
961 (tramp-cleanup-connection
962 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
965 (let ((tmp-name1 (tramp--test-make-temp-name))
966 (tmp-name2 (tramp--test-make-temp-name))
967 (tmp-name3 (make-temp-name "tramp-")))
970 (write-region "foo" nil tmp-name1
)
971 (should (file-exists-p tmp-name1
))
972 ;; Method "smb" supports `make-symbolic-link' only if the
973 ;; remote host has CIFS capabilities. tramp-adb.el and
974 ;; tramp-gvfs.el do not support symbolic links at all.
976 (make-symbolic-link tmp-name1 tmp-name2
)
979 (not (string-equal (error-message-string err
)
980 "make-symbolic-link not supported")))))
981 (should (file-symlink-p tmp-name2
))
982 (should-error (make-symbolic-link tmp-name1 tmp-name2
))
983 (make-symbolic-link tmp-name1 tmp-name2
'ok-if-already-exists
)
984 (should (file-symlink-p tmp-name2
))
985 ;; `tmp-name3' is a local file name.
986 (should-error (make-symbolic-link tmp-name1 tmp-name3
)))
988 (delete-file tmp-name1
)
989 (delete-file tmp-name2
)))
993 (write-region "foo" nil tmp-name1
)
994 (should (file-exists-p tmp-name1
))
995 (add-name-to-file tmp-name1 tmp-name2
)
996 (should-not (file-symlink-p tmp-name2
))
997 (should-error (add-name-to-file tmp-name1 tmp-name2
))
998 (add-name-to-file tmp-name1 tmp-name2
'ok-if-already-exists
)
999 (should-not (file-symlink-p tmp-name2
))
1000 ;; `tmp-name3' is a local file name.
1001 (should-error (add-name-to-file tmp-name1 tmp-name3
)))
1003 (delete-file tmp-name1
)
1004 (delete-file tmp-name2
)))
1008 (write-region "foo" nil tmp-name1
)
1009 (should (file-exists-p tmp-name1
))
1010 (make-symbolic-link tmp-name1 tmp-name2
)
1011 (should (file-symlink-p tmp-name2
))
1012 (should-not (string-equal tmp-name2
(file-truename tmp-name2
)))
1014 (string-equal (file-truename tmp-name1
) (file-truename tmp-name2
))))
1016 (delete-file tmp-name1
)
1017 (delete-file tmp-name2
)))))
1019 (ert-deftest tramp-test22-file-times
()
1020 "Check `set-file-times' and `file-newer-than-file-p'."
1021 (skip-unless (tramp--test-enabled))
1025 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1026 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
1027 (tramp-cleanup-connection
1028 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1031 (let ((tmp-name1 (tramp--test-make-temp-name))
1032 (tmp-name2 (tramp--test-make-temp-name))
1033 (tmp-name3 (tramp--test-make-temp-name)))
1036 (write-region "foo" nil tmp-name1
)
1037 (should (file-exists-p tmp-name1
))
1038 (should (consp (nth 5 (file-attributes tmp-name1
))))
1039 ;; '(0 0) means don't know, and will be replaced by `current-time'.
1040 (set-file-times tmp-name1
'(0 1))
1041 ;; Dumb busyboxes are not able to return the date correctly.
1042 ;; They say "don't know.
1043 (skip-unless (not (equal (nth 5 (file-attributes tmp-name1
)) '(0 0))))
1044 (should (equal (nth 5 (file-attributes tmp-name1
)) '(0 1)))
1045 (write-region "bla" nil tmp-name2
)
1046 (should (file-exists-p tmp-name2
))
1047 (should (file-newer-than-file-p tmp-name2 tmp-name1
))
1048 ;; `tmp-name3' does not exist.
1049 (should (file-newer-than-file-p tmp-name2 tmp-name3
))
1050 (should-not (file-newer-than-file-p tmp-name3 tmp-name1
)))
1052 (delete-file tmp-name1
)
1053 (delete-file tmp-name2
)))))
1055 (ert-deftest tramp-test23-visited-file-modtime
()
1056 "Check `set-visited-file-modtime' and `verify-visited-file-modtime'."
1057 (skip-unless (tramp--test-enabled))
1058 (tramp-cleanup-connection
1059 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1062 (let ((tmp-name (tramp--test-make-temp-name)))
1065 (write-region "foo" nil tmp-name
)
1066 (should (file-exists-p tmp-name
))
1068 (insert-file-contents tmp-name
)
1069 (should (verify-visited-file-modtime))
1070 (set-visited-file-modtime '(0 1))
1071 (should (verify-visited-file-modtime))
1072 (should (equal (visited-file-modtime) '(0 1 0 0)))))
1073 (ignore-errors (delete-file tmp-name
)))))
1075 (ert-deftest tramp-test24-file-name-completion
()
1076 "Check `file-name-completion' and `file-name-all-completions'."
1077 (skip-unless (tramp--test-enabled))
1078 (tramp-cleanup-connection
1079 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1082 (let ((tmp-name (tramp--test-make-temp-name)))
1085 (make-directory tmp-name
)
1086 (should (file-directory-p tmp-name
))
1087 (write-region "foo" nil
(expand-file-name "foo" tmp-name
))
1088 (write-region "bar" nil
(expand-file-name "bold" tmp-name
))
1089 (make-directory (expand-file-name "boz" tmp-name
))
1090 (should (equal (file-name-completion "fo" tmp-name
) "foo"))
1091 (should (equal (file-name-completion "b" tmp-name
) "bo"))
1093 (equal (file-name-completion "b" tmp-name
'file-directory-p
) "boz/"))
1094 (should (equal (file-name-all-completions "fo" tmp-name
) '("foo")))
1096 (equal (sort (file-name-all-completions "b" tmp-name
) 'string-lessp
)
1098 (ignore-errors (delete-directory tmp-name
'recursive
)))))
1100 (ert-deftest tramp-test25-load
()
1102 (skip-unless (tramp--test-enabled))
1103 (tramp-cleanup-connection
1104 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1107 (let ((tmp-name (tramp--test-make-temp-name)))
1110 (load tmp-name
'noerror
'nomessage
)
1111 (should-not (featurep 'tramp-test-load
))
1112 (write-region "(provide 'tramp-test-load)" nil tmp-name
)
1113 ;; `load' in lread.c does not pass `must-suffix'. Why?
1114 ;(should-error (load tmp-name nil 'nomessage 'nosuffix 'must-suffix))
1115 (load tmp-name nil
'nomessage
'nosuffix
)
1116 (should (featurep 'tramp-test-load
)))
1118 (and (featurep 'tramp-test-load
) (unload-feature 'tramp-test-load
))
1119 (delete-file tmp-name
)))))
1121 (ert-deftest tramp-test26-process-file
()
1122 "Check `process-file'."
1123 (skip-unless (tramp--test-enabled))
1127 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1128 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
1129 (tramp-cleanup-connection
1130 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1133 (let ((tmp-name (tramp--test-make-temp-name))
1134 (default-directory tramp-test-temporary-file-directory
))
1137 ;; We cannot use "/bin/true" and "/bin/false"; those paths
1138 ;; do not exist on hydra.
1139 (should (zerop (process-file "true")))
1140 (should-not (zerop (process-file "false")))
1141 (should-not (zerop (process-file "binary-does-not-exist")))
1143 (write-region "foo" nil tmp-name
)
1144 (should (file-exists-p tmp-name
))
1147 (process-file "ls" nil t nil
(file-name-nondirectory tmp-name
))))
1148 ;; `ls' could produce colorized output.
1149 (goto-char (point-min))
1150 (while (re-search-forward tramp-color-escape-sequence-regexp nil t
)
1151 (replace-match "" nil nil
))
1154 (format "%s\n" (file-name-nondirectory tmp-name
))
1156 (ignore-errors (delete-file tmp-name
)))))
1158 (ert-deftest tramp-test27-start-file-process
()
1159 "Check `start-file-process'."
1160 (skip-unless (tramp--test-enabled))
1164 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1165 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
1166 (tramp-cleanup-connection
1167 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1170 (let ((default-directory tramp-test-temporary-file-directory
)
1171 (tmp-name (tramp--test-make-temp-name))
1172 kill-buffer-query-functions proc
)
1175 (setq proc
(start-file-process "test1" (current-buffer) "cat"))
1176 (should (processp proc
))
1177 (should (equal (process-status proc
) 'run
))
1178 (process-send-string proc
"foo")
1179 (process-send-eof proc
)
1180 (accept-process-output proc
1)
1181 (should (string-equal (buffer-string) "foo")))
1182 (ignore-errors (delete-process proc
)))
1186 (write-region "foo" nil tmp-name
)
1187 (should (file-exists-p tmp-name
))
1190 "test2" (current-buffer)
1191 "cat" (file-name-nondirectory tmp-name
)))
1192 (should (processp proc
))
1193 (accept-process-output proc
1)
1194 (should (string-equal (buffer-string) "foo")))
1196 (delete-process proc
)
1197 (delete-file tmp-name
)))
1201 (setq proc
(start-file-process "test3" nil
"cat"))
1202 (should (processp proc
))
1203 (should (equal (process-status proc
) 'run
))
1205 proc
(lambda (_p s
) (should (string-equal s
"foo"))))
1206 (process-send-string proc
"foo")
1207 (process-send-eof proc
)
1208 (accept-process-output proc
1))
1209 (ignore-errors (delete-process proc
)))))
1211 (ert-deftest tramp-test28-shell-command
()
1212 "Check `shell-command'."
1213 (skip-unless (tramp--test-enabled))
1217 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1218 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
1219 (tramp-cleanup-connection
1220 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1223 (let ((tmp-name (tramp--test-make-temp-name))
1224 (default-directory tramp-test-temporary-file-directory
))
1227 (write-region "foo" nil tmp-name
)
1228 (should (file-exists-p tmp-name
))
1230 (format "ls %s" (file-name-nondirectory tmp-name
)) (current-buffer))
1231 ;; `ls' could produce colorized output.
1232 (goto-char (point-min))
1233 (while (re-search-forward tramp-color-escape-sequence-regexp nil t
)
1234 (replace-match "" nil nil
))
1237 (format "%s\n" (file-name-nondirectory tmp-name
)) (buffer-string))))
1238 (ignore-errors (delete-file tmp-name
)))
1242 (write-region "foo" nil tmp-name
)
1243 (should (file-exists-p tmp-name
))
1244 (async-shell-command
1245 (format "ls %s" (file-name-nondirectory tmp-name
)) (current-buffer))
1246 (accept-process-output (get-buffer-process (current-buffer)) 1)
1247 (while (ignore-errors
1248 (memq (process-status (get-buffer-process (current-buffer)))
1250 (accept-process-output (get-buffer-process (current-buffer)) 1))
1251 ;; `ls' could produce colorized output.
1252 (goto-char (point-min))
1253 (while (re-search-forward tramp-color-escape-sequence-regexp nil t
)
1254 (replace-match "" nil nil
))
1257 (format "%s\n" (file-name-nondirectory tmp-name
)) (buffer-string))))
1258 (ignore-errors (delete-file tmp-name
)))
1262 (write-region "foo" nil tmp-name
)
1263 (should (file-exists-p tmp-name
))
1264 (async-shell-command "read line; ls $line" (current-buffer))
1265 (process-send-string
1266 (get-buffer-process (current-buffer))
1267 (format "%s\n" (file-name-nondirectory tmp-name
)))
1268 (accept-process-output (get-buffer-process (current-buffer)) 1)
1269 (while (ignore-errors
1270 (memq (process-status (get-buffer-process (current-buffer)))
1272 (accept-process-output (get-buffer-process (current-buffer)) 1))
1275 (format "%s\n" (file-name-nondirectory tmp-name
)) (buffer-string))))
1276 (ignore-errors (delete-file tmp-name
)))))
1278 (ert-deftest tramp-test29-vc-registered
()
1279 "Check `vc-registered'."
1280 (skip-unless (tramp--test-enabled))
1283 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1284 'tramp-sh-file-name-handler
))
1285 (tramp-cleanup-connection
1286 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1289 (let* ((default-directory tramp-test-temporary-file-directory
)
1290 (tmp-name1 (tramp--test-make-temp-name))
1291 (tmp-name2 (expand-file-name "foo" tmp-name1
))
1292 (vc-handled-backends
1293 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
1295 ((tramp-find-executable v vc-bzr-program
(tramp-get-remote-path v
))
1297 ((tramp-find-executable v vc-git-program
(tramp-get-remote-path v
))
1299 ((tramp-find-executable v vc-hg-program
(tramp-get-remote-path v
))
1302 (skip-unless vc-handled-backends
)
1303 (message "%s" vc-handled-backends
)
1307 (make-directory tmp-name1
)
1308 (write-region "foo" nil tmp-name2
)
1309 (should (file-directory-p tmp-name1
))
1310 (should (file-exists-p tmp-name2
))
1311 (should-not (vc-registered tmp-name1
))
1312 (should-not (vc-registered tmp-name2
))
1314 (let ((default-directory tmp-name1
))
1315 ;; Create empty repository, and register the file.
1316 (vc-create-repo (car vc-handled-backends
))
1317 ;; The structure of VC-FILESET is not documented. Let's
1318 ;; hope it won't change.
1320 nil
(list (car vc-handled-backends
)
1321 (list (file-name-nondirectory tmp-name2
)))))
1322 (should (vc-registered tmp-name2
)))
1324 (ignore-errors (delete-directory tmp-name1
'recursive
)))))
1326 (ert-deftest tramp-test30-utf8
()
1327 "Check UTF8 encoding in file names and file contents."
1328 (skip-unless (tramp--test-enabled))
1329 (tramp-cleanup-connection
1330 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1333 (let ((tmp-name (tramp--test-make-temp-name))
1334 (coding-system-for-read 'utf-8
)
1335 (coding-system-for-write 'utf-8
)
1336 (arabic "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت")
1337 (chinese "银河系漫游指南系列")
1338 (russian "Автостопом по гала́ктике"))
1341 (make-directory tmp-name
)
1342 (dolist (lang `(,arabic
,chinese
,russian
))
1343 (let ((file (expand-file-name lang tmp-name
)))
1344 (write-region lang nil file
)
1345 (should (file-exists-p file
))
1346 ;; Check file contents.
1348 (insert-file-contents file
)
1349 (should (string-equal (buffer-string) lang
)))))
1350 ;; Check file names.
1351 (should (equal (directory-files
1352 tmp-name nil directory-files-no-dot-files-regexp
)
1353 (sort `(,arabic
,chinese
,russian
) 'string-lessp
))))
1354 (ignore-errors (delete-directory tmp-name
'recursive
)))))
1358 ;; * dired-compress-file
1361 ;; * file-ownership-preserved-p
1362 ;; * file-selinux-context
1363 ;; * find-backup-file-name
1364 ;; * make-auto-save-file-name
1366 ;; * set-file-selinux-context
1368 ;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?).
1369 ;; * Fix `tramp-test28-shell-command' on MS Windows (`process-send-eof'?).
1370 ;; * Fix `tramp-test30-utf8' on MS Windows. Seems to be in `directory-files'.
1372 (defun tramp-test-all (&optional interactive
)
1373 "Run all tests for \\[tramp]."
1376 (if interactive
'ert-run-tests-interactively
'ert-run-tests-batch
) "^tramp"))
1378 (provide 'tramp-tests
)
1379 ;;; tramp-tests.el ends here