aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael Albinus2019-03-09 16:44:24 +0100
committerMichael Albinus2019-03-09 16:44:24 +0100
commit21f54feee8c83e2c5fd8eeb6741cbd479a7b19eb (patch)
tree3edf223c49dfedf09ec93804856954a9554a93cd /test
parentc37bdd00c7dcabaa3ca8405d9dc5122ed36f27e0 (diff)
downloademacs-21f54feee8c83e2c5fd8eeb6741cbd479a7b19eb.tar.gz
emacs-21f54feee8c83e2c5fd8eeb6741cbd479a7b19eb.zip
Do not hardcode "/bin/sh" in compile. Bug#24338, Bug#29723
* doc/emacs/custom.texi (Connection Variables): New node. * doc/emacs/emacs.texi (Top): Add entry for Connection Variables. * doc/emacs/misc.texi (Single Shell): Mention default value for remote buffers. * doc/lispref/variables.texi (Connection Local Variables): Describe `with-connection-local-variables' instead of `with-connection-local-profiles'. * doc/misc/tramp.texi (Remote processes): Refer to Emacs manual. Mention default connection-local settings for `shell-file-name' and `shell-command-switch'. * etc/NEWS: Mention connection-local variables changes. * lisp/files-x.el (hack-connection-local-variables): Push connection-local variables to `file-local-variables-alist'. (connection-local-criteria-for-default-directory): New defsubst. (with-connection-local-variables): Rename from `with-connection-local-profiles'. Adapt implementation. * lisp/files.el (hack-local-variables): Call `hack-connection-local-variables'. * lisp/shell.el (shell): Use `with-connection-local-variables'. * lisp/subr.el (start-file-process-shell-command): * lisp/progmodes/compile.el (compilation-start): Use `with-connection-local-variables'. Do not set "/bin/sh" for remote buffers, trust settings of `shell-file-name'. (Bug#24338), (Bug#29723) * lisp/net/ange-ftp.el (ange-ftp-compress, ange-ftp-uncompress): Use `shell-command-switch'. * lisp/net/tramp-adb.el (tramp-adb-connection-local-default-profile): New defvar. Add it to connection-local profiles after loading "shell". * lisp/net/tramp-integration.el (tramp-compat): Require tramp-compat. (tramp-compat-exec-path): Do not declare anymore. (tramp-connection-local-safe-shell-file-names): New defvar. (tramp-connection-local-default-profile): New defconst. Activate it after loading "shell". (shell-file-name, shell-command-switch): Add safe-local-variable property. * lisp/net/tramp-sh.el (tramp-display-escape-sequence-regexp): Add tramp-autoload cookie. * test/lisp/files-x-tests.el (remote-shell-file-name): Add safe-local-variable property to remote-* variables. (tramp-connection-local-default-profile): Declare. (files-x-test-with-connection-local-variables): Rename from `files-x-test-with-connection-local-profiles'. Adapt implementation. * test/lisp/net/tramp-tests.el (tramp-test34-connection-local-variables): New test. (tramp-test34-explicit-shell-file-name): Run it also for tramp-adb. Bind connection-local-{profile,criteria}-alist. Use tramp-adb specific `shell-file-name'. Add safe-local-variable property to `explicit-shell-file-name' and `explicit-sh-args'.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/files-x-tests.el89
-rw-r--r--test/lisp/net/tramp-tests.el77
2 files changed, 123 insertions, 43 deletions
diff --git a/test/lisp/files-x-tests.el b/test/lisp/files-x-tests.el
index d678be409d1..568a8984479 100644
--- a/test/lisp/files-x-tests.el
+++ b/test/lisp/files-x-tests.el
@@ -35,6 +35,11 @@
35 '((remote-null-device . "/dev/null"))) 35 '((remote-null-device . "/dev/null")))
36(defconst files-x-test--variables4 36(defconst files-x-test--variables4
37 '((remote-null-device . "null"))) 37 '((remote-null-device . "null")))
38(put 'remote-shell-file-name 'safe-local-variable #'identity)
39(put 'remote-shell-command-switch 'safe-local-variable #'identity)
40(put 'remote-shell-interactive-switch 'safe-local-variable #'identity)
41(put 'remote-shell-login-switch 'safe-local-variable #'identity)
42(put 'remote-null-device 'safe-local-variable #'identity)
38 43
39(defconst files-x-test--application '(:application 'my-application)) 44(defconst files-x-test--application '(:application 'my-application))
40(defconst files-x-test--another-application 45(defconst files-x-test--another-application
@@ -268,7 +273,9 @@
268 (should-not (local-variable-p 'remote-shell-file-name)) 273 (should-not (local-variable-p 'remote-shell-file-name))
269 (should-not (boundp 'remote-shell-file-name)))))) 274 (should-not (boundp 'remote-shell-file-name))))))
270 275
271(ert-deftest files-x-test-with-connection-local-profiles () 276(defvar tramp-connection-local-default-profile)
277
278(ert-deftest files-x-test-with-connection-local-variables ()
272 "Test setting connection-local variables." 279 "Test setting connection-local variables."
273 280
274 (let (connection-local-profile-alist connection-local-criteria-alist) 281 (let (connection-local-profile-alist connection-local-criteria-alist)
@@ -303,46 +310,48 @@
303 (string-equal (symbol-value 'remote-null-device) "/dev/null")) 310 (string-equal (symbol-value 'remote-null-device) "/dev/null"))
304 311
305 ;; A candidate connection-local variable is not bound yet. 312 ;; A candidate connection-local variable is not bound yet.
306 (should-not (local-variable-p 'remote-shell-command-switch)) 313 (should-not (local-variable-p 'remote-shell-command-switch))))
307
308 ;; Use the macro.
309 (with-connection-local-profiles '(remote-bash remote-ksh)
310 ;; All connection-local variables are set. They apply in
311 ;; reverse order in `connection-local-variables-alist'.
312 ;; This variable keeps only the variables to be set inside
313 ;; the macro.
314 (should
315 (equal connection-local-variables-alist
316 (nreverse (copy-tree files-x-test--variables1))))
317 ;; The variables exist also as local variables.
318 (should (local-variable-p 'remote-shell-file-name))
319 (should (local-variable-p 'remote-shell-command-switch))
320 ;; The proper variable values are set. The settings from
321 ;; `remote-bash' overwrite the same variables as in
322 ;; `remote-ksh'.
323 (should
324 (string-equal (symbol-value 'remote-shell-file-name) "/bin/bash"))
325 (should
326 (string-equal (symbol-value 'remote-shell-command-switch) "-c")))
327
328 ;; Everything is rewound. The old variable values are reset.
329 (should
330 (equal connection-local-variables-alist
331 (append
332 (nreverse (copy-tree files-x-test--variables3))
333 (nreverse (copy-tree files-x-test--variables2)))))
334 ;; The variables exist also as local variables.
335 (should (local-variable-p 'remote-shell-file-name))
336 (should (local-variable-p 'remote-null-device))
337 ;; The proper variable values are set. The settings from
338 ;; `remote-ksh' are back.
339 (should
340 (string-equal (symbol-value 'remote-shell-file-name) "/bin/ksh"))
341 (should
342 (string-equal (symbol-value 'remote-null-device) "/dev/null"))
343 314
344 ;; The variable set temporarily is not unbound, again. 315 (with-temp-buffer
345 (should-not (local-variable-p 'remote-shell-command-switch)))))) 316 ;; Use the macro. We need a remote `default-directory'.
317 (let ((enable-connection-local-variables t)
318 (default-directory "/method:host:")
319 (remote-null-device "null"))
320 (should-not connection-local-variables-alist)
321 (should-not (local-variable-p 'remote-shell-file-name))
322 (should-not (local-variable-p 'remote-null-device))
323 (should-not (boundp 'remote-shell-file-name))
324 (should (string-equal (symbol-value 'remote-null-device) "null"))
325
326 (with-connection-local-variables
327 ;; All connection-local variables are set. They apply in
328 ;; reverse order in `connection-local-variables-alist'.
329 ;; Since we ha a remote default directory, Tramp's settings
330 ;; are appended as well.
331 (should
332 (equal
333 connection-local-variables-alist
334 (append
335 (nreverse (copy-tree files-x-test--variables3))
336 (nreverse (copy-tree files-x-test--variables2))
337 (nreverse (copy-tree tramp-connection-local-default-profile)))))
338 ;; The variables exist also as local variables.
339 (should (local-variable-p 'remote-shell-file-name))
340 (should (local-variable-p 'remote-null-device))
341 ;; The proper variable values are set.
342 (should
343 (string-equal (symbol-value 'remote-shell-file-name) "/bin/ksh"))
344 (should
345 (string-equal (symbol-value 'remote-null-device) "/dev/null")))
346
347 ;; Everything is rewound. The old variable values are reset.
348 (should-not connection-local-variables-alist)
349 ;; The variables don't exist as local variables.
350 (should-not (local-variable-p 'remote-shell-file-name))
351 (should-not (local-variable-p 'remote-null-device))
352 ;; The variable values are reset.
353 (should-not (boundp 'remote-shell-file-name))
354 (should (string-equal (symbol-value 'remote-null-device) "null"))))))
346 355
347(provide 'files-x-tests) 356(provide 'files-x-tests)
348;;; files-x-tests.el ends here 357;;; files-x-tests.el ends here
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 69d5ba8b7df..bf7cdfafabe 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -4274,12 +4274,78 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4274 (dolist (dir '("/mock:localhost#11111:" "/mock:localhost#22222:")) 4274 (dolist (dir '("/mock:localhost#11111:" "/mock:localhost#22222:"))
4275 (tramp-cleanup-connection (tramp-dissect-file-name dir))))) 4275 (tramp-cleanup-connection (tramp-dissect-file-name dir)))))
4276 4276
4277;; Connection-local variables are enabled per default since Emacs 27.1.
4278(ert-deftest tramp-test34-connection-local-variables ()
4279 "Check that connection-local variables are enabled."
4280 :tags '(:expensive-test)
4281 (skip-unless (tramp--test-enabled))
4282 ;; Since Emacs 27.1.
4283 (skip-unless (fboundp 'with-connection-local-variables))
4284
4285 ;; `connection-local-set-profile-variables' and
4286 ;; `connection-local-set-profiles' exist since Emacs 26.1. We don't
4287 ;; want to see compiler warnings for older Emacsen.
4288 (let* ((default-directory tramp-test-temporary-file-directory)
4289 (tmp-name1 (tramp--test-make-temp-name))
4290 (tmp-name2 (expand-file-name "foo" tmp-name1))
4291 (enable-local-variables :all)
4292 (enable-remote-dir-locals t)
4293 kill-buffer-query-functions
4294 connection-local-profile-alist connection-local-criteria-alist)
4295 (unwind-protect
4296 (progn
4297 (make-directory tmp-name1)
4298 (should (file-directory-p tmp-name1))
4299
4300 ;; `local-variable' is buffer-local due to explicit setting.
4301 (with-no-warnings
4302 (defvar-local local-variable 'buffer))
4303 (with-temp-buffer
4304 (should (eq local-variable 'buffer)))
4305
4306 ;; `local-variable' is connection-local due to Tramp.
4307 (write-region "foo" nil tmp-name2)
4308 (should (file-exists-p tmp-name2))
4309 (with-no-warnings
4310 (connection-local-set-profile-variables
4311 'local-variable-profile
4312 '((local-variable . connect)))
4313 (connection-local-set-profiles
4314 `(:application tramp
4315 :protocol ,(file-remote-p default-directory 'method)
4316 :user ,(file-remote-p default-directory 'user)
4317 :machine ,(file-remote-p default-directory 'host))
4318 'local-variable-profile))
4319 (with-current-buffer (find-file-noselect tmp-name2)
4320 (should (eq local-variable 'connect))
4321 (kill-buffer (current-buffer)))
4322
4323 ;; `local-variable' is dir-local due to existence of .dir-locals.el.
4324 (write-region
4325 "((nil . ((local-variable . dir))))" nil
4326 (expand-file-name ".dir-locals.el" tmp-name1))
4327 (should (file-exists-p (expand-file-name ".dir-locals.el" tmp-name1)))
4328 (with-current-buffer (find-file-noselect tmp-name2)
4329 (should (eq local-variable 'dir))
4330 (kill-buffer (current-buffer)))
4331
4332 ;; `local-variable' is file-local due to specifying as file variable.
4333 (write-region
4334 "-*- mode: comint; local-variable: file; -*-" nil tmp-name2)
4335 (should (file-exists-p tmp-name2))
4336 (with-current-buffer (find-file-noselect tmp-name2)
4337 (should (eq local-variable 'file))
4338 (kill-buffer (current-buffer))))
4339
4340 ;; Cleanup.
4341 (ignore-errors (delete-directory tmp-name1 'recursive)))))
4342
4277;; The functions were introduced in Emacs 26.1. 4343;; The functions were introduced in Emacs 26.1.
4278(ert-deftest tramp-test34-explicit-shell-file-name () 4344(ert-deftest tramp-test34-explicit-shell-file-name ()
4279 "Check that connection-local `explicit-shell-file-name' is set." 4345 "Check that connection-local `explicit-shell-file-name' is set."
4280 :tags '(:expensive-test) 4346 :tags '(:expensive-test)
4281 (skip-unless (tramp--test-enabled)) 4347 (skip-unless (tramp--test-enabled))
4282 (skip-unless (tramp--test-sh-p)) 4348 (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p)))
4283 ;; Since Emacs 26.1. 4349 ;; Since Emacs 26.1.
4284 (skip-unless (and (fboundp 'connection-local-set-profile-variables) 4350 (skip-unless (and (fboundp 'connection-local-set-profile-variables)
4285 (fboundp 'connection-local-set-profiles))) 4351 (fboundp 'connection-local-set-profiles)))
@@ -4288,7 +4354,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4288 ;; `connection-local-set-profiles' exist since Emacs 26.1. We don't 4354 ;; `connection-local-set-profiles' exist since Emacs 26.1. We don't
4289 ;; want to see compiler warnings for older Emacsen. 4355 ;; want to see compiler warnings for older Emacsen.
4290 (let ((default-directory tramp-test-temporary-file-directory) 4356 (let ((default-directory tramp-test-temporary-file-directory)
4291 explicit-shell-file-name kill-buffer-query-functions) 4357 explicit-shell-file-name kill-buffer-query-functions
4358 connection-local-profile-alist connection-local-criteria-alist)
4292 (unwind-protect 4359 (unwind-protect
4293 (progn 4360 (progn
4294 ;; `shell-mode' would ruin our test, because it deletes all 4361 ;; `shell-mode' would ruin our test, because it deletes all
@@ -4298,7 +4365,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4298 (with-no-warnings 4365 (with-no-warnings
4299 (connection-local-set-profile-variables 4366 (connection-local-set-profile-variables
4300 'remote-sh 4367 'remote-sh
4301 '((explicit-shell-file-name . "/bin/sh") 4368 `((explicit-shell-file-name
4369 . ,(if (tramp--test-adb-p) "/system/bin/sh" "/bin/sh"))
4302 (explicit-sh-args . ("-i")))) 4370 (explicit-sh-args . ("-i"))))
4303 (connection-local-set-profiles 4371 (connection-local-set-profiles
4304 `(:application tramp 4372 `(:application tramp
@@ -4306,6 +4374,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4306 :user ,(file-remote-p default-directory 'user) 4374 :user ,(file-remote-p default-directory 'user)
4307 :machine ,(file-remote-p default-directory 'host)) 4375 :machine ,(file-remote-p default-directory 'host))
4308 'remote-sh)) 4376 'remote-sh))
4377 (put 'explicit-shell-file-name 'safe-local-variable #'identity)
4378 (put 'explicit-sh-args 'safe-local-variable #'identity)
4309 4379
4310 ;; Run interactive shell. Since the default directory is 4380 ;; Run interactive shell. Since the default directory is
4311 ;; remote, `explicit-shell-file-name' shall be set in order 4381 ;; remote, `explicit-shell-file-name' shall be set in order
@@ -4316,6 +4386,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4316 (call-interactively #'shell) 4386 (call-interactively #'shell)
4317 (should explicit-shell-file-name))) 4387 (should explicit-shell-file-name)))
4318 4388
4389 ;; Cleanup.
4319 (put 'explicit-shell-file-name 'permanent-local nil) 4390 (put 'explicit-shell-file-name 'permanent-local nil)
4320 (kill-buffer "*shell*")))) 4391 (kill-buffer "*shell*"))))
4321 4392