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 (let ((tmp-name (tramp--test-make-temp-name))
900 (make-directory tmp-name
)
901 (should (file-directory-p tmp-name
))
902 (write-region "foo" nil
(expand-file-name "foo" tmp-name
))
903 (write-region "bar" nil
(expand-file-name "bar" tmp-name
))
904 (write-region "boz" nil
(expand-file-name "boz" tmp-name
))
905 (setq attr
(directory-files-and-attributes tmp-name
))
906 (should (consp attr
))
908 (tramp--instrument-test-case 10
910 (equal (file-attributes (expand-file-name (car elt
) tmp-name
))
912 (setq attr
(directory-files-and-attributes tmp-name
'full
))
914 (tramp--instrument-test-case 10
916 (equal (file-attributes (car elt
)) (cdr elt
)))))
917 (setq attr
(directory-files-and-attributes tmp-name nil
"^b"))
918 (should (equal (mapcar 'car attr
) '("bar" "boz"))))
919 (ignore-errors (delete-directory tmp-name
'recursive
)))))
921 (ert-deftest tramp-test20-file-modes
()
923 This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
924 (skip-unless (tramp--test-enabled))
928 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
929 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
930 (tramp-cleanup-connection
931 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
934 (let ((tmp-name (tramp--test-make-temp-name)))
937 (write-region "foo" nil tmp-name
)
938 (should (file-exists-p tmp-name
))
939 (set-file-modes tmp-name
#o777
)
940 (should (= (file-modes tmp-name
) #o777
))
941 (should (file-executable-p tmp-name
))
942 (should (file-writable-p tmp-name
))
943 (set-file-modes tmp-name
#o444
)
944 (should (= (file-modes tmp-name
) #o444
))
945 (should-not (file-executable-p tmp-name
))
946 ;; A file is always writable for user "root".
947 (when (and (stringp (file-remote-p tmp-name
'user
))
948 (not (string-equal (file-remote-p tmp-name
'user
) "root")))
949 (should-not (file-writable-p tmp-name
))))
950 (ignore-errors (delete-file tmp-name
)))))
952 (ert-deftest tramp-test21-file-links
()
953 "Check `file-symlink-p'.
954 This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
955 (skip-unless (tramp--test-enabled))
956 (tramp-cleanup-connection
957 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
960 (let ((tmp-name1 (tramp--test-make-temp-name))
961 (tmp-name2 (tramp--test-make-temp-name))
962 (tmp-name3 (make-temp-name "tramp-")))
965 (write-region "foo" nil tmp-name1
)
966 (should (file-exists-p tmp-name1
))
967 ;; Method "smb" supports `make-symbolic-link' only if the
968 ;; remote host has CIFS capabilities. tramp-adb.el and
969 ;; tramp-gvfs.el do not support symbolic links at all.
971 (make-symbolic-link tmp-name1 tmp-name2
)
974 (not (string-equal (error-message-string err
)
975 "make-symbolic-link not supported")))))
976 (should (file-symlink-p tmp-name2
))
977 (should-error (make-symbolic-link tmp-name1 tmp-name2
))
978 (make-symbolic-link tmp-name1 tmp-name2
'ok-if-already-exists
)
979 (should (file-symlink-p tmp-name2
))
980 ;; `tmp-name3' is a local file name.
981 (should-error (make-symbolic-link tmp-name1 tmp-name3
)))
983 (delete-file tmp-name1
)
984 (delete-file tmp-name2
)))
988 (write-region "foo" nil tmp-name1
)
989 (should (file-exists-p tmp-name1
))
990 (add-name-to-file tmp-name1 tmp-name2
)
991 (should-not (file-symlink-p tmp-name2
))
992 (should-error (add-name-to-file tmp-name1 tmp-name2
))
993 (add-name-to-file tmp-name1 tmp-name2
'ok-if-already-exists
)
994 (should-not (file-symlink-p tmp-name2
))
995 ;; `tmp-name3' is a local file name.
996 (should-error (add-name-to-file tmp-name1 tmp-name3
)))
998 (delete-file tmp-name1
)
999 (delete-file tmp-name2
)))
1003 (write-region "foo" nil tmp-name1
)
1004 (should (file-exists-p tmp-name1
))
1005 (make-symbolic-link tmp-name1 tmp-name2
)
1006 (should (file-symlink-p tmp-name2
))
1007 (should-not (string-equal tmp-name2
(file-truename tmp-name2
)))
1009 (string-equal (file-truename tmp-name1
) (file-truename tmp-name2
))))
1011 (delete-file tmp-name1
)
1012 (delete-file tmp-name2
)))))
1014 (ert-deftest tramp-test22-file-times
()
1015 "Check `set-file-times' and `file-newer-than-file-p'."
1016 (skip-unless (tramp--test-enabled))
1020 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1021 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
1022 (tramp-cleanup-connection
1023 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1026 (let ((tmp-name1 (tramp--test-make-temp-name))
1027 (tmp-name2 (tramp--test-make-temp-name))
1028 (tmp-name3 (tramp--test-make-temp-name)))
1031 (write-region "foo" nil tmp-name1
)
1032 (should (file-exists-p tmp-name1
))
1033 (should (consp (nth 5 (file-attributes tmp-name1
))))
1034 ;; '(0 0) means don't know, and will be replaced by `current-time'.
1035 (set-file-times tmp-name1
'(0 1))
1036 ;; Dumb busyboxes are not able to return the date correctly.
1037 ;; They say "don't know.
1038 (skip-unless (not (equal (nth 5 (file-attributes tmp-name1
)) '(0 0))))
1039 (should (equal (nth 5 (file-attributes tmp-name1
)) '(0 1)))
1040 (write-region "bla" nil tmp-name2
)
1041 (should (file-exists-p tmp-name2
))
1042 (should (file-newer-than-file-p tmp-name2 tmp-name1
))
1043 ;; `tmp-name3' does not exist.
1044 (should (file-newer-than-file-p tmp-name2 tmp-name3
))
1045 (should-not (file-newer-than-file-p tmp-name3 tmp-name1
)))
1047 (delete-file tmp-name1
)
1048 (delete-file tmp-name2
)))))
1050 (ert-deftest tramp-test23-visited-file-modtime
()
1051 "Check `set-visited-file-modtime' and `verify-visited-file-modtime'."
1052 (skip-unless (tramp--test-enabled))
1053 (tramp-cleanup-connection
1054 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1057 (let ((tmp-name (tramp--test-make-temp-name)))
1060 (write-region "foo" nil tmp-name
)
1061 (should (file-exists-p tmp-name
))
1063 (insert-file-contents tmp-name
)
1064 (should (verify-visited-file-modtime))
1065 (set-visited-file-modtime '(0 1))
1066 (should (verify-visited-file-modtime))
1067 (should (equal (visited-file-modtime) '(0 1 0 0)))))
1068 (ignore-errors (delete-file tmp-name
)))))
1070 (ert-deftest tramp-test24-file-name-completion
()
1071 "Check `file-name-completion' and `file-name-all-completions'."
1072 (skip-unless (tramp--test-enabled))
1073 (tramp-cleanup-connection
1074 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1077 (let ((tmp-name (tramp--test-make-temp-name)))
1080 (make-directory tmp-name
)
1081 (should (file-directory-p tmp-name
))
1082 (write-region "foo" nil
(expand-file-name "foo" tmp-name
))
1083 (write-region "bar" nil
(expand-file-name "bold" tmp-name
))
1084 (make-directory (expand-file-name "boz" tmp-name
))
1085 (should (equal (file-name-completion "fo" tmp-name
) "foo"))
1086 (should (equal (file-name-completion "b" tmp-name
) "bo"))
1088 (equal (file-name-completion "b" tmp-name
'file-directory-p
) "boz/"))
1089 (should (equal (file-name-all-completions "fo" tmp-name
) '("foo")))
1091 (equal (sort (file-name-all-completions "b" tmp-name
) 'string-lessp
)
1093 (ignore-errors (delete-directory tmp-name
'recursive
)))))
1095 (ert-deftest tramp-test25-load
()
1097 (skip-unless (tramp--test-enabled))
1098 (tramp-cleanup-connection
1099 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1102 (let ((tmp-name (tramp--test-make-temp-name)))
1105 (load tmp-name
'noerror
'nomessage
)
1106 (should-not (featurep 'tramp-test-load
))
1107 (write-region "(provide 'tramp-test-load)" nil tmp-name
)
1108 ;; `load' in lread.c does not pass `must-suffix'. Why?
1109 ;(should-error (load tmp-name nil 'nomessage 'nosuffix 'must-suffix))
1110 (load tmp-name nil
'nomessage
'nosuffix
)
1111 (should (featurep 'tramp-test-load
)))
1113 (and (featurep 'tramp-test-load
) (unload-feature 'tramp-test-load
))
1114 (delete-file tmp-name
)))))
1116 (ert-deftest tramp-test26-process-file
()
1117 "Check `process-file'."
1118 (skip-unless (tramp--test-enabled))
1122 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1123 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
1124 (tramp-cleanup-connection
1125 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1128 (let ((tmp-name (tramp--test-make-temp-name))
1129 (default-directory tramp-test-temporary-file-directory
))
1132 ;; We cannot use "/bin/true" and "/bin/false"; those paths
1133 ;; do not exist on hydra.
1134 (should (zerop (process-file "true")))
1135 (should-not (zerop (process-file "false")))
1136 (should-not (zerop (process-file "binary-does-not-exist")))
1138 (write-region "foo" nil tmp-name
)
1139 (should (file-exists-p tmp-name
))
1142 (process-file "ls" nil t nil
(file-name-nondirectory tmp-name
))))
1143 ;; `ls' could produce colorized output.
1144 (goto-char (point-min))
1145 (while (re-search-forward tramp-color-escape-sequence-regexp nil t
)
1146 (replace-match "" nil nil
))
1149 (format "%s\n" (file-name-nondirectory tmp-name
))
1151 (ignore-errors (delete-file tmp-name
)))))
1153 (ert-deftest tramp-test27-start-file-process
()
1154 "Check `start-file-process'."
1155 (skip-unless (tramp--test-enabled))
1159 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1160 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
1161 (tramp-cleanup-connection
1162 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1165 (let ((default-directory tramp-test-temporary-file-directory
)
1166 (tmp-name (tramp--test-make-temp-name))
1167 kill-buffer-query-functions proc
)
1170 (setq proc
(start-file-process "test1" (current-buffer) "cat"))
1171 (should (processp proc
))
1172 (should (equal (process-status proc
) 'run
))
1173 (process-send-string proc
"foo")
1174 (process-send-eof proc
)
1175 (accept-process-output proc
1)
1176 (should (string-equal (buffer-string) "foo")))
1177 (ignore-errors (delete-process proc
)))
1181 (write-region "foo" nil tmp-name
)
1182 (should (file-exists-p tmp-name
))
1185 "test2" (current-buffer)
1186 "cat" (file-name-nondirectory tmp-name
)))
1187 (should (processp proc
))
1188 (accept-process-output proc
1)
1189 (should (string-equal (buffer-string) "foo")))
1191 (delete-process proc
)
1192 (delete-file tmp-name
)))
1196 (setq proc
(start-file-process "test3" nil
"cat"))
1197 (should (processp proc
))
1198 (should (equal (process-status proc
) 'run
))
1200 proc
(lambda (_p s
) (should (string-equal s
"foo"))))
1201 (process-send-string proc
"foo")
1202 (process-send-eof proc
)
1203 (accept-process-output proc
1))
1204 (ignore-errors (delete-process proc
)))))
1206 (ert-deftest tramp-test28-shell-command
()
1207 "Check `shell-command'."
1208 (skip-unless (tramp--test-enabled))
1212 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1213 '(tramp-gvfs-file-name-handler tramp-smb-file-name-handler
))))
1214 (tramp-cleanup-connection
1215 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1218 (let ((tmp-name (tramp--test-make-temp-name))
1219 (default-directory tramp-test-temporary-file-directory
))
1222 (write-region "foo" nil tmp-name
)
1223 (should (file-exists-p tmp-name
))
1225 (format "ls %s" (file-name-nondirectory tmp-name
)) (current-buffer))
1226 ;; `ls' could produce colorized output.
1227 (goto-char (point-min))
1228 (while (re-search-forward tramp-color-escape-sequence-regexp nil t
)
1229 (replace-match "" nil nil
))
1232 (format "%s\n" (file-name-nondirectory tmp-name
)) (buffer-string))))
1233 (ignore-errors (delete-file tmp-name
)))
1237 (write-region "foo" nil tmp-name
)
1238 (should (file-exists-p tmp-name
))
1239 (async-shell-command
1240 (format "ls %s" (file-name-nondirectory tmp-name
)) (current-buffer))
1241 (accept-process-output (get-buffer-process (current-buffer)) 1)
1242 (while (ignore-errors
1243 (memq (process-status (get-buffer-process (current-buffer)))
1245 (accept-process-output (get-buffer-process (current-buffer)) 1))
1246 ;; `ls' could produce colorized output.
1247 (goto-char (point-min))
1248 (while (re-search-forward tramp-color-escape-sequence-regexp nil t
)
1249 (replace-match "" nil nil
))
1252 (format "%s\n" (file-name-nondirectory tmp-name
)) (buffer-string))))
1253 (ignore-errors (delete-file tmp-name
)))
1257 (write-region "foo" nil tmp-name
)
1258 (should (file-exists-p tmp-name
))
1259 (async-shell-command "read line; ls $line" (current-buffer))
1260 (process-send-string
1261 (get-buffer-process (current-buffer))
1262 (format "%s\n" (file-name-nondirectory tmp-name
)))
1263 (accept-process-output (get-buffer-process (current-buffer)) 1)
1264 (while (ignore-errors
1265 (memq (process-status (get-buffer-process (current-buffer)))
1267 (accept-process-output (get-buffer-process (current-buffer)) 1))
1270 (format "%s\n" (file-name-nondirectory tmp-name
)) (buffer-string))))
1271 (ignore-errors (delete-file tmp-name
)))))
1273 (ert-deftest tramp-test29-vc-registered
()
1274 "Check `vc-registered'."
1275 (skip-unless (tramp--test-enabled))
1278 (tramp-find-foreign-file-name-handler tramp-test-temporary-file-directory
)
1279 'tramp-sh-file-name-handler
))
1280 (tramp-cleanup-connection
1281 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1284 (let* ((default-directory tramp-test-temporary-file-directory
)
1285 (tmp-name1 (tramp--test-make-temp-name))
1286 (tmp-name2 (expand-file-name "foo" tmp-name1
))
1287 (vc-handled-backends
1288 (with-parsed-tramp-file-name tramp-test-temporary-file-directory nil
1290 ((tramp-find-executable v vc-bzr-program
(tramp-get-remote-path v
))
1292 ((tramp-find-executable v vc-git-program
(tramp-get-remote-path v
))
1294 ((tramp-find-executable v vc-hg-program
(tramp-get-remote-path v
))
1297 (skip-unless vc-handled-backends
)
1298 (message "%s" vc-handled-backends
)
1302 (make-directory tmp-name1
)
1303 (write-region "foo" nil tmp-name2
)
1304 (should (file-directory-p tmp-name1
))
1305 (should (file-exists-p tmp-name2
))
1306 (should-not (vc-registered tmp-name1
))
1307 (should-not (vc-registered tmp-name2
))
1309 (let ((default-directory tmp-name1
))
1310 ;; Create empty repository, and register the file.
1311 (vc-create-repo (car vc-handled-backends
))
1312 ;; The structure of VC-FILESET is not documented. Let's
1313 ;; hope it won't change.
1315 nil
(list (car vc-handled-backends
)
1316 (list (file-name-nondirectory tmp-name2
)))))
1317 (should (vc-registered tmp-name2
)))
1319 (ignore-errors (delete-directory tmp-name1
'recursive
)))))
1321 (ert-deftest tramp-test30-utf8
()
1322 "Check UTF8 encoding in file names and file contents."
1323 (skip-unless (tramp--test-enabled))
1324 (tramp-cleanup-connection
1325 (tramp-dissect-file-name tramp-test-temporary-file-directory
)
1328 (let ((tmp-name (tramp--test-make-temp-name))
1329 (coding-system-for-read 'utf-8
)
1330 (coding-system-for-write 'utf-8
)
1331 (arabic "أصبح بوسعك الآن تنزيل نسخة كاملة من موسوعة ويكيبيديا العربية لتصفحها بلا اتصال بالإنترنت")
1332 (chinese "银河系漫游指南系列")
1333 (russian "Автостопом по гала́ктике"))
1336 (make-directory tmp-name
)
1337 (dolist (lang `(,arabic
,chinese
,russian
))
1338 (let ((file (expand-file-name lang tmp-name
)))
1339 (write-region lang nil file
)
1340 (should (file-exists-p file
))
1341 ;; Check file contents.
1343 (insert-file-contents file
)
1344 (should (string-equal (buffer-string) lang
)))))
1345 ;; Check file names.
1346 (should (equal (directory-files
1347 tmp-name nil directory-files-no-dot-files-regexp
)
1348 (sort `(,arabic
,chinese
,russian
) 'string-lessp
))))
1349 (ignore-errors (delete-directory tmp-name
'recursive
)))))
1353 ;; * dired-compress-file
1356 ;; * file-ownership-preserved-p
1357 ;; * file-selinux-context
1358 ;; * find-backup-file-name
1359 ;; * make-auto-save-file-name
1361 ;; * set-file-selinux-context
1363 ;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?).
1364 ;; * Fix `tramp-test28-shell-command' on MS Windows (`process-send-eof'?).
1365 ;; * Fix `tramp-test30-utf8' on MS Windows. Seems to be in `directory-files'.
1367 (defun tramp-test-all (&optional interactive
)
1368 "Run all tests for \\[tramp]."
1371 (if interactive
'ert-run-tests-interactively
'ert-run-tests-batch
) "^tramp"))
1373 (provide 'tramp-tests
)
1374 ;;; tramp-tests.el ends here