diff options
| author | Stefan Kangas | 2019-06-09 09:18:46 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-06-09 10:08:36 -0700 |
| commit | 1af27a17847fb02f35359e9bc03c77c1058f7a1d (patch) | |
| tree | 8ad0793bdc6d9e8165d1e27abc8aa19d3ad73a73 /test | |
| parent | 179b9c44c5dc6ba0cf8c9235b59c52aebcbaa828 (diff) | |
| download | emacs-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.
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/password-cache-tests.el | 75 |
1 files changed, 75 insertions, 0 deletions
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 | ||