[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup 406c41d 190/340: Print elapsed time for each spe
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup 406c41d 190/340: Print elapsed time for each spec |
Date: |
Thu, 16 Dec 2021 14:59:32 -0500 (EST) |
branch: elpa/buttercup
commit 406c41d9a795ed17f6d91f7b9ea2c66edd9fdbb5
Author: Ola Nilsson <ola.nilsson@gmail.com>
Commit: Jorgen Schäfer <Jorgen.Schaefer@gmail.com>
Print elapsed time for each spec
---
buttercup-compat.el | 19 +++++++++++++++++++
buttercup.el | 25 +++++++++++++++----------
tests/test-buttercup.el | 32 +++++++++++++++++++++++++++-----
3 files changed, 61 insertions(+), 15 deletions(-)
diff --git a/buttercup-compat.el b/buttercup-compat.el
index cd1776e..d70bd62 100644
--- a/buttercup-compat.el
+++ b/buttercup-compat.el
@@ -91,5 +91,24 @@ If INCLUDE-DIRECTORIES, also include directories that have
matching names."
(and (> (length name) 0)
(char-equal (aref name (1- (length name))) ?/))))
+(when (not (fboundp 'seconds-to-string))
+ (defvar seconds-to-string
+ (list (list 1 "ms" 0.001)
+ (list 100 "s" 1)
+ (list (* 60 100) "m" 60.0)
+ (list (* 3600 30) "h" 3600.0)
+ (list (* 3600 24 400) "d" (* 3600.0 24.0))
+ (list nil "y" (* 365.25 24 3600)))
+ "Formatting used by the function `seconds-to-string'.")
+ (defun seconds-to-string (delay)
+ "Convert the time interval in seconds to a short string."
+ (cond ((> 0 delay) (concat "-" (seconds-to-string (- delay))))
+ ((= 0 delay) "0s")
+ (t (let ((sts seconds-to-string) here)
+ (while (and (car (setq here (pop sts)))
+ (<= (car here) delay)))
+ (concat (format "%.2f" (/ delay (car (cddr here)))) (cadr
here)))))))
+
+
(provide 'buttercup-compat)
;;; buttercup-compat.el ends here
diff --git a/buttercup.el b/buttercup.el
index e030472..2437001 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -1488,17 +1488,19 @@ EVENT and ARG are described in `buttercup-reporter'."
(`spec-done
(cond
- ((eq (buttercup-spec-status arg) 'passed)
- (buttercup--print "\n"))
+ ((eq (buttercup-spec-status arg) 'passed)) ; do nothing
((eq (buttercup-spec-status arg) 'failed)
- (buttercup--print " FAILED\n")
+ (buttercup--print " FAILED")
(setq buttercup-reporter-batch--failures
(append buttercup-reporter-batch--failures
(list arg))))
((eq (buttercup-spec-status arg) 'pending)
- (buttercup--print " %s\n" (buttercup-spec-failure-description arg)))
+ (buttercup--print " %s" (buttercup-spec-failure-description arg)))
(t
- (error "Unknown spec status %s" (buttercup-spec-status arg)))))
+ (error "Unknown spec status %s" (buttercup-spec-status arg))))
+ (buttercup--print " (%s)\n"
+ (seconds-to-string
+ (float-time (buttercup-elapsed-time arg)))))
(`suite-done
(when (= 0 (length (buttercup-suite-or-spec-parents arg)))
@@ -1559,11 +1561,11 @@ EVENT and ARG are described in `buttercup-reporter'."
(let ((level (length (buttercup-suite-or-spec-parents arg))))
(cond
((eq (buttercup-spec-status arg) 'passed)
- (buttercup--print (buttercup-colorize "\r%s%s\n" 'green)
+ (buttercup--print (buttercup-colorize "\r%s%s" '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)
+ (buttercup--print (buttercup-colorize "\r%s%s FAILED" 'red)
(make-string (* 2 level) ?\s)
(buttercup-spec-description arg))
(setq buttercup-reporter-batch--failures
@@ -1571,13 +1573,16 @@ EVENT and ARG are described in `buttercup-reporter'."
(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)
+ (buttercup--print " %s" (buttercup-spec-failure-description arg))
+ (buttercup--print (buttercup-colorize "\r%s%s %s" 'yellow)
(make-string (* 2 level) ?\s)
(buttercup-spec-description arg)
(buttercup-spec-failure-description arg))))
(t
- (error "Unknown spec status %s" (buttercup-spec-status arg))))))
+ (error "Unknown spec status %s" (buttercup-spec-status arg))))
+ (buttercup--print " (%s)\n"
+ (seconds-to-string
+ (float-time (buttercup-elapsed-time arg))))))
(`buttercup-done
(dolist (failed buttercup-reporter-batch--failures)
diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el
index 80c5721..39cc272 100644
--- a/tests/test-buttercup.el
+++ b/tests/test-buttercup.el
@@ -912,10 +912,16 @@
"spec")))
(describe "on the spec-done event"
- (it "should simply emit a newline for a passed spec"
+ (it "should print no status tag for a passed spec"
+ (buttercup--set-start-time spec)
+ (setf (buttercup-spec-failure-description spec) "DONTSHOW")
+ (buttercup--set-end-time spec)
(buttercup-reporter-batch 'spec-done spec)
- (expect 'buttercup--print :to-have-been-called-with "\n"))
+ (expect (mapconcat (apply-partially #'apply #'format)
+ (spy-calls-all-args 'buttercup--print)
+ "")
+ :to-match "^\\s-*([0-9]+\\.[0-9]+\\(h\\|m\\|m?s\\))\n$"))
(it "should say FAILED for a failed spec"
(setf (buttercup-spec-status spec) 'failed)
@@ -923,7 +929,10 @@
(let ((buttercup-reporter-batch--failures nil))
(buttercup-reporter-batch 'spec-done spec))
- (expect 'buttercup--print :to-have-been-called-with " FAILED\n"))
+ (expect (mapconcat (apply-partially #'apply #'format)
+ (spy-calls-all-args 'buttercup--print)
+ "")
+ :to-match "FAILED\\(\\s-+.*\\)?\n$"))
(it "should output the failure-description for a pending spec"
(setf (buttercup-spec-status spec) 'pending
@@ -932,13 +941,26 @@
(buttercup-reporter-batch 'spec-done spec))
(expect (mapconcat (apply-partially #'apply #'format)
(spy-calls-all-args 'buttercup--print) "")
- :to-match "DESCRIPTION"))
+ :to-match "DESCRIPTION\\(\\s-+.*\\)?\n$"))
(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)))
+ :to-throw))
+
+ (it "should print the elapsed time for all specs"
+ (dolist (state '(pending failed passed))
+ (setq spec (make-buttercup-spec :description "spec" :status state
:parent child-suite))
+ (buttercup--set-start-time spec)
+ (buttercup--set-end-time spec)
+ (let ((buttercup-reporter-batch--failures nil))
+ (buttercup-reporter-batch 'spec-done spec))
+
+ (expect (mapconcat (apply-partially #'apply #'format)
+ (spy-calls-all-args 'buttercup--print)
+ "")
+ :to-match "([0-9]+\\.[0-9]+\\(h\\|m\\|m?s\\))"))))
(describe "on the suite-done event"
(it "should emit a newline at the end of the top-level suite"
- [nongnu] elpa/buttercup 794afbf 114/340: Merge pull request #65 from DamienCassou/patch-1, (continued)
- [nongnu] elpa/buttercup 794afbf 114/340: Merge pull request #65 from DamienCassou/patch-1, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d5c9a19 120/340: Make --with-cleanup public so spies can be used without specs, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 79286cf 055/340: Test for the batch reporter., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 87e0c0d 073/340: Bump version: 1.0 → 1.1, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 10e0537 150/340: Manually fix bumpversion.cfg, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 18a8879 151/340: Bump version: 1.8 → 1.9, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 62c416a 164/340: Rewrite the pattern loop of buttercup-run-discover, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 636db47 172/340: Typo fixes (#126), ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 8034597 175/340: Replace remaining calls to obsolete buttercup-*-parents, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f57036f 180/340: Update the disabled/pending sections of writing-tests.md, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 406c41d 190/340: Print elapsed time for each spec,
ELPA Syncer <=
- [nongnu] elpa/buttercup 19f256e 094/340: Update copyright / license information for some details, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 46882f8 131/340: Show a message about duplicate spec names, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 07cf64b 140/340: Run test-buttercup.el before tests in writing-tests.md, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 2edeae5 159/340: Rewrite buttercup-suite-full-name with a single loop, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 4063f55 162/340: Add function buttercup--specs, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup bf0e1da 049/340: Rename tar target to release and add compile and clean targets., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 17f3cf5 062/340: Remove error in favor of failed., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f3d6709 074/340: Use relative path when testing for dotfiles in current project, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup acccc0f 179/340: Modify xdescribe to keep all contained specs as pending, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d07dbf3 182/340: Merge pull request #129 from snogge/fix-obsolete-aliases, ELPA Syncer, 2021/12/16