diff options
Diffstat (limited to 'test/lisp')
-rw-r--r-- | test/lisp/loadhist-resources/loadhist--bar.el | 27 | ||||
-rw-r--r-- | test/lisp/loadhist-resources/loadhist--foo.el | 29 | ||||
-rw-r--r-- | test/lisp/loadhist-tests.el | 47 |
3 files changed, 103 insertions, 0 deletions
diff --git a/test/lisp/loadhist-resources/loadhist--bar.el b/test/lisp/loadhist-resources/loadhist--bar.el new file mode 100644 index 00000000000..5c8914ed573 --- /dev/null +++ b/test/lisp/loadhist-resources/loadhist--bar.el @@ -0,0 +1,27 @@ +;;; loadhist--bar.el --- Dummy package for loadhist-tests -*- lexical-binding: t; -*- + +;; Copyright (C) 2022 Free Software Foundation, Inc. + +;; Author: Stefan Monnier <monnier@iro.umontreal.ca> + +;; This program 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. + +;; This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Code: + +(autoload 'loadhist--foo-inc "loadhist--foo") + +(defun loadhist--bar-dec (x) (1- x)) + +(provide 'loadhist--bar) +;;; loadhist--bar.el ends here diff --git a/test/lisp/loadhist-resources/loadhist--foo.el b/test/lisp/loadhist-resources/loadhist--foo.el new file mode 100644 index 00000000000..3574c220135 --- /dev/null +++ b/test/lisp/loadhist-resources/loadhist--foo.el @@ -0,0 +1,29 @@ +;;; loadhist--foo.el --- Dummy package for loadhist-tests -*- lexical-binding: t; -*- + +;; Copyright (C) 2022 Free Software Foundation, Inc. + +;; Author: Stefan Monnier <monnier@iro.umontreal.ca> + +;; This program 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. + +;; This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;;; Code: + +(autoload 'loadhist--bar-dec "loadhist--bar") + +(defun loadhist--foo-inc (x) (1+ x)) + +(provide 'loadhist--foo) +;;; loadhist--foo.el ends here diff --git a/test/lisp/loadhist-tests.el b/test/lisp/loadhist-tests.el index a941ac06320..ef5fc164d34 100644 --- a/test/lisp/loadhist-tests.el +++ b/test/lisp/loadhist-tests.el @@ -54,4 +54,51 @@ (should-error (unload-feature 'dired)) (unload-feature 'dired-x)) +(defvar loadhist--tests-dir (file-name-directory (macroexp-file-name))) + +(ert-deftest loadhist-tests-unload-feature-nested () + (add-to-list 'load-path (expand-file-name + "loadhist-resources/" + loadhist--tests-dir)) + (declare-function loadhist--foo-inc "loadhist--foo") + (declare-function loadhist--bar-dec "loadhist--dec") + (load "loadhist--foo" nil t) + (should (and (functionp 'loadhist--bar-dec) (functionp 'loadhist--foo-inc))) + (should (autoloadp (symbol-function 'loadhist--bar-dec))) + (load "loadhist--bar" nil t) + (should (and (functionp 'loadhist--bar-dec) (functionp 'loadhist--foo-inc))) + (should (not (autoloadp (symbol-function 'loadhist--bar-dec)))) + (should (not (autoloadp (symbol-function 'loadhist--foo-inc)))) + (should (equal (list 40 42) + (list (loadhist--bar-dec 41) (loadhist--foo-inc 41)))) + (unload-feature 'loadhist--bar) + (should (and (functionp 'loadhist--bar-dec) (functionp 'loadhist--foo-inc))) + (should (autoloadp (symbol-function 'loadhist--bar-dec))) + (should (not (autoloadp (symbol-function 'loadhist--foo-inc)))) + (unload-feature 'loadhist--foo) + (should (null (symbol-function 'loadhist--bar-dec))) + (should (null (symbol-function 'loadhist--foo-inc))) + (should (null (get 'loadhist--bar-dec 'function-history))) + (should (null (get 'loadhist--foo-inc 'function-history)))) + +(ert-deftest loadhist-tests-unload-feature-notnested () + (add-to-list 'load-path (expand-file-name + "loadhist-resources/" + loadhist--tests-dir)) + (load "loadhist--foo" nil t) + (load "loadhist--bar" nil t) + (should (equal (list 40 42) + (list (loadhist--bar-dec 41) (loadhist--foo-inc 41)))) + (unload-feature 'loadhist--foo) + (should (functionp 'loadhist--bar-dec)) + (should (not (autoloadp (symbol-function 'loadhist--bar-dec)))) + (should (let ((f (symbol-function 'loadhist--foo-inc))) + ;; Both choices seem acceptable. + (or (null f) (autoloadp f)))) + (unload-feature 'loadhist--bar) + (should (null (symbol-function 'loadhist--bar-dec))) + (should (null (symbol-function 'loadhist--foo-inc))) + (should (null (get 'loadhist--bar-dec 'function-history))) + (should (null (get 'loadhist--foo-inc 'function-history)))) + ;;; loadhist-tests.el ends here |