Commit 406c41d9 authored by Ola Nilsson's avatar Ola Nilsson Committed by Jorgen Schäfer

Print elapsed time for each spec

parent edcffdec
......@@ -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
......@@ -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)
......
......@@ -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"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment