branch: elpa/buttercup commit 96f0b9b7a14e8c66eeaaf89f66240ee4302999da Merge: 700dfbb569 48753c6ede Author: Ola Nilsson <ola.nils...@gmail.com> Commit: Ola Nilsson <ola.nils...@gmail.com>
Merge pull request #255 from snogge/fix-255 * fix-255: test: Set b*c*-r*r-batch--start-time in with-local-buttercup Use format instead of concat for constructing warning message Warn when :var is used with a special variable --- buttercup.el | 44 ++++++++++++++++++++++++++++++-------------- tests/test-buttercup.el | 12 ++++-------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/buttercup.el b/buttercup.el index f7349f357f..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> @@ -951,19 +951,33 @@ mainly calls to `describe', `it' and `before-each'." (unless lexical-binding (signal 'buttercup-dynamic-binding-error "buttercup requires `lexical-binding' to be t")) - (let ((new-body - (cond - ((eq (elt body 0) :var) - `((let ,(elt body 1) - ,@(cddr body)))) - ((eq (elt body 0) :var*) - `((let* ,(elt body 1) - ,@(cddr body)))) - (t body)))) - (if (or (memq :var new-body) - (memq :var* new-body)) + ;; Convert `:var' or `:var*' to a lexical let form + (when + (memq (elt body 0) '(:var :var*)) + (let ((let-form-to-use (if (eq (elt body 0) :var) 'let 'let*)) + (let-bindings (elt body 1)) + (let-body (cddr body))) + ;; Verify that all the specified variables are lexical + (cl-loop + for binding in let-bindings + for var = (if (symbolp binding) binding (car binding)) + when (special-variable-p var) + do (display-warning + 'buttercup-describe + (format + "Possible erroneous use of special variable `%s' in :var(*) form" + var))) + ;; Wrap new body in the appropriate let form + (setq body + `((,let-form-to-use + ;; Let bindings + ,let-bindings + ;; Let body + ,@let-body))))) + (if (or (memq :var body) + (memq :var* body)) `(error "buttercup: :var(*) found in invalid position of describe form \"%s\"" ,description) - `(buttercup-describe ,description (lambda () ,@new-body))))) + `(buttercup-describe ,description (lambda () ,@body)))) (defun buttercup-describe (description body-function) "Function to handle a `describe' form. @@ -1779,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 a5640da6aa..b25afae135 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 @@ -70,6 +70,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) @@ -1699,11 +1700,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))) @@ -1874,8 +1871,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)