all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: dick.r.chiang@gmail.com
To: 38825@debbugs.gnu.org
Subject: bug#38825: no subject
Date: Mon, 30 Dec 2019 16:58:57 -0500	[thread overview]
Message-ID: <87sgl18ogu.fsf@dick> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: patch --]
[-- Type: text/x-diff, Size: 5207 bytes --]

From 7d9c0dd38e1581070adaa55fc1e6d4d99133c395 Mon Sep 17 00:00:00 2001
From: dickmao <none>
Date: Mon, 30 Dec 2019 16:35:28 -0500
Subject: [PATCH] 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
---
 test/lisp/comint-tests.el | 77 +++++++++++----------------------------
 1 file changed, 21 insertions(+), 56 deletions(-)

diff --git a/test/lisp/comint-tests.el b/test/lisp/comint-tests.el
index c04134599f..29787d980d 100644
--- a/test/lisp/comint-tests.el
+++ b/test/lisp/comint-tests.el
@@ -52,73 +52,38 @@ comint-testsuite-password-strings
   (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))))
-            (comint-send-string proc "Password: ")
-            (accept-process-output proc 0 1 t)
-            (comint-send-eof)
-            (accept-process-output proc 0 1 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))))
-            (comint-send-string proc "Password: ")
-            (accept-process-output proc 0 1 t)
-            (comint-send-eof)
-            (accept-process-output proc 0 1 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))))
-            (comint-send-string proc "Password: ")
-            (accept-process-output proc 0 1 t)
-            (comint-send-eof)
-            (accept-process-output proc 0 1 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
-- 
2.23.0






             reply	other threads:[~2019-12-30 21:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-30 21:58 dick.r.chiang [this message]
2020-09-20 10:43 ` bug#38825: no subject Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sgl18ogu.fsf@dick \
    --to=dick.r.chiang@gmail.com \
    --cc=38825@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.