[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup 24a7bb9 306/340: Extract buttercup-reporter-batc
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup 24a7bb9 306/340: Extract buttercup-reporter-batch--print-spec-done-line |
Date: |
Thu, 16 Dec 2021 14:59:56 -0500 (EST) |
branch: elpa/buttercup
commit 24a7bb9389416ce3e9a09f98aafa7ba51b56fd0c
Author: Ola Nilsson <ola.nilsson@gmail.com>
Commit: Ola Nilsson <ola.nilsson@gmail.com>
Extract buttercup-reporter-batch--print-spec-done-line
... from the batch reporters.
---
buttercup.el | 89 +++++++++++++++++++++++++++++--------------------
tests/test-buttercup.el | 14 +++++---
2 files changed, 63 insertions(+), 40 deletions(-)
diff --git a/buttercup.el b/buttercup.el
index 3deceed..6ba18d7 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -1622,18 +1622,11 @@ EVENT and ARG are described in `buttercup-reporter'."
(string-match-p "[\n\v\f]" (buttercup-spec-description
arg)))
(buttercup--print "%s" (buttercup--indented-description arg))))
(`spec-done
- (pcase (buttercup-spec-status arg)
- (`passed) ; do nothing
- (`failed
- (buttercup--print " FAILED")
- (setq buttercup-reporter-batch--failures
- (append buttercup-reporter-batch--failures
- (list arg))))
- (`pending
- (buttercup--print " %s" (buttercup-spec-failure-description arg)))
- (_
- (error "Unknown spec status %s" (buttercup-spec-status arg))))
- (buttercup--print " (%s)\n" (buttercup-elapsed-time-string arg)))
+ (when (eq (buttercup-spec-status arg) 'failed)
+ (setq buttercup-reporter-batch--failures
+ (append buttercup-reporter-batch--failures
+ (list arg))))
+ (buttercup-reporter-batch--print-spec-done-line arg buttercup-color))
(`suite-done
(when (= 0 (length (buttercup-suite-or-spec-parents arg)))
@@ -1647,6 +1640,52 @@ EVENT and ARG are described in `buttercup-reporter'."
(_
(error "Unknown event %s" event)))))
+(defun buttercup-reporter-batch--print-spec-done-line (spec color)
+ "Print the remainder of the SPEC report line for `spec-done'.
+
+If COLOR is non-nil, erace the text so far on the current line
+using '\r' and replace it with the same text colored according to
+the SPEC status. Do not erase and replace if the text would have
+been reprinted with the default color.
+
+Then print the SPEC failure description except if the status is
+`passed'. If COLOR is non-nil, print it in the aproprate color
+for the spec status.
+
+Finally print the elapsed time for SPEC."
+ (let* ((status (buttercup-spec-status spec))
+ (failure (buttercup-spec-failure-description spec)))
+ ;; Failed specs do typically not have string filure-descriptions.
+ ;; In this typical case, use the string "FAILED" for the output.
+ (and (eq status 'failed)
+ (not (stringp failure))
+ (setq failure "FAILED"))
+ (unless (memq status '(passed pending failed))
+ (error "Unknown spec status %s" status))
+ ;; Special status in this function;
+ ;; skipped - a pending spec with failure description "SKIPPED".
+ (and (eq status 'pending)
+ (equal failure "SKIPPED")
+ (setq status 'skipped))
+ ;; Use color both as a boolean for erase-and-reprint and the color
+ ;; to use. nil means the default color.
+ (setq color (and color (pcase status
+ (`passed 'green)
+ (`pending 'yellow)
+ (`failed 'red)
+ (`skipped nil))))
+ (when color
+ ;; Carriage returns (\r) should not be colorized. It would mess
+ ;; up color handling in Emacs compilation buffers using
+ ;; `ansi-color-apply-on-region' in `compilation-filter-hook'.
+ (buttercup--print "\r%s"
+ (buttercup-colorize
+ (buttercup--indented-description spec) color)))
+ (unless (eq 'passed status)
+ (buttercup--print "%s"
+ (buttercup-colorize (concat " " failure) color)))
+ (buttercup--print " (%s)\n" (buttercup-elapsed-time-string spec))))
+
(defun buttercup-reporter-batch--print-failed-spec-report (failed-spec color)
"Print a failure report for FAILED-SPEC.
@@ -1706,33 +1745,11 @@ colors.
EVENT and ARG are described in `buttercup-reporter'."
(pcase event
(`spec-done
- ;; Carriage returns (\r) should not be colorized. It would mess
- ;; up color handling in Emacs compilation buffers using
- ;; `ansi-color-apply-on-region' in `compilation-filter-hook'.
- (pcase (buttercup-spec-status arg)
- (`passed
- (buttercup--print
- "\r%s" (buttercup-colorize (buttercup--indented-description arg)
'green)))
- (`failed
- (buttercup--print
- "\r%s" (buttercup-colorize
- (concat (buttercup--indented-description arg) " FAILED")
- 'red))
+ (when (eq (buttercup-spec-status arg) 'failed)
(setq buttercup-reporter-batch--failures
(append buttercup-reporter-batch--failures
(list arg))))
- (`pending
- (if (equal (buttercup-spec-failure-description arg) "SKIPPED")
- (buttercup--print " %s" (buttercup-spec-failure-description arg))
- (buttercup--print
- "\r%s" (buttercup-colorize
- (concat (buttercup--indented-description arg) " "
- (buttercup-spec-failure-description arg))
- 'yellow))))
- (_
- (error "Unknown spec status %s" (buttercup-spec-status arg))))
- (buttercup--print " (%s)\n" (buttercup-elapsed-time-string arg)))
-
+ (buttercup-reporter-batch--print-spec-done-line arg buttercup-color))
(_
;; Fall through to buttercup-reporter-batch implementation.
(buttercup-reporter-batch event arg)))
diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el
index a6774f3..9f7b9fe 100644
--- a/tests/test-buttercup.el
+++ b/tests/test-buttercup.el
@@ -1242,10 +1242,16 @@ text properties using `ansi-color-apply'."
(format "\e[33m spec DESCRIPTION\e[0m (%s)\n"
(buttercup-elapsed-time-string spec))))))
- (it "should throw an error for an unknown spec status"
- (setf (buttercup-spec-status spec) 'unknown)
- (expect (buttercup-reporter-batch 'spec-done spec)
- :to-throw)))
+ (describe "should throw an error for an unknown spec status"
+ (before-each (setf (buttercup-spec-status spec) 'unknown))
+ (it "for plain output"
+ (with-local-buttercup :color nil
+ (expect (buttercup-reporter-batch 'spec-done spec)
+ :to-throw)))
+ (it "for colored output"
+ (with-local-buttercup :color t
+ (expect (buttercup-reporter-batch 'spec-done spec)
+ :to-throw)))))
(describe "on the suite-done event"
(it "should emit a newline at the end of a top-level suite"
- [nongnu] elpa/buttercup a22fc29 288/340: Bump version: 1.21 → 1.22, (continued)
- [nongnu] elpa/buttercup a22fc29 288/340: Bump version: 1.21 → 1.22, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup dde8651 290/340: Add new function buttercup--spec-mark-pending and use it, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c59110b 291/340: test: Extend with-local-buttercup with some key arguments, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d443ecb 293/340: Clarify patterns in bin/buttercup, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 4d1acb8 294/340: test: Rewrite buttercup-run tests using spies, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 37223e4 296/340: actions: Run actions on push for all branches, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 50c7fc2 297/340: Switch to pcase in spec-done case of buttercup-reporter-batch, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup dd32cc7 298/340: test: Fix "should color-print pending spec count in default color", ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 0debeec 299/340: test: Use with-local-buttercup in more tests, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b3acf50 304/340: Lift spec-started handling into buttercup-reporter-batch, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 24a7bb9 306/340: Extract buttercup-reporter-batch--print-spec-done-line,
ELPA Syncer <=
- [nongnu] elpa/buttercup c9addd5 307/340: Lift spec-done handling into buttercup-reporter-batch, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d6de872 309/340: Improve buttercup-reporter-batch--print-failed-spec-report, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 392b99c 310/340: Extend batch reporters to optionally print sparse reports, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f6ab784 315/340: test: Test on GNU Emacs 27.1, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 4d974d2 319/340: Use correct function for --stale-file-error, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup a37d1a0 325/340: Fix compilation warning about undefined variable., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b4e0986 333/340: Merge pull request #194 from doublep/eldev-doc, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 108d229 340/340: Fix property comparisons in unit tests., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup dacfacc 332/340: Recognize buttercup--mark-stackframe in buttercup--enclosed-expr, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup bd55e2b 330/340: Add stacktrace style `omit`, ELPA Syncer, 2021/12/16