branch: elpa/buttercup
commit 48753c6ede10b5ddc019f2b911afdb040ea3342f
Author: Ola Nilsson <ola.nils...@gmail.com>
Commit: Ola Nilsson <ola.nils...@gmail.com>

    test: Set b*c*-r*r-batch--start-time in with-local-buttercup
    
    The value of the actual buttercup-reporter-batch--start-time variable
    should only be used by the main test loop, not by the tests used to
    verify buttercup.  Otherwise the time could easily be accidentaly
    reset by the individual tests.  The variable value needs to be an
    actual timestamp or some elapsed times will be reported as "-0.00ms"
    which will cause test failures.
    
    The "on the buttercup-started event" and "on the buttercup-done event"
    suites should not use the :var tag to set the variable.  This is not
    supported for dynamic variables, which was exposed by the recently
    added warning.
---
 buttercup.el            |  6 ++++--
 tests/test-buttercup.el | 12 ++++--------
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/buttercup.el b/buttercup.el
index f4b750617d..630ad1ea14 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -1,7 +1,7 @@
 ;;; buttercup.el --- Behavior-Driven Emacs Lisp Testing -*-lexical-binding:t-*-
 
 ;; Copyright (C) 2015-2017  Jorgen Schaefer <cont...@jorgenschaefer.de>
-;; Copyright (C) 2018-2024  Ola Nilsson <ola.nils...@gmail.com>
+;; Copyright (C) 2018-2025  Ola Nilsson <ola.nils...@gmail.com>
 
 ;; Version: 1.37
 ;; Author: Jorgen Schaefer <cont...@jorgenschaefer.de>
@@ -1793,7 +1793,9 @@ EVENT and ARG are described in `buttercup-reporter'."
     (buttercup-reporter-interactive event arg)))
 
 (defvar buttercup-reporter-batch--start-time nil
-  "The time the last batch report started.")
+  "The time the last batch report started.
+Shall be set to a Lisp timestamp (see Info node `(elisp)Time of Day') at
+the `buttercup-started' event.")
 
 (defvar buttercup-reporter-batch--failures nil
   "List of failed specs of the current batch report.")
diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el
index 4da26dea2f..6c03919fc7 100644
--- a/tests/test-buttercup.el
+++ b/tests/test-buttercup.el
@@ -1,7 +1,7 @@
 ;;; buttercup-test.el --- Tests for buttercup.el -*-lexical-binding:t-*-
 
 ;; Copyright (C) 2015-2017 Jorgen Schaefer <cont...@jorgenschaefer.de>
-;; Copyright (C) 2017-2024 Ola Nilsson <ola.nils...@gmail.com>
+;; Copyright (C) 2017-2025 Ola Nilsson <ola.nils...@gmail.com>
 
 ;; This program is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU General Public License
@@ -71,6 +71,7 @@ variables or environment variables while executing BODY:
          buttercup-suites
          buttercup-color
          buttercup-reporter-batch-quiet-statuses
+         (buttercup-reporter-batch--start-time (current-time))
          buttercup-reporter-batch--suite-stack
          buttercup-reporter-batch--failures
          (buttercup-stack-frame-style 'crop)
@@ -1696,11 +1697,7 @@ before it's processed by other functions."
       (setq print-buffer nil))
 
     (describe "on the buttercup-started event"
-      :var (skipped
-            ;; Local var for testing. The real variable is used by the
-            ;; reporter attached to the buttercup instance running
-            ;; these tests.
-            buttercup-reporter-batch--start-time)
+      :var (skipped)
       (before-each
         (setq skipped (make-buttercup-spec :description "skipped" :status 
'pending)))
 
@@ -1871,8 +1868,7 @@ before it's processed by other functions."
         (expect (buttercup-output) :to-equal-including-properties "")))
 
     (describe "on the buttercup-done event"
-      :var ((buttercup-reporter-batch--start-time (current-time))
-            defined-specs pending-specs failed-specs)
+      :var (defined-specs pending-specs failed-specs)
 
       (before-each
         (setq defined-specs 10 pending-specs 0 failed-specs 0)

Reply via email to