commit 04073c80f3c82fa488edcd0cffa4961ff40cf885
parent 7970efb1dbd1f4e71064e981a42c6bf7503a167e
Author: Wilfred Hughes <me@wilfred.me.uk>
Date: Sun, 7 Jan 2018 15:28:21 +0000
Allow running ERT tests found in property lists
Diffstat:
2 files changed, 34 insertions(+), 11 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -25,6 +25,9 @@ Smarter handling of keybindings:
When `helpful-max-buffers` is set, we now kill buffers in the order of
least recently accessed. Previously, we killed in creation order.
+If a function also has a unit test of the same name, allow it to be
+run directly from the property list.
+
# v0.5
Allow function tracing to be enabled/disabled from Helpful buffers.
diff --git a/helpful.el b/helpful.el
@@ -232,15 +232,17 @@ Return SYM otherwise."
(propertize (symbol-name sym)
'face 'font-lock-constant-face)
(helpful--indent-rigidly pretty-val 2)
- ;; Also offer to disassemble byte-code
- ;; properties.
- (if (byte-code-function-p val)
- (format "\n %s"
- (helpful--button
- "Disassemble"
- 'helpful-disassemble-button
- 'object val))
- "")))
+ (cond
+ ;; Also offer to disassemble byte-code
+ ;; properties.
+ ((byte-code-function-p val)
+ (format "\n %s"
+ (helpful--make-disassemble-button val)))
+ ((eq sym 'ert--test)
+ (format "\n %s"
+ (helpful--make-run-test-button symbol)))
+ (t
+ ""))))
syms-and-vals)))
(when lines
(s-join "\n" lines))))
@@ -293,6 +295,16 @@ source code to primitives."
;; byte-code objects.
(disassemble (button-get button 'object)))
+(define-button-type 'helpful-run-test-button
+ 'action #'helpful--run-test
+ 'follow-link t
+ 'symbol nil
+ 'help-echo "Run ERT test")
+
+(defun helpful--run-test (button)
+ "Disassemble the current symbol."
+ (ert (button-get button 'symbol)))
+
(define-button-type 'helpful-edebug-button
'action #'helpful--edebug
'follow-link t
@@ -1062,11 +1074,19 @@ POSITION-HEADS takes the form ((123 (defun foo)) (456 (defun bar)))."
'helpful-trace-button
'symbol sym))
-(defun helpful--make-disassemble-button (sym)
- "Make disassemble button for SYM."
+(defun helpful--make-disassemble-button (obj)
+ "Make disassemble button for OBJ.
+OBJ may be a symbol or a compiled function object."
(helpful--button
"Disassemble"
'helpful-disassemble-button
+ 'object obj))
+
+(defun helpful--make-run-test-button (sym)
+ "Make an ERT test button for SYM."
+ (helpful--button
+ "Run test"
+ 'helpful-run-test-button
'symbol sym))
(defun helpful--make-forget-button (sym callable-p)