[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup a05fdcb 117/340: Colorize output
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup a05fdcb 117/340: Colorize output |
Date: |
Thu, 16 Dec 2021 14:59:16 -0500 (EST) |
branch: elpa/buttercup
commit a05fdcbeaa45c8c229718aafe8d04e1b24d26ab8
Author: Thomas Fini Hansen <xen@xen.dk>
Commit: Thomas Fini Hansen <xen@xen.dk>
Colorize output
---
bin/buttercup | 4 +++
buttercup.el | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 111 insertions(+), 1 deletion(-)
diff --git a/bin/buttercup b/bin/buttercup
index 05929f1..9f63e69 100755
--- a/bin/buttercup
+++ b/bin/buttercup
@@ -25,6 +25,10 @@ do
shift
shift
;;
+ "-c"|"--no-color")
+ BUTTERCUP_ARGS+=("$1")
+ shift
+ ;;
*)
BUTTERCUP_ARGS+=("$1")
shift
diff --git a/buttercup.el b/buttercup.el
index 0def52d..49c428c 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -676,6 +676,9 @@ current directory."
(error "Option requires argument: %s" (car args)))
(push (cadr args) patterns)
(setq args (cddr args)))
+ ((member (car args) '("-c" "--no-color"))
+ (setq buttercup-color nil)
+ (setq args (cdr args)))
(t
(push (car args) dirs)
(setq args (cdr args)))))
@@ -823,13 +826,18 @@ suite-done -- A suite has finished. The argument is the
spec.
buttercup-done -- All suites have run, the test run is over.")
+(defvar buttercup-color t
+ "Whether to use colors in output.")
+
(defun buttercup-reporter-adaptive (event arg)
"A reporter that handles both interactive and noninteractive sessions.
Calls either `buttercup-reporter-batch' or
`buttercup-reporter-interactive', depending."
(if noninteractive
- (buttercup-reporter-batch event arg)
+ (if buttercup-color
+ (buttercup-reporter-batch-color event arg)
+ (buttercup-reporter-batch event arg))
(buttercup-reporter-interactive event arg)))
(defvar buttercup-reporter-batch--start-time nil
@@ -929,9 +937,107 @@ Calls either `buttercup-reporter-batch' or
(_
(error "Unknown event %s" event)))))
+(defun buttercup-reporter-batch-color (event arg)
+ (pcase event
+ (`spec-done
+ (let ((level (length (buttercup-spec-parents arg))))
+ (cond
+ ((eq (buttercup-spec-status arg) 'passed)
+ (buttercup--print (buttercup-colorize "\r%s%s\n" 'green)
+ (make-string (* 2 level) ?\s)
+ (buttercup-spec-description arg)))
+ ((eq (buttercup-spec-status arg) 'failed)
+ (buttercup--print (buttercup-colorize "\r%s%s FAILED\n" 'red)
+ (make-string (* 2 level) ?\s)
+ (buttercup-spec-description arg))
+ (setq buttercup-reporter-batch--failures
+ (append buttercup-reporter-batch--failures
+ (list arg))))
+ ((eq (buttercup-spec-status arg) 'pending)
+ (if (equal (buttercup-spec-failure-description arg) "SKIPPED")
+ (buttercup--print " %s\n" (buttercup-spec-failure-description arg))
+ (buttercup--print (buttercup-colorize "\r%s%s %s\n" 'yellow)
+ (make-string (* 2 level) ?\s)
+ (buttercup-spec-description arg)
+ (buttercup-spec-failure-description arg))))
+ (_
+ (error "Unknown spec status %s" (buttercup-spec-status arg))))))
+
+ (`buttercup-done
+ (dolist (failed buttercup-reporter-batch--failures)
+ (let ((description (buttercup-spec-failure-description failed))
+ (stack (buttercup-spec-failure-stack failed)))
+ (buttercup--print "%s\n" (make-string 40 ?=))
+ (buttercup--print (buttercup-colorize "%s\n" 'red)
(buttercup-spec-full-name failed))
+ (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))))
+ (cond
+ ((stringp description)
+ (buttercup--print (concat (buttercup-colorize "FAILED" 'red ) ":
%s\n")
+ description))
+ ((eq (car description) 'error)
+ (buttercup--print "%S: %S\n\n"
+ (car description)
+ (cadr description)))
+ (t
+ (buttercup--print "FAILED: %S\n" description)))
+ (buttercup--print "\n")))
+ (let ((defined (buttercup-suites-total-specs-defined arg))
+ (pending (buttercup-suites-total-specs-pending arg))
+ (failed (buttercup-suites-total-specs-failed arg))
+ (duration (- (float-time)
+ buttercup-reporter-batch--start-time)))
+ (if (> pending 0)
+ (buttercup--print
+ (concat
+ "Ran %s out of %s specs,"
+ (buttercup-colorize " %s failed" (if (eq 0 failed) 'green 'red))
+ ", in %.1f seconds.\n")
+ (- defined pending)
+ defined
+ failed
+ duration)
+ (buttercup--print
+ (concat
+ "Ran %s specs,"
+ (buttercup-colorize " %s failed" (if (eq 0 failed) 'green 'red))
+ ", in %.1f seconds.\n")
+ defined
+ failed
+ duration))
+ (when (> failed 0)
+ (error ""))))
+
+ (_
+ ;; Fall through to buttercup-reporter-batch implementation.
+ (buttercup-reporter-batch event arg)))
+ )
+
(defun buttercup--print (fmt &rest args)
(send-string-to-terminal (apply #'format fmt args)))
+(defconst buttercup-colors
+ '((black . 30)
+ (red . 31)
+ (green . 32)
+ (yellow . 33)
+ (blue . 34)
+ (magenta . 35)
+ (cyan . 36)
+ (white . 37))
+ "List of text colors.")
+
+(defun buttercup-colorize (string color)
+ "Format STRING with COLOR."
+ (let ((color-code (cdr (assoc color buttercup-colors))))
+ (format "\u001b[%sm%s\u001b[0m" color-code string)))
+
(defun buttercup-reporter-interactive (event arg)
"Reporter for interactive uses."
;; This is a bit rudimentary ...
- [nongnu] elpa/buttercup b3bb12a 070/340: buttercup-run-discover: Fix regexp., (continued)
- [nongnu] elpa/buttercup b3bb12a 070/340: buttercup-run-discover: Fix regexp., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 26f8117 071/340: Rename buttercup-test.el and move it to the right directory., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f593486 092/340: Use pattern _ not t in pcase, as t is deprecated, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 0a889e2 098/340: Merge pull request #43 from spwhitton/apt-get, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup afbaae1 091/340: Document file names for test discovery, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 25cb350 089/340: Rename docs to be more easily understandable, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 6d96ea3 093/340: Add format specifier to error call with argument, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup cef9988 110/340: Merge pull request #61 from spwhitton/fix-regexp, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 2b5f53d 121/340: [Fix #72] Add buttercup-minor-mode, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 5db07c9 112/340: Merge pull request #63 from ebpa/patch-1, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup a05fdcb 117/340: Colorize output,
ELPA Syncer <=
- [nongnu] elpa/buttercup ed649d7 125/340: Merge pull request #76 from DamienCassou/make-buttercup--with-cleanup-public, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup ce75b50 115/340: Report load errors in buttercup-run-discover, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 3deb9a4 053/340: Test discovery: Ignore files in dot directories., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 444716b 079/340: Handle windows better in interactive runs., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 512b82b 077/340: Rework documentation to make the readme more concise., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 238bfa8 082/340: Support --pattern command line argument, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 5cbd468 084/340: Bump version: 1.2 → 1.3, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup ba8cd05 106/340: Merge pull request #59 from immerrr/add-other-emacs-params, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 07c525e 116/340: Merge pull request #68 from ebpa/report-load-errors, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 11f072f 123/340: Merge pull request #81 from DamienCassou/fix-to-have-same-items-as, ELPA Syncer, 2021/12/16