branch: externals/compat commit d81a132d2fd0f5fec08486ed5222b8e1d0402560 Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
Add test for package-get-version --- compat-27.el | 9 +++------ compat-tests.el | 5 +++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/compat-27.el b/compat-27.el index 9a74a4d5b8..26e557d270 100644 --- a/compat-27.el +++ b/compat-27.el @@ -494,20 +494,17 @@ Optional arg PARENTS, if non-nil then creates parent dirs as needed." (declare-function lm-header "lisp-mnt") -(compat-defun package-get-version () ;; <UNTESTED> +(compat-defun package-get-version () ;; <compat-tests:package-get-version> "Return the version number of the package in which this is used. Assumes it is used from an Elisp file placed inside the top-level directory of an installed ELPA package. The return value is a string (or nil in case we can’t find it)." - :feature package + ;; No :feature since the function is autoloaded. ;; In a sense, this is a lie, but it does just what we want: precompute ;; the version at compile time and hardcodes it into the .elc file! (declare (pure t)) ;; Hack alert! - (let ((file - (or (and (boundp 'byte-compile-current-file) byte-compile-current-file) - load-file-name - buffer-file-name))) + (let ((file (or (macroexp-file-name) buffer-file-name))) (cond ((null file) nil) ;; Packages are normally installed into directories named "<pkg>-<vers>", diff --git a/compat-tests.el b/compat-tests.el index 61b2e8fc54..0f520c8ee1 100644 --- a/compat-tests.el +++ b/compat-tests.el @@ -80,6 +80,11 @@ (setq list (funcall sym list "first" 1 #'string=)) (should (eq (compat-call plist-get list "first" #'string=) 1)))) +(defconst compat-tests--version (package-get-version)) +(ert-deftest package-get-version () + (should (stringp compat-tests--version)) + (should-equal 29 (car (version-to-list compat-tests--version)))) + (ert-deftest buffer-match-p () (let ((b "*compat-test-buffer*") (child-mode (make-symbol "child"))