emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 321bba0: Terminate `comint-password-function' tests


From: Lars Ingebrigtsen
Subject: master 321bba0: Terminate `comint-password-function' tests
Date: Sun, 20 Sep 2020 06:43:47 -0400 (EDT)

branch: master
commit 321bba0c99c6712921830d0dcf7e681e804c7cd1
Author: dickmao <dick.r.chiang@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Terminate `comint-password-function' tests
    
    * test/lisp/comint-tests.el (comint-test-no-password-function)
    (comint-test-password-function-with-value)
    (comint-test-password-function-with-nil): refactor
    (comint-tests/test-password-function): actually test
    `comint-send-invisible' and inhibit inadvertent interactive query
    (bug#38825).
---
 src/lread.c               |  1 +
 test/lisp/comint-tests.el | 78 ++++++++++++++---------------------------------
 2 files changed, 24 insertions(+), 55 deletions(-)

diff --git a/src/lread.c b/src/lread.c
index 8064bf4..f465b45 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -4104,6 +4104,7 @@ intern_sym (Lisp_Object sym, Lisp_Object obarray, 
Lisp_Object index)
     {
       make_symbol_constant (sym);
       XSYMBOL (sym)->u.s.redirect = SYMBOL_PLAINVAL;
+      XSYMBOL (sym)->u.s.declared_special = true;
       SET_SYMBOL_VAL (XSYMBOL (sym), sym);
     }
 
diff --git a/test/lisp/comint-tests.el b/test/lisp/comint-tests.el
index 132fe87..5b59340 100644
--- a/test/lisp/comint-tests.el
+++ b/test/lisp/comint-tests.el
@@ -52,73 +52,41 @@
   (dolist (str comint-testsuite-password-strings)
     (should (string-match comint-password-prompt-regexp str))))
 
-(ert-deftest comint-test-no-password-function ()
-  "Test that `comint-password-function' not being set does not
-alter normal password flow."
-  (cl-letf
-      (((symbol-function 'read-passwd)
-        (lambda (_prompt &optional _confirm _default)
-          "PaSsWoRd123")))
-    (let ((cat (executable-find "cat")))
-      (when cat
+(defun comint-tests/test-password-function (password-function)
+  "PASSWORD-FUNCTION can return nil or a string."
+  (when-let ((cat (executable-find "cat")))
+    (let ((comint-password-function password-function))
+      (cl-letf (((symbol-function 'read-passwd)
+                 (lambda (&rest _args) "non-nil")))
         (with-temp-buffer
           (make-comint-in-buffer "test-comint-password" (current-buffer) cat)
           (let ((proc (get-buffer-process (current-buffer))))
             (set-process-query-on-exit-flag proc nil)
-            (comint-send-string proc "Password: ")
-            (comint-send-eof)
-            (while (accept-process-output proc 0.1 nil t))
-            (should (string-equal (buffer-substring-no-properties (point-min) 
(point-max))
-                                  "Password: PaSsWoRd123\n"))
-            (when (process-live-p proc)
-              (kill-process proc))
-            (accept-process-output proc 0 1 t)))))))
+            (set-process-query-on-exit-flag proc nil)
+            (comint-send-invisible "Password: ")
+            (accept-process-output proc 0.1)
+            (should (string-equal
+                     (buffer-substring-no-properties (point-min) (point-max))
+                     (concat (or (and password-function
+                                      (funcall password-function))
+                                 "non-nil")
+                             "\n")))))))))
+
+(ert-deftest comint-test-no-password-function ()
+  "Test that `comint-password-function' not being set does not
+alter normal password flow."
+  (comint-tests/test-password-function nil))
 
 (ert-deftest comint-test-password-function-with-value ()
   "Test that `comint-password-function' alters normal password
 flow.  Hook function returns alternative password."
-  (cl-letf
-      (((symbol-function 'read-passwd)
-        (lambda (_prompt &optional _confirm _default)
-          "PaSsWoRd123")))
-    (let ((cat (executable-find "cat"))
-          (comint-password-function (lambda (_prompt) "MaGiC-PaSsWoRd789")))
-      (when cat
-        (with-temp-buffer
-          (make-comint-in-buffer "test-comint-password" (current-buffer) cat)
-          (let ((proc (get-buffer-process (current-buffer))))
-            (set-process-query-on-exit-flag proc nil)
-            (comint-send-string proc "Password: ")
-            (comint-send-eof)
-            (while (accept-process-output proc 0.1 nil t))
-            (should (string-equal (buffer-substring-no-properties (point-min) 
(point-max))
-                                  "Password: MaGiC-PaSsWoRd789\n"))
-            (when (process-live-p proc)
-              (kill-process proc))
-            (accept-process-output proc 0 1 t)))))))
+  (comint-tests/test-password-function
+   (lambda (&rest _args) "MaGiC-PaSsWoRd789")))
 
 (ert-deftest comint-test-password-function-with-nil ()
   "Test that `comint-password-function' does not alter the normal
 password flow if it returns a nil value."
-  (cl-letf
-      (((symbol-function 'read-passwd)
-        (lambda (_prompt &optional _confirm _default)
-          "PaSsWoRd456")))
-    (let ((cat (executable-find "cat"))
-          (comint-password-function (lambda (_prompt) nil)))
-      (when cat
-        (with-temp-buffer
-          (make-comint-in-buffer "test-comint-password" (current-buffer) cat)
-          (let ((proc (get-buffer-process (current-buffer))))
-            (set-process-query-on-exit-flag proc nil)
-            (comint-send-string proc "Password: ")
-            (comint-send-eof)
-            (while (accept-process-output proc 0.1 nil t))
-            (should (string-equal (buffer-substring-no-properties (point-min) 
(point-max))
-                                  "Password: PaSsWoRd456\n"))
-            (when (process-live-p proc)
-              (kill-process proc))
-            (accept-process-output proc 0 1 t)))))))
+  (comint-tests/test-password-function #'ignore))
 
 ;; Local Variables:
 ;; no-byte-compile: t



reply via email to

[Prev in Thread] Current Thread [Next in Thread]