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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/buttercup d41c6dc 301/340: Extract buttercup-reporter-batc


From: ELPA Syncer
Subject: [nongnu] elpa/buttercup d41c6dc 301/340: Extract buttercup-reporter-batch--print-summary
Date: Thu, 16 Dec 2021 14:59:55 -0500 (EST)

branch: elpa/buttercup
commit d41c6dcc81f8e8634b09acf8ce245bd99fc58930
Author: Ola Nilsson <ola.nilsson@gmail.com>
Commit: Ola Nilsson <ola.nilsson@gmail.com>

    Extract buttercup-reporter-batch--print-summary
    
    ... from the batch reporters
---
 buttercup.el            | 61 +++++++++++++++++--------------------------------
 tests/test-buttercup.el |  4 ++--
 2 files changed, 23 insertions(+), 42 deletions(-)

diff --git a/buttercup.el b/buttercup.el
index dbfb21b..530569e 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -1658,27 +1658,30 @@ EVENT and ARG are described in `buttercup-reporter'."
             (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 (time-subtract
-                                    (current-time)
-                                    buttercup-reporter-batch--start-time))))
-         (if (> pending 0)
-             (buttercup--print
-              "Ran %s out of %s specs, %s failed, in %s.\n"
-              (- defined pending)
-              defined
-              failed
-              (seconds-to-string duration))
-           (buttercup--print "Ran %s specs, %s failed, in %s.\n"
-                             defined
-                             failed
-                             (seconds-to-string duration)))))
+       (buttercup-reporter-batch--print-summary arg nil))
 
       (_
        (error "Unknown event %s" event)))))
 
+(defun buttercup-reporter-batch--print-summary (suites color)
+  "Print a summary of the reults of SUITES.
+
+Colorize parts of the output if COLOR is non-nil."
+  (let* ((defined (buttercup-suites-total-specs-defined suites))
+         (pending (buttercup-suites-total-specs-pending suites))
+         (failed (buttercup-suites-total-specs-failed suites))
+         (duration (seconds-to-string
+                    (float-time
+                     (time-subtract (current-time)
+                                    buttercup-reporter-batch--start-time))))
+         (out-of (if (zerop pending) "" (format " out of %d" defined)))
+         (failed-str (format "%d failed" failed)))
+    (if color
+        (setq failed-str (buttercup-colorize failed-str (if (zerop failed) 
'green 'red))))
+    (buttercup--print
+     "Ran %d%s specs, %s, in %s.\n"
+     (- defined pending) out-of failed-str duration)))
+
 (defun buttercup-reporter-batch-color (event arg)
   "A reporter that handles batch sessions.
 
@@ -1740,29 +1743,7 @@ EVENT and ARG are described in `buttercup-reporter'."
           (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 (time-subtract (current-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 %s.\n")
-            (- defined pending)
-            defined
-            failed
-            (seconds-to-string duration))
-         (buttercup--print
-          (concat
-           "Ran %s specs,"
-           (buttercup-colorize " %s failed" (if (eq 0 failed) 'green 'red))
-           ", in %s.\n")
-          defined
-          failed
-          (seconds-to-string duration)))))
+     (buttercup-reporter-batch--print-summary arg buttercup-color))
 
     (_
      ;; Fall through to buttercup-reporter-batch implementation.
diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el
index 22973fc..a6774f3 100644
--- a/tests/test-buttercup.el
+++ b/tests/test-buttercup.el
@@ -1292,7 +1292,7 @@ text properties using `ansi-color-apply'."
                 "Ran 10 specs, 0 failed, in [0-9]+.[0-9]+[mu]?s.\n")
         (expect (substring (buttercup-output) 0 (length "Ran 10 specs, 0 
failed, in"))
                 :to-equal-including-properties
-                (ansi-color-apply "Ran 10 specs,\e[32m 0 failed\e[0m, in")))
+                (ansi-color-apply "Ran 10 specs, \e[32m0 failed\e[0m, in")))
 
       (it "should color-print `X failed' specs in red"
         (setq failed-specs 6)
@@ -1302,7 +1302,7 @@ text properties using `ansi-color-apply'."
                 "Ran 10 specs, 6 failed, in [0-9]+.[0-9]+[mu]?s.\n")
         (expect (substring (buttercup-output) 0 (length "Ran 10 specs, 6 
failed, in"))
                 :to-equal-including-properties
-                (ansi-color-apply "Ran 10 specs,\e[31m 6 failed\e[0m, in")))
+                (ansi-color-apply "Ran 10 specs, \e[31m6 failed\e[0m, in")))
 
       (it "should print a summary separating run and pending specs"
         (setq pending-specs 3)



reply via email to

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