all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#36119: Use lexical-binding in password-cache.el and add tests
@ 2019-06-06 19:41 Stefan Kangas
  2019-06-06 19:51 ` Stefan Kangas
  2019-06-09 17:09 ` bug#36119: [PATCH] " Paul Eggert
  0 siblings, 2 replies; 5+ messages in thread
From: Stefan Kangas @ 2019-06-06 19:41 UTC (permalink / raw)
  To: 36119

[-- Attachment #1: Type: text/plain, Size: 152 bytes --]

I've written unit tests and added the lexical-binding header to
password-cache.el.  Please let me know if you have any comments.

Thanks,
Stefan Kangas

[-- Attachment #2: 0001-Use-lexical-binding-in-password-cache.el-and-add-tes.patch --]
[-- Type: text/x-patch, Size: 4701 bytes --]

From 7176690ed13bce840129e1d79f211a0fd731a610 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Thu, 6 Jun 2019 20:31:09 +0200
Subject: [PATCH] Use lexical-binding in password-cache.el and add tests

* lisp/password-cache.el: Use lexical-binding.
* test/lisp/password-cache-tests.el: New file.
---
 lisp/emacs-lisp/check-declare.el  |  2 +-
 lisp/password-cache.el            |  4 +--
 test/lisp/password-cache-tests.el | 75 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+), 3 deletions(-)
 create mode 100644 test/lisp/password-cache-tests.el

diff --git a/lisp/emacs-lisp/check-declare.el b/lisp/emacs-lisp/check-declare.el
index 8445950311..0cb63bbe98 100644
--- a/lisp/emacs-lisp/check-declare.el
+++ b/lisp/emacs-lisp/check-declare.el
@@ -33,7 +33,7 @@
 ;;; TODO:
 
 ;; 1. Warn about functions marked as obsolete, eg
-;; password-read-and-add in smime.el.
+;; password-read-and-add in password-cache.el.
 ;; 2. defmethod, defclass argument checking.
 ;; 3. defclass also defines -p and -child-p.
 
diff --git a/lisp/password-cache.el b/lisp/password-cache.el
index b868b720f0..5a09ae4859 100644
--- a/lisp/password-cache.el
+++ b/lisp/password-cache.el
@@ -1,10 +1,10 @@
-;;; password-cache.el --- Read passwords, possibly using a password cache.
+;;; password-cache.el --- Read passwords, possibly using a password cache.  -*- lexical-binding: t -*-
 
 ;; Copyright (C) 1999-2000, 2003-2019 Free Software Foundation, Inc.
 
 ;; Author: Simon Josefsson <simon@josefsson.org>
 ;; Created: 2003-12-21
-;; Keywords: password cache passphrase key
+;; Keywords: extensions
 
 ;; This file is part of GNU Emacs.
 
diff --git a/test/lisp/password-cache-tests.el b/test/lisp/password-cache-tests.el
new file mode 100644
index 0000000000..bb8064d4c6
--- /dev/null
+++ b/test/lisp/password-cache-tests.el
@@ -0,0 +1,75 @@
+;;; password-cache-tests.el --- Tests for password-cache.el  -*- lexical-binding: t -*-
+
+;; Copyright (C) 2019 Free Software Foundation, Inc.
+
+;; Author: Stefan Kangas <stefankangas@gmail.com>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'ert)
+(require 'password-cache)
+
+(ert-deftest password-cache-tests-add-and-remove ()
+  (let ((password-data (copy-hash-table password-data)))
+    (password-cache-add "foo" "bar")
+    (should (equal (password-in-cache-p "foo") "bar"))
+    (password-cache-remove "foo")
+    (should (not (password-in-cache-p "foo")))))
+
+(ert-deftest password-cache-tests-read-from-cache ()
+  (let ((password-data (copy-hash-table password-data)))
+    (password-cache-add "foo" "bar")
+    (should (equal (password-read-from-cache "foo") "bar"))
+    (should (not (password-read-from-cache nil)))))
+
+(ert-deftest password-cache-tests-in-cache-p ()
+  (let ((password-data (copy-hash-table password-data)))
+    (password-cache-add "foo" "bar")
+    (should (password-in-cache-p "foo"))
+    (should (not (password-read-from-cache nil)))))
+
+(ert-deftest password-cache-tests-read ()
+  (let ((password-data (copy-hash-table password-data)))
+    (password-cache-add "foo" "bar")
+    (should (equal (password-read nil "foo") "bar"))))
+
+(ert-deftest password-cache-tests-reset ()
+  (let ((password-data (copy-hash-table password-data)))
+    (password-cache-add "foo" "bar")
+    (password-reset)
+    (should (not (password-in-cache-p "foo")))))
+
+(ert-deftest password-cache-tests-add/expires-key ()
+  :tags '(:expensive-test)
+  (let ((password-data (copy-hash-table password-data))
+        (password-cache-expiry 0.01))
+    (password-cache-add "foo" "bar")
+    (sit-for 0.1)
+    (should (not (password-in-cache-p "foo")))))
+
+(ert-deftest password-cache-tests-no-password-cache ()
+  (let ((password-data (copy-hash-table password-data))
+        (password-cache nil))
+    (password-cache-add "foo" "bar")
+    (should (not (password-in-cache-p "foo")))
+    (should (not (password-read-from-cache "foo")))))
+
+(provide 'password-cache-tests)
+;;; password-cache-tests.el ends here
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-06-09 17:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-06 19:41 bug#36119: Use lexical-binding in password-cache.el and add tests Stefan Kangas
2019-06-06 19:51 ` Stefan Kangas
2019-06-07  0:55   ` Noam Postavsky
2019-06-07  1:05     ` Stefan Kangas
2019-06-09 17:09 ` bug#36119: [PATCH] " Paul Eggert

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.