[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup edcffde 189/340: Add start and end times to each
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup edcffde 189/340: Add start and end times to each suite or spec |
Date: |
Thu, 16 Dec 2021 14:59:32 -0500 (EST) |
branch: elpa/buttercup
commit edcffdecc164d9fbf2fb8083bfa7019ada7f1d6e
Author: Ola Nilsson <ola.nilsson@gmail.com>
Commit: Jorgen Schäfer <Jorgen.Schaefer@gmail.com>
Add start and end times to each suite or spec
The timestamps and the new function buttercup-elapsed-time can be used
by reporters to print elapsed time.
---
buttercup.el | 24 +++++++++++++++++--
tests/test-buttercup.el | 64 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 86 insertions(+), 2 deletions(-)
diff --git a/buttercup.el b/buttercup.el
index b1fcef7..e030472 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -670,7 +670,8 @@ See also `buttercup-define-matcher'."
(status 'passed)
failure-description
failure-stack
- )
+ time-started
+ time-ended)
(cl-defstruct (buttercup-suite (:include buttercup-suite-or-spec))
;; Any children of this suite, both suites and specs
@@ -771,6 +772,21 @@ See also `buttercup-define-matcher'."
(push name duplicates)
(push name seen)))))
+(defun buttercup--set-start-time (suite-or-spec)
+ "Set time-started of SUITE-OR-SPEC to `current-time'."
+ (setf (buttercup-suite-or-spec-time-started suite-or-spec) (current-time)))
+
+(defun buttercup--set-end-time (suite-or-spec)
+ "Set time-ended of SUITE-OR-SPEC to `current-time'."
+ (setf (buttercup-suite-or-spec-time-ended suite-or-spec) (current-time)))
+
+(defun buttercup-elapsed-time (suite-or-spec)
+ "Get elapsed time of SUITE-OR-SPEC."
+ ;; time-subtract does not handle nil arguments until Emacs 25.1
+ (time-subtract
+ (or (buttercup-suite-or-spec-time-ended suite-or-spec) (current-time))
+ (or (buttercup-suite-or-spec-time-started suite-or-spec) (current-time))))
+
;;;;;;;;;;;;;;;;;;;;
;;; Suites: describe
@@ -1349,6 +1365,7 @@ Do not change the global value.")
(defun buttercup--run-suite (suite)
"Run SUITE. A suite is a sequence of suites and specs."
+ (buttercup--set-start-time suite)
(let* ((buttercup--before-each (append buttercup--before-each
(buttercup-suite-before-each suite)))
(buttercup--after-each (append (buttercup-suite-after-each suite)
@@ -1364,9 +1381,11 @@ Do not change the global value.")
(buttercup--run-spec sub))))
(dolist (f (buttercup-suite-after-all suite))
(buttercup--update-with-funcall suite f))
+ (buttercup--set-end-time suite)
(funcall buttercup-reporter 'suite-done suite)))
(defun buttercup--run-spec (spec)
+ (buttercup--set-start-time spec)
(unwind-protect
(progn
;; Kill any previous warning buffer, just in case
@@ -1391,7 +1410,8 @@ Do not change the global value.")
(buffer-string)
'yellow)))))
(when (get-buffer buttercup-warning-buffer-name)
- (kill-buffer buttercup-warning-buffer-name))))
+ (kill-buffer buttercup-warning-buffer-name))
+ (buttercup--set-end-time spec)))
(defun buttercup--update-with-funcall (suite-or-spec function &rest args)
"Update SUITE-OR-SPEC with the result of calling FUNCTION with ARGS.
diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el
index c32a384..80c5721 100644
--- a/tests/test-buttercup.el
+++ b/tests/test-buttercup.el
@@ -302,6 +302,70 @@
:to-equal
"su1 su2 sp2"))))
+(describe "The `buttercup-elapsed-time' function"
+ (let ((spytime (current-time)))
+ (before-each
+ (spy-on 'current-time
+ :and-call-fake
+ (lambda ()
+ (setq spytime (time-add spytime (seconds-to-time 1.5))))))
+ (it "should report elapsed time for suites"
+ (let ((suite (make-buttercup-suite)))
+ (buttercup--set-start-time suite)
+ (buttercup--set-end-time suite)
+ (expect (buttercup-elapsed-time suite)
+ :to-equal (seconds-to-time 1.5))))
+ (it "should report elapsed time for specs"
+ (let ((spec (make-buttercup-spec)))
+ (buttercup--set-start-time spec)
+ (buttercup--set-end-time spec)
+ (expect (buttercup-elapsed-time spec)
+ :to-equal (seconds-to-time 1.5))))))
+
+(defmacro with-local-buttercup (&rest body)
+ "Execute BODY with local buttercup state variables."
+ (declare (debug t) (indent defun))
+ `(let (buttercup--after-all
+ buttercup--after-each
+ buttercup--before-all
+ buttercup--before-each
+ buttercup--cleanup-functions
+ buttercup--current-suite
+ (buttercup-reporter #'ignore)
+ buttercup-suites
+ (buttercup-warning-buffer-name " *ignored buttercup warnings*"))
+ ,@body))
+
+(describe "The `buttercup--run-suite' function"
+ (before-each
+ (spy-on 'buttercup--set-start-time :and-call-through)
+ (spy-on 'buttercup--set-end-time :and-call-through))
+ (it "should set start and end time of the suite"
+ (with-local-buttercup
+ (let ((suite (make-buttercup-suite)))
+ (buttercup--run-suite suite)
+ (expect 'buttercup--set-start-time :to-have-been-called-times 1)
+ (expect (buttercup-suite-or-spec-time-started suite)
+ :not :to-be nil)
+ (expect 'buttercup--set-end-time :to-have-been-called-times 1)
+ (expect (buttercup-suite-or-spec-time-ended suite)
+ :not :to-be nil)))))
+
+(describe "The `buttercup--run-spec' function"
+ (before-each
+ (spy-on 'buttercup--set-start-time :and-call-through)
+ (spy-on 'buttercup--set-end-time :and-call-through))
+ (it "should set start and end time of the spec"
+ (with-local-buttercup
+ (let ((spec (make-buttercup-spec)))
+ (buttercup--run-spec spec)
+ (expect 'buttercup--set-start-time :to-have-been-called-times 1)
+ (expect (buttercup-suite-or-spec-time-started spec)
+ :not :to-be nil)
+ (expect 'buttercup--set-end-time :to-have-been-called-times 1)
+ (expect (buttercup-suite-or-spec-time-ended spec)
+ :not :to-be nil)))))
+
;;;;;;;;;;;;;;;;;;;;
;;; Suites: describe
- [nongnu] elpa/buttercup 07cf64b 140/340: Run test-buttercup.el before tests in writing-tests.md, (continued)
- [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
- [nongnu] elpa/buttercup 079ef3e 186/340: Bump version: 1.12 → 1.13, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 1998ae3 188/340: Drop unused variable in buttercup--disable-specs, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup edcffde 189/340: Add start and end times to each suite or spec,
ELPA Syncer <=
- [nongnu] elpa/buttercup 075b318 198/340: Add support for :var*, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 1c762a5 200/340: Add documentation for :var and :var*, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 159fe3c 203/340: Really fix the buttercup-run tests, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d2b6692 206/340: Bump version: 1.16 → 1.17, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup e62ce43 207/340: test: Do not leak functions from "The Spy " test suite, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 8b3cfad 214/340: Update test for new warning capture suppression behavior, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 1567c03 215/340: Add emacs-26.3 to CI config, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 6cf8041 229/340: Update writing-tests.md to describe new spy context structs, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup c720cef 233/340: Merge pull request #146 from DarwinAwardWinner/spy-record-errors, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b2edd35 235/340: Change: (buttercup-define-matcher-for-binary-function) Add newlines, ELPA Syncer, 2021/12/16