aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2018-01-07 15:28:21 +0000
committerWilfred Hughes <me@wilfred.me.uk>2018-01-07 15:28:21 +0000
commit04073c80f3c82fa488edcd0cffa4961ff40cf885 (patch)
treec1b84a938a77b0c82e01195500e54e44c653489f
parent7970efb1dbd1f4e71064e981a42c6bf7503a167e (diff)
Allow running ERT tests found in property lists
-rw-r--r--CHANGELOG.md3
-rw-r--r--helpful.el42
2 files changed, 34 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6c4d1b0..72fbcd6 100644
--- 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
index 0dc2b09..9471eb0 100644
--- 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)