commit 44e7d2702f55e9a5693aebfeadc6a8c5418b7c41 parent 518d24b76bc6e4d55c8b2c288a33faf67100b101 Author: Wilfred Hughes <me@wilfred.me.uk> Date: Wed, 13 Dec 2017 23:38:15 +0000 Fix crash on definition of primitive variables Diffstat:
| M | helpful.el | | | 2 | +- |
| M | test/unit-test.el | | | 13 | ++++++++++--- |
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/helpful.el b/helpful.el @@ -464,7 +464,7 @@ buffer." ;; `base-sym' is the underlying symbol if `sym' is an alias. (setq sym base-sym) (setq path src-path))) - (when primitive-p + (when (and primitive-p path) ;; Convert "src/foo.c" to "". (setq path (f-expand path (f-parent find-function-C-source-directory)))) diff --git a/test/unit-test.el b/test/unit-test.el @@ -140,9 +140,16 @@ (setq helpful-var-without-defvar 'foo) (ert-deftest helpful--definition () - "Ensure we don't crash on calling `helpful--definition' on -variables defined without `defvar'." - (helpful--definition 'helpful-var-without-defvar nil)) + ;; Ensure we don't crash on calling `helpful--definition' on + ;; variables defined without `defvar'. + (helpful--definition 'helpful-var-without-defvar nil) + ;; Handle definitions of variables in C source code. + (let* ((emacs-src-path (f-join default-directory "emacs-25.3" "src"))) + (if (f-exists-p emacs-src-path) + (let ((find-function-C-source-directory emacs-src-path)) + (helpful--definition 'default-directory nil)) + (message "No Emacs source code found at %S, skipping test." + emacs-src-path)))) (ert-deftest helpful-variable () "Smoke test for `helpful-variable'."