aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas2019-06-09 09:18:46 -0700
committerPaul Eggert2019-06-09 10:08:36 -0700
commit1af27a17847fb02f35359e9bc03c77c1058f7a1d (patch)
tree8ad0793bdc6d9e8165d1e27abc8aa19d3ad73a73
parent179b9c44c5dc6ba0cf8c9235b59c52aebcbaa828 (diff)
downloademacs-1af27a17847fb02f35359e9bc03c77c1058f7a1d.tar.gz
emacs-1af27a17847fb02f35359e9bc03c77c1058f7a1d.zip
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.
-rw-r--r--lisp/emacs-lisp/check-declare.el2
-rw-r--r--lisp/password-cache.el4
-rw-r--r--test/lisp/password-cache-tests.el75
3 files changed, 78 insertions, 3 deletions
diff --git a/lisp/emacs-lisp/check-declare.el b/lisp/emacs-lisp/check-declare.el
index 8445950311b..0cb63bbe987 100644
--- a/lisp/emacs-lisp/check-declare.el
+++ b/lisp/emacs-lisp/check-declare.el
@@ -33,7 +33,7 @@
33;;; TODO: 33;;; TODO:
34 34
35;; 1. Warn about functions marked as obsolete, eg 35;; 1. Warn about functions marked as obsolete, eg
36;; password-read-and-add in smime.el. 36;; password-read-and-add in password-cache.el.
37;; 2. defmethod, defclass argument checking. 37;; 2. defmethod, defclass argument checking.
38;; 3. defclass also defines -p and -child-p. 38;; 3. defclass also defines -p and -child-p.
39 39
diff --git a/lisp/password-cache.el b/lisp/password-cache.el
index b868b720f00..5a09ae4859d 100644
--- a/lisp/password-cache.el
+++ b/lisp/password-cache.el
@@ -1,10 +1,10 @@
1;;; password-cache.el --- Read passwords, possibly using a password cache. 1;;; password-cache.el --- Read passwords, possibly using a password cache. -*- lexical-binding: t -*-
2 2
3;; Copyright (C) 1999-2000, 2003-2019 Free Software Foundation, Inc. 3;; Copyright (C) 1999-2000, 2003-2019 Free Software Foundation, Inc.
4 4
5;; Author: Simon Josefsson <simon@josefsson.org> 5;; Author: Simon Josefsson <simon@josefsson.org>
6;; Created: 2003-12-21 6;; Created: 2003-12-21
7;; Keywords: password cache passphrase key 7;; Keywords: extensions
8 8
9;; This file is part of GNU Emacs. 9;; This file is part of GNU Emacs.
10 10
diff --git a/test/lisp/password-cache-tests.el b/test/lisp/password-cache-tests.el
new file mode 100644
index 00000000000..bb8064d4c69
--- /dev/null
+++ b/test/lisp/password-cache-tests.el
@@ -0,0 +1,75 @@
1;;; password-cache-tests.el --- Tests for password-cache.el -*- lexical-binding: t -*-
2
3;; Copyright (C) 2019 Free Software Foundation, Inc.
4
5;; Author: Stefan Kangas <stefankangas@gmail.com>
6
7;; This file is part of GNU Emacs.
8
9;; GNU Emacs is free software: you can redistribute it and/or modify
10;; it under the terms of the GNU General Public License as published by
11;; the Free Software Foundation, either version 3 of the License, or
12;; (at your option) any later version.
13
14;; GNU Emacs is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details.
18
19;; You should have received a copy of the GNU General Public License
20;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
21
22;;; Commentary:
23
24;;; Code:
25
26(require 'ert)
27(require 'password-cache)
28
29(ert-deftest password-cache-tests-add-and-remove ()
30 (let ((password-data (copy-hash-table password-data)))
31 (password-cache-add "foo" "bar")
32 (should (equal (password-in-cache-p "foo") "bar"))
33 (password-cache-remove "foo")
34 (should (not (password-in-cache-p "foo")))))
35
36(ert-deftest password-cache-tests-read-from-cache ()
37 (let ((password-data (copy-hash-table password-data)))
38 (password-cache-add "foo" "bar")
39 (should (equal (password-read-from-cache "foo") "bar"))
40 (should (not (password-read-from-cache nil)))))
41
42(ert-deftest password-cache-tests-in-cache-p ()
43 (let ((password-data (copy-hash-table password-data)))
44 (password-cache-add "foo" "bar")
45 (should (password-in-cache-p "foo"))
46 (should (not (password-read-from-cache nil)))))
47
48(ert-deftest password-cache-tests-read ()
49 (let ((password-data (copy-hash-table password-data)))
50 (password-cache-add "foo" "bar")
51 (should (equal (password-read nil "foo") "bar"))))
52
53(ert-deftest password-cache-tests-reset ()
54 (let ((password-data (copy-hash-table password-data)))
55 (password-cache-add "foo" "bar")
56 (password-reset)
57 (should (not (password-in-cache-p "foo")))))
58
59(ert-deftest password-cache-tests-add/expires-key ()
60 :tags '(:expensive-test)
61 (let ((password-data (copy-hash-table password-data))
62 (password-cache-expiry 0.01))
63 (password-cache-add "foo" "bar")
64 (sit-for 0.1)
65 (should (not (password-in-cache-p "foo")))))
66
67(ert-deftest password-cache-tests-no-password-cache ()
68 (let ((password-data (copy-hash-table password-data))
69 (password-cache nil))
70 (password-cache-add "foo" "bar")
71 (should (not (password-in-cache-p "foo")))
72 (should (not (password-read-from-cache "foo")))))
73
74(provide 'password-cache-tests)
75;;; password-cache-tests.el ends here