[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup e8140aa 133/340: Implement configurable stack tr
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup e8140aa 133/340: Implement configurable stack traces |
Date: |
Thu, 16 Dec 2021 14:59:19 -0500 (EST) |
branch: elpa/buttercup
commit e8140aa8f824ae6dadf78c664bf13c28a5e45dbf
Author: Ryan C. Thompson <rct@thompsonclan.org>
Commit: Jorgen Schäfer <Jorgen.Schaefer@gmail.com>
Implement configurable stack traces
Use the "--traceback" command-line option or set the
"buttercup-stack-frame-style" variable to use this. Possible values
are "crop", "full", and "pretty". This option still needs to be added
to the documentation.
---
buttercup.el | 58 ++++++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 48 insertions(+), 10 deletions(-)
diff --git a/buttercup.el b/buttercup.el
index dc7e48f..bf33e83 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -716,6 +716,14 @@ current directory."
(args command-line-args-left))
(while args
(cond
+ ((member (car args) '("--traceback"))
+ (when (not (cdr args))
+ (error "Option requires argument: %s" (car args)))
+ ;; Make sure it's a valid style by trying to format a dummy
+ ;; frame with it
+ (buttercup--format-stack-frame '(t myfun 1 2) (intern (cadr args)))
+ (setq buttercup-stack-frame-style (intern (cadr args)))
+ (setq args (cddr args)))
((member (car args) '("-p" "--pattern"))
(when (not (cdr args))
(error "Option requires argument: %s" (car args)))
@@ -945,11 +953,8 @@ Calls either `buttercup-reporter-batch' or
(when stack
(buttercup--print "\nTraceback (most recent call last):\n")
(dolist (frame stack)
- (let ((line (format " %S" (cdr frame))))
- (when (> (length line) 79)
- (setq line (concat (substring line 0 76)
- "...")))
- (buttercup--print "%s\n" line))))
+ (let ((frame-text (buttercup--format-stack-frame frame)))
+ (buttercup--print "%s\n" frame-text))))
(cond
((stringp description)
(buttercup--print "FAILED: %s\n" description))
@@ -1017,11 +1022,8 @@ Calls either `buttercup-reporter-batch' or
(when stack
(buttercup--print "\nTraceback (most recent call last):\n")
(dolist (frame stack)
- (let ((line (format " %S" (cdr frame))))
- (when (> (length line) 79)
- (setq line (concat (substring line 0 76)
- "...")))
- (buttercup--print "%s\n" line))))
+ (let ((frame-text (buttercup--format-stack-frame frame)))
+ (buttercup--print "%s\n" frame-text))))
(cond
((stringp description)
(buttercup--print (concat (buttercup-colorize "FAILED" 'red ) ":
%s\n")
@@ -1154,6 +1156,42 @@ failed -- The second value is the description of the
expectation
frame (backtrace-frame n)))
frame-list))
+(defvar buttercup-stack-frame-style (car '(crop full pretty))
+ "Style to use when printing stack traces of tests.
+
+`full' is roughly the same style as normal Emacs stack traces:
+print each stack frame in full with no line breaks. `crop' is
+like full, but truncates each line to 80 characters. `pretty'
+uses `pp' to generate a multi-line indented representation of
+each frame, and prefixes each stack frame with lambda or M to
+indicate whether it represents a normal evaluated function call
+or a macro/special form.")
+
+(defun buttercup--format-stack-frame (frame &optional style)
+ (pcase (or style buttercup-stack-frame-style 'crop)
+ (`full (format " %S" (cdr frame)))
+ (`crop
+ (let ((line (buttercup--format-stack-frame frame 'full)))
+ ;; Note: this could be done sith `s-truncate' from the s
+ ;; package
+ (when (> (length line) 79)
+ (setq line (concat (substring line 0 76)
+ "...")))
+ line))
+ (`pretty
+ (thread-last (pp-to-string (cdr frame))
+ ;; Delete empty trailing line
+ (replace-regexp-in-string "\n[[:space:]]*\\'"
+ "")
+ ;; Indent 2 spaces
+ (replace-regexp-in-string "^"
+ " ")
+ ;; Prefix first line with lambda for function call and M for
+ ;; macro/special form
+ (replace-regexp-in-string "\\` "
+ (if (car frame) "λ" "M"))))
+ (_ (error "Unknown stack trace style: %S" style))))
+
(defmacro buttercup-with-converted-ert-signals (&rest body)
"Convert ERT signals to buttercup signals in BODY.
- [nongnu] elpa/buttercup a1c7bff 101/340: Do not ignore errors when after-each succeeds, (continued)
- [nongnu] elpa/buttercup a1c7bff 101/340: Do not ignore errors when after-each succeeds, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b120003 108/340: Merge pull request #60 from howdoicomputer/feature/windows-bin-support, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 06c9699 104/340: Merge pull request #58 from Fuco1/to-equal-as-set, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup a6d9bde 105/340: Support more emacs parameters useful for pre-test initialization, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup abf2abe 109/340: Exclude hidden files and dirs in test root, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f60ed2a 119/340: Bump version: 1.5 → 1.6, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 677d6d3 118/340: Merge pull request #70 from xendk/color-output, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d8dc80d 126/340: Bump version: 1.6 → 1.7, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b6deeff 128/340: Set Emacs 24.3 as minimum and clean outdated code (close #89), ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 39c7d8c 132/340: Allow ERT "should" and similar to work with buttercup, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup e8140aa 133/340: Implement configurable stack traces,
ELPA Syncer <=
- [nongnu] elpa/buttercup e6f97d0 136/340: Release 1.8, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup e26ea54 137/340: Let spy-on :and-return-value work with lists and symbols (close #104), ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup e55e3d8 138/340: travis: Test on 25.1 and 25.2, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c032c8f 141/340: Exec code blocks in markdown labeled as "emacs-lisp" and "elisp", ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b97714d 144/340: Declare all variables before first use, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 4128f3e 147/340: Document ERT support in writing-tests.md, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 47dd72c 156/340: Set file local variables for consistent code style, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 5458dcc 158/340: Replace buttercup-*-parents with buttercup-suite-or-spec-parents, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 77367d3 165/340: Change shebang to use /usr/bin/env, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup bbbf692 166/340: Fix more compile warnings., ELPA Syncer, 2021/12/16