summaryrefslogtreecommitdiff
path: root/test/lisp/files-x-tests.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2022-09-25 16:15:16 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2022-09-25 16:15:16 -0400
commit650c20f1ca4e07591a727e1cfcc74b3363d15985 (patch)
tree85d11f6437cde22f410c25e0e5f71a3131ebd07d /test/lisp/files-x-tests.el
parent8869332684c2302b5ba1ead4568bbc7ba1c0183e (diff)
parent4b85ae6a24380fb67a3315eaec9233f17a872473 (diff)
downloademacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.tar.gz
emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.tar.bz2
emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.zip
Merge 'master' into noverlay
Diffstat (limited to 'test/lisp/files-x-tests.el')
-rw-r--r--test/lisp/files-x-tests.el171
1 files changed, 109 insertions, 62 deletions
diff --git a/test/lisp/files-x-tests.el b/test/lisp/files-x-tests.el
index 21cb01c350c..7ee2f0c1a65 100644
--- a/test/lisp/files-x-tests.el
+++ b/test/lisp/files-x-tests.el
@@ -1,6 +1,6 @@
-;;; files-x-tests.el --- tests for files-x.el.
+;;; files-x-tests.el --- tests for files-x.el. -*- lexical-binding: t -*-
-;; Copyright (C) 2016-2017 Free Software Foundation, Inc.
+;; Copyright (C) 2016-2022 Free Software Foundation, Inc.
;; Author: Michael Albinus <michael.albinus@gmx.de>
@@ -35,6 +35,12 @@
'((remote-null-device . "/dev/null")))
(defconst files-x-test--variables4
'((remote-null-device . "null")))
+(defvar remote-null-device)
+(put 'remote-shell-file-name 'safe-local-variable #'identity)
+(put 'remote-shell-command-switch 'safe-local-variable #'identity)
+(put 'remote-shell-interactive-switch 'safe-local-variable #'identity)
+(put 'remote-shell-login-switch 'safe-local-variable #'identity)
+(put 'remote-null-device 'safe-local-variable #'identity)
(defconst files-x-test--application '(:application 'my-application))
(defconst files-x-test--another-application
@@ -101,15 +107,19 @@
(setq files-x-test--criteria
(append files-x-test--application files-x-test--protocol
files-x-test--user files-x-test--machine))
+
;; An empty variable list is accepted (but makes no sense).
(connection-local-set-profiles files-x-test--criteria)
(should-not (connection-local-get-profiles files-x-test--criteria))
+
+ ;; First test, all declared properties.
(connection-local-set-profiles
files-x-test--criteria 'remote-bash 'remote-ksh)
(should
(equal
(connection-local-get-profiles files-x-test--criteria)
'(remote-bash remote-ksh)))
+
;; Changing the order of properties doesn't matter.
(setq files-x-test--criteria
(append files-x-test--protocol files-x-test--application
@@ -118,12 +128,14 @@
(equal
(connection-local-get-profiles files-x-test--criteria)
'(remote-bash remote-ksh)))
- ;; A further call adds profiles.
+
+ ;; A further call adds profiles.
(connection-local-set-profiles files-x-test--criteria 'remote-nullfile)
(should
(equal
(connection-local-get-profiles files-x-test--criteria)
'(remote-bash remote-ksh remote-nullfile)))
+
;; Adding existing profiles doesn't matter.
(connection-local-set-profiles
files-x-test--criteria 'remote-bash 'remote-nullfile)
@@ -132,31 +144,38 @@
(connection-local-get-profiles files-x-test--criteria)
'(remote-bash remote-ksh remote-nullfile)))
- ;; Use a criteria without application.
- (setq files-x-test--criteria
- (append files-x-test--protocol
- files-x-test--user files-x-test--machine))
- (connection-local-set-profiles files-x-test--criteria 'remote-ksh)
- (should
- (equal
- (connection-local-get-profiles files-x-test--criteria)
- '(remote-ksh)))
- ;; An application not used in any registered criteria matches also this.
- (setq files-x-test--criteria
- (append files-x-test--another-application files-x-test--protocol
- files-x-test--user files-x-test--machine))
- (should
- (equal
- (connection-local-get-profiles files-x-test--criteria)
- '(remote-ksh)))
+ ;; Use different properties.
+ (dolist (criteria
+ `(;; All properties.
+ ,(append files-x-test--application files-x-test--protocol
+ files-x-test--user files-x-test--machine)
+ ;; Without :application.
+ ,(append files-x-test--protocol
+ files-x-test--user files-x-test--machine)
+ ;; Without :protocol.
+ ,(append files-x-test--application
+ files-x-test--user files-x-test--machine)
+ ;; Without :user.
+ ,(append files-x-test--application files-x-test--protocol
+ files-x-test--machine)
+ ;; Without :machine.
+ ,(append files-x-test--application files-x-test--protocol
+ files-x-test--user)
+ ;; No property at all.
+ nil))
+ (should
+ (equal
+ (connection-local-get-profiles criteria)
+ '(remote-bash remote-ksh remote-nullfile))))
;; Using a nil criteria also works. Duplicate profiles are trashed.
(connection-local-set-profiles
nil 'remote-bash 'remote-ksh 'remote-ksh 'remote-bash)
+ ;; This matches also the existing profiles from other criteria.
(should
(equal
(connection-local-get-profiles nil)
- '(remote-bash remote-ksh)))
+ '(remote-bash remote-ksh remote-nullfile)))
;; A criteria other than plist is wrong.
(should-error (connection-local-set-profiles 'dummy))))
@@ -235,7 +254,9 @@
;; declare same variables as in `remote-bash'.
(should
(equal connection-local-variables-alist
- (nreverse (copy-tree files-x-test--variables1))))
+ (append
+ (nreverse (copy-tree files-x-test--variables3))
+ (nreverse (copy-tree files-x-test--variables1)))))
;; The variables exist also as local variables.
(should (local-variable-p 'remote-shell-file-name))
;; The proper variable value is set.
@@ -253,7 +274,10 @@
(should-not (local-variable-p 'remote-shell-file-name))
(should-not (boundp 'remote-shell-file-name))))))
-(ert-deftest files-x-test-with-connection-local-profiles ()
+(defvar tramp-connection-local-default-shell-variables)
+(defvar tramp-connection-local-default-system-variables)
+
+(ert-deftest files-x-test-with-connection-local-variables ()
"Test setting connection-local variables."
(let (connection-local-profile-alist connection-local-criteria-alist)
@@ -288,46 +312,69 @@
(string-equal (symbol-value 'remote-null-device) "/dev/null"))
;; A candidate connection-local variable is not bound yet.
- (should-not (local-variable-p 'remote-shell-command-switch))
-
- ;; Use the macro.
- (with-connection-local-profiles '(remote-bash remote-ksh)
- ;; All connection-local variables are set. They apply in
- ;; reverse order in `connection-local-variables-alist'.
- ;; This variable keeps only the variables to be set inside
- ;; the macro.
- (should
- (equal connection-local-variables-alist
- (nreverse (copy-tree files-x-test--variables1))))
- ;; The variables exist also as local variables.
- (should (local-variable-p 'remote-shell-file-name))
- (should (local-variable-p 'remote-shell-command-switch))
- ;; The proper variable values are set. The settings from
- ;; `remote-bash' overwrite the same variables as in
- ;; `remote-ksh'.
- (should
- (string-equal (symbol-value 'remote-shell-file-name) "/bin/bash"))
- (should
- (string-equal (symbol-value 'remote-shell-command-switch) "-c")))
-
- ;; Everything is rewound. The old variable values are reset.
- (should
- (equal connection-local-variables-alist
- (append
- (nreverse (copy-tree files-x-test--variables3))
- (nreverse (copy-tree files-x-test--variables2)))))
- ;; The variables exist also as local variables.
- (should (local-variable-p 'remote-shell-file-name))
- (should (local-variable-p 'remote-null-device))
- ;; The proper variable values are set. The settings from
- ;; `remote-ksh' are back.
- (should
- (string-equal (symbol-value 'remote-shell-file-name) "/bin/ksh"))
- (should
- (string-equal (symbol-value 'remote-null-device) "/dev/null"))
+ (should-not (local-variable-p 'remote-shell-command-switch))))
- ;; The variable set temporarily is not unbound, again.
- (should-not (local-variable-p 'remote-shell-command-switch))))))
+ (with-temp-buffer
+ ;; Use the macro. We need a remote `default-directory'.
+ (let ((enable-connection-local-variables t)
+ (default-directory "/method:host:")
+ (remote-null-device "null"))
+ (should-not connection-local-variables-alist)
+ (should-not (local-variable-p 'remote-shell-file-name))
+ (should-not (local-variable-p 'remote-null-device))
+ (should-not (boundp 'remote-shell-file-name))
+ (should (string-equal (symbol-value 'remote-null-device) "null"))
+
+ (connection-local-set-profiles
+ files-x-test--application 'remote-bash)
+
+ (with-connection-local-variables
+ ;; All connection-local variables are set. They apply in
+ ;; reverse order in `connection-local-variables-alist'.
+ ;; Since we ha a remote default directory, Tramp's settings
+ ;; are appended as well.
+ (should
+ (equal
+ connection-local-variables-alist
+ (append
+ (nreverse (copy-tree files-x-test--variables3))
+ (nreverse (copy-tree files-x-test--variables2))
+ (nreverse
+ (copy-tree tramp-connection-local-default-shell-variables))
+ (nreverse
+ (copy-tree tramp-connection-local-default-system-variables)))))
+ ;; The variables exist also as local variables.
+ (should (local-variable-p 'remote-shell-file-name))
+ (should (local-variable-p 'remote-null-device))
+ ;; The proper variable values are set.
+ (should
+ (string-equal (symbol-value 'remote-shell-file-name) "/bin/ksh"))
+ (should
+ (string-equal (symbol-value 'remote-null-device) "/dev/null"))
+
+ ;; Run another instance of `with-connection-local-variables'
+ ;; with a different application.
+ (let ((connection-local-default-application (cadr files-x-test--application)))
+ (with-connection-local-variables
+ ;; The proper variable values are set.
+ (should
+ (string-equal (symbol-value 'remote-shell-file-name) "/bin/bash"))
+ (should
+ (string-equal (symbol-value 'remote-null-device) "/dev/null"))))
+ ;; The variable values are reset.
+ (should
+ (string-equal (symbol-value 'remote-shell-file-name) "/bin/ksh"))
+ (should
+ (string-equal (symbol-value 'remote-null-device) "/dev/null")))
+
+ ;; Everything is rewound. The old variable values are reset.
+ (should-not connection-local-variables-alist)
+ ;; The variables don't exist as local variables.
+ (should-not (local-variable-p 'remote-shell-file-name))
+ (should-not (local-variable-p 'remote-null-device))
+ ;; The variable values are reset.
+ (should-not (boundp 'remote-shell-file-name))
+ (should (string-equal (symbol-value 'remote-null-device) "null"))))))
(provide 'files-x-tests)
;;; files-x-tests.el ends here