summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOla Nilsson <ola.nilsson@gmail.com>2018-09-09 23:36:26 +0200
committerJorgen Schäfer <Jorgen.Schaefer@gmail.com>2018-09-21 11:30:44 +0200
commit406c41d9a795ed17f6d91f7b9ea2c66edd9fdbb5 (patch)
tree3731b9f5b552a16f3ff2664c5f26a3680c71ef22
parentedcffdecc164d9fbf2fb8083bfa7019ada7f1d6e (diff)
Print elapsed time for each spec
-rw-r--r--buttercup-compat.el19
-rw-r--r--buttercup.el25
-rw-r--r--tests/test-buttercup.el32
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"