diff options
author | Michael Albinus <michael.albinus@gmx.de> | 2017-02-19 17:14:35 +0100 |
---|---|---|
committer | Michael Albinus <michael.albinus@gmx.de> | 2017-02-19 17:14:35 +0100 |
commit | 143bc75c414434badcb324db056ad37c15893bd9 (patch) | |
tree | edb4c926bd940e39ec9a88ea13324d55f925223c /test | |
parent | b6a1a74522120979fe1a63b2d5517a490ee572b0 (diff) | |
download | emacs-143bc75c414434badcb324db056ad37c15893bd9.tar.gz |
Rework connection local variables
For connection local variables interface, `class' is renamed
to `profile'. All arguments `criteria' are a plist now.
* doc/lispref/variables.texi (Connection Local Variables):
Rewrite.
* lisp/files-x.el (connection-local-profile-alist): Rename
from `connection-local-class-alist'. Adapt docstring.
(connection-local-criteria-alist): Adapt docstring.
(connection-local-normalize-criteria): New defun.
(connection-local-get-profiles): Rename from
`connection-local-get-classes'. Rewrite.
(connection-local-set-profiles): Rename from
`connection-local-set-classes'. Rewrite.
(connection-local-get-profile-variables): Rename from
`connection-local-get-class-variables'. Rewrite.
(connection-local-set-profile-variables): Rename from
`connection-local-set-class-variables'. Rewrite.
(hack-connection-local-variables)
(hack-connection-local-variables-apply)): Rewrite.
(with-connection-local-profiles): Rename from
`ith-connection-local-classes'. Rewrite.
* lisp/net/tramp.el (tramp-set-connection-local-variables):
Compute criteria.
* lisp/net/tramp-cmds.el (tramp-bug):
Use `connection-local-profile-alist'.
* test/lisp/files-x-tests.el (files-x-test--variables1)
(files-x-test--variables2, files-x-test--variables3)
(files-x-test--variables4, files-x-test--criteria1)
(files-x-test--criteria2): Make them a defconst.
(files-x-test--application)
(files-x-test--another-application, files-x-test--protocol)
(files-x-test--user, files-x-test--machine): New defconst.
(files-x-test--criteria): New defvar.
(files-x-test--criteria3): Remove.
(files-x-test-connection-local-set-profile-variables):
Rename from `files-x-test-connection-local-set-class-variables'.
Rewrite.
(files-x-test-connection-local-set-profiles): Rename from
`files-x-test-connection-local-set-classes'. Rewrite.
(files-x-test-hack-connection-local-variables-apply) Rewrite.
(files-x-test-with-connection-local-profiles): Rename from
`files-x-test-with-connection-local-classes'. Rewrite.
Diffstat (limited to 'test')
-rw-r--r-- | test/lisp/files-x-tests.el | 214 |
1 files changed, 125 insertions, 89 deletions
diff --git a/test/lisp/files-x-tests.el b/test/lisp/files-x-tests.el index 88b58fe9576..21d0087ebcf 100644 --- a/test/lisp/files-x-tests.el +++ b/test/lisp/files-x-tests.el @@ -24,130 +24,167 @@ (require 'ert) (require 'files-x) -(defvar files-x-test--criteria1 "my-user@my-remote-host") -(defvar files-x-test--criteria2 - (lambda (identification) - (string-match "another-user@my-remote-host" identification))) -(defvar files-x-test--criteria3 nil) - -(defvar files-x-test--variables1 +(defconst files-x-test--variables1 '((remote-shell-file-name . "/bin/bash") (remote-shell-command-switch . "-c") (remote-shell-interactive-switch . "-i") (remote-shell-login-switch . "-l"))) -(defvar files-x-test--variables2 +(defconst files-x-test--variables2 '((remote-shell-file-name . "/bin/ksh"))) -(defvar files-x-test--variables3 +(defconst files-x-test--variables3 '((remote-null-device . "/dev/null"))) -(defvar files-x-test--variables4 +(defconst files-x-test--variables4 '((remote-null-device . "null"))) -(ert-deftest files-x-test-connection-local-set-class-variables () - "Test setting connection-local class variables." - - ;; Declare (CLASS VARIABLES) objects. - (let (connection-local-class-alist connection-local-criteria-alist) - (connection-local-set-class-variables 'remote-bash files-x-test--variables1) +(defconst files-x-test--application '(:application 'my-application)) +(defconst files-x-test--another-application + '(:application 'another-application)) +(defconst files-x-test--protocol '(:protocol "my-protocol")) +(defconst files-x-test--user '(:user "my-user")) +(defconst files-x-test--machine '(:machine "my-machine")) + +(defvar files-x-test--criteria nil) +(defconst files-x-test--criteria1 + (append files-x-test--application files-x-test--protocol + files-x-test--user files-x-test--machine)) +(defconst files-x-test--criteria2 + (append files-x-test--another-application files-x-test--protocol + files-x-test--user files-x-test--machine)) + +(ert-deftest files-x-test-connection-local-set-profile-variables () + "Test setting connection-local profile variables." + + ;; Declare (PROFILE VARIABLES) objects. + (let (connection-local-profile-alist connection-local-criteria-alist) + (connection-local-set-profile-variables + 'remote-bash files-x-test--variables1) (should (equal - (connection-local-get-class-variables 'remote-bash) + (connection-local-get-profile-variables 'remote-bash) files-x-test--variables1)) - (connection-local-set-class-variables 'remote-ksh files-x-test--variables2) + (connection-local-set-profile-variables + 'remote-ksh files-x-test--variables2) (should (equal - (connection-local-get-class-variables 'remote-ksh) + (connection-local-get-profile-variables 'remote-ksh) files-x-test--variables2)) - (connection-local-set-class-variables + (connection-local-set-profile-variables 'remote-nullfile files-x-test--variables3) (should (equal - (connection-local-get-class-variables 'remote-nullfile) + (connection-local-get-profile-variables 'remote-nullfile) files-x-test--variables3)) ;; A redefinition overwrites existing values. - (connection-local-set-class-variables + (connection-local-set-profile-variables 'remote-nullfile files-x-test--variables4) (should (equal - (connection-local-get-class-variables 'remote-nullfile) + (connection-local-get-profile-variables 'remote-nullfile) files-x-test--variables4)))) -(ert-deftest files-x-test-connection-local-set-classes () - "Test setting connection-local classes." +(ert-deftest files-x-test-connection-local-set-profiles () + "Test setting connection-local profiles." - ;; Declare (CRITERIA CLASSES) objects. - (let (connection-local-class-alist connection-local-criteria-alist) - (connection-local-set-class-variables 'remote-bash files-x-test--variables1) - (connection-local-set-class-variables 'remote-ksh files-x-test--variables2) - (connection-local-set-class-variables + ;; Declare (CRITERIA PROFILES) objects. + (let (connection-local-profile-alist connection-local-criteria-alist) + (connection-local-set-profile-variables + 'remote-bash files-x-test--variables1) + (connection-local-set-profile-variables + 'remote-ksh files-x-test--variables2) + (connection-local-set-profile-variables 'remote-nullfile files-x-test--variables3) - (connection-local-set-classes - files-x-test--criteria1 'remote-bash 'remote-ksh) + ;; Use a criteria with all properties. + (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)) + (connection-local-set-profiles + files-x-test--criteria 'remote-bash 'remote-ksh) (should (equal - (connection-local-get-classes files-x-test--criteria1) + (connection-local-get-profiles files-x-test--criteria) '(remote-bash remote-ksh))) - - (connection-local-set-classes files-x-test--criteria2 'remote-ksh) + ;; Changing the order of properties doesn't matter. + (setq files-x-test--criteria + (append files-x-test--protocol files-x-test--application + files-x-test--machine files-x-test--user)) (should (equal - (connection-local-get-classes files-x-test--criteria2) - '(remote-ksh))) - ;; A further call adds classes. - (connection-local-set-classes files-x-test--criteria2 'remote-nullfile) + (connection-local-get-profiles files-x-test--criteria) + '(remote-bash remote-ksh))) + ;; A further call adds profiles. + (connection-local-set-profiles files-x-test--criteria 'remote-nullfile) (should (equal - (connection-local-get-classes files-x-test--criteria2) - '(remote-ksh remote-nullfile))) - ;; Adding existing classes doesn't matter. - (connection-local-set-classes - files-x-test--criteria2 'remote-bash 'remote-nullfile) + (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) (should (equal - (connection-local-get-classes files-x-test--criteria2) - '(remote-ksh remote-nullfile remote-bash))) - - ;; An empty variable list is accepted (but makes no sense). - (connection-local-set-classes files-x-test--criteria3) - (should-not (connection-local-get-classes files-x-test--criteria3)) + (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))) - ;; Using a nil criteria also works. Duplicate classes are trashed. - (connection-local-set-classes - files-x-test--criteria3 'remote-bash 'remote-ksh 'remote-ksh 'remote-bash) + ;; Using a nil criteria also works. Duplicate profiles are trashed. + (connection-local-set-profiles + nil 'remote-bash 'remote-ksh 'remote-ksh 'remote-bash) (should (equal - (connection-local-get-classes files-x-test--criteria3) + (connection-local-get-profiles nil) '(remote-bash remote-ksh))) - ;; A criteria other than nil, regexp or lambda function is wrong. - (should-error (connection-local-set-classes 'dummy)))) + ;; A criteria other than plist is wrong. + (should-error (connection-local-set-profiles 'dummy)))) (ert-deftest files-x-test-hack-connection-local-variables-apply () "Test setting connection-local variables." - (let (connection-local-class-alist connection-local-criteria-alist) + (let (connection-local-profile-alist connection-local-criteria-alist) - (connection-local-set-class-variables 'remote-bash files-x-test--variables1) - (connection-local-set-class-variables 'remote-ksh files-x-test--variables2) - (connection-local-set-class-variables + (connection-local-set-profile-variables + 'remote-bash files-x-test--variables1) + (connection-local-set-profile-variables + 'remote-ksh files-x-test--variables2) + (connection-local-set-profile-variables 'remote-nullfile files-x-test--variables3) - (connection-local-set-classes + (connection-local-set-profiles files-x-test--criteria1 'remote-bash 'remote-ksh) - (connection-local-set-classes + (connection-local-set-profiles files-x-test--criteria2 'remote-ksh 'remote-nullfile) ;; Apply the variables. (with-temp-buffer - (let ((enable-connection-local-variables t) - (default-directory "/sudo:my-user@my-remote-host:")) + (let ((enable-connection-local-variables t)) (should-not connection-local-variables-alist) (should-not (local-variable-p 'remote-shell-file-name)) (should-not (boundp 'remote-shell-file-name)) - (hack-connection-local-variables-apply) + (hack-connection-local-variables-apply files-x-test--criteria1) ;; All connection-local variables are set. They apply in ;; reverse order in `connection-local-variables-alist'. The ;; settings from `remote-ksh' are not contained, because they @@ -163,12 +200,11 @@ ;; The second test case. (with-temp-buffer - (let ((enable-connection-local-variables t) - (default-directory "/ssh:another-user@my-remote-host:")) + (let ((enable-connection-local-variables t)) (should-not connection-local-variables-alist) (should-not (local-variable-p 'remote-shell-file-name)) (should-not (boundp 'remote-shell-file-name)) - (hack-connection-local-variables-apply) + (hack-connection-local-variables-apply files-x-test--criteria2) ;; All connection-local variables are set. They apply in ;; reverse order in `connection-local-variables-alist'. (should @@ -182,18 +218,17 @@ (should (string-equal (symbol-value 'remote-shell-file-name) "/bin/ksh")))) - ;; The third test case. Both `files-x-test--criteria1' and - ;; `files-x-test--criteria3' apply, but there are no double + ;; The third test case. Both criteria `files-x-test--criteria1' + ;; and `files-x-test--criteria2' apply, but there are no double ;; entries. - (connection-local-set-classes - files-x-test--criteria3 'remote-bash 'remote-ksh) + (connection-local-set-profiles + nil 'remote-bash 'remote-ksh) (with-temp-buffer - (let ((enable-connection-local-variables t) - (default-directory "/sudo:my-user@my-remote-host:")) + (let ((enable-connection-local-variables t)) (should-not connection-local-variables-alist) (should-not (local-variable-p 'remote-shell-file-name)) (should-not (boundp 'remote-shell-file-name)) - (hack-connection-local-variables-apply) + (hack-connection-local-variables-apply nil) ;; All connection-local variables are set. They apply in ;; reverse order in `connection-local-variables-alist'. The ;; settings from `remote-ksh' are not contained, because they @@ -209,31 +244,32 @@ ;; When `enable-connection-local-variables' is nil, nothing happens. (with-temp-buffer - (let ((enable-connection-local-variables nil) - (default-directory "/ssh:another-user@my-remote-host:")) + (let ((enable-connection-local-variables nil)) (should-not connection-local-variables-alist) (should-not (local-variable-p 'remote-shell-file-name)) (should-not (boundp 'remote-shell-file-name)) - (hack-connection-local-variables-apply) + (hack-connection-local-variables-apply nil) (should-not connection-local-variables-alist) (should-not (local-variable-p 'remote-shell-file-name)) (should-not (boundp 'remote-shell-file-name)))))) -(ert-deftest files-x-test-with-connection-local-classes () +(ert-deftest files-x-test-with-connection-local-profiles () "Test setting connection-local variables." - (let (connection-local-class-alist connection-local-criteria-alist) - (connection-local-set-class-variables 'remote-bash files-x-test--variables1) - (connection-local-set-class-variables 'remote-ksh files-x-test--variables2) - (connection-local-set-class-variables + (let (connection-local-profile-alist connection-local-criteria-alist) + (connection-local-set-profile-variables + 'remote-bash files-x-test--variables1) + (connection-local-set-profile-variables + 'remote-ksh files-x-test--variables2) + (connection-local-set-profile-variables 'remote-nullfile files-x-test--variables3) - (connection-local-set-classes - files-x-test--criteria3 'remote-ksh 'remote-nullfile) + + (connection-local-set-profiles + nil 'remote-ksh 'remote-nullfile) (with-temp-buffer - (let ((enable-connection-local-variables t) - (default-directory "/sudo:my-user@my-remote-host:")) - (hack-connection-local-variables-apply) + (let ((enable-connection-local-variables t)) + (hack-connection-local-variables-apply nil) ;; All connection-local variables are set. They apply in ;; reverse order in `connection-local-variables-alist'. @@ -255,7 +291,7 @@ (should-not (local-variable-p 'remote-shell-command-switch)) ;; Use the macro. - (with-connection-local-classes '(remote-bash remote-ksh) + (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 |