aboutsummaryrefslogtreecommitdiff
path: root/test/helpful-unit-test.el
diff options
context:
space:
mode:
authorDario Gjorgjevski <dario.gjorgjevski+git@gmail.com>2021-02-02 17:54:44 +0100
committerWilfred Hughes <me@wilfred.me.uk>2021-03-19 01:02:58 -0700
commit7e4b1f0d5572a4e2b8ee7a9b084ef863d0315a73 (patch)
tree68bdf56b7f046197fbc3b0f9b52bac14d58ecf56 /test/helpful-unit-test.el
parent716c116d6a9fafb16a5b1e6be5dbd8e82f357c7e (diff)
Prevent error in helpful-variable if sexp at point can't be read
How to reproduce from emacs -Q in the *scratch* buffer: 0. If needed, do `(package-initialize)` and `(require 'helpful)`. 1. Type `(something some-undefined-variable|` where | represents point. (Note that there is no closing parenthesis!) 2. Call helpful-variable. This will give you an `End of file during parsing` from `helpful--variable-defined-at-point` because the sexp at point can't be read due to the missing parenthesis. This commit suppresses the error Fix #251 Close #254
Diffstat (limited to 'test/helpful-unit-test.el')
-rw-r--r--test/helpful-unit-test.el12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/helpful-unit-test.el b/test/helpful-unit-test.el
index 2ce5011..1fbf87c 100644
--- a/test/helpful-unit-test.el
+++ b/test/helpful-unit-test.el
@@ -133,6 +133,18 @@ bar")))
(helpful-function #'test-foo-defined-interactively)
(should (equal (buffer-name) "*helpful function: test-foo-defined-interactively*"))))
+(ert-deftest helpful--variable-defined-at-point ()
+ ;; The happy case with valid code.
+ (with-temp-buffer
+ (insert "(defvar foo nil)")
+ (goto-char (1+ (point-min)))
+ (should (eq (helpful--variable-defined-at-point) 'foo)))
+ ;; Ensure we don't crash if the source code isn't valid.
+ (with-temp-buffer
+ (insert "(defvar foo nil")
+ (goto-char (1+ (point-min)))
+ (helpful--variable-defined-at-point)))
+
(ert-deftest helpful--edebug-fn ()
"We should not crash on a function with edebug enabled."
(let ((edebug-all-forms t)