emacs-elpa-diffs
[Top][All Lists]
Advanced

[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"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]