diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 925b7f0..9eb4782 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,13 +46,14 @@ jobs: - 28.1 - 28.2 - 29.1 + - 29.2 - snapshot steps: - uses: purcell/setup-emacs@master with: version: ${{ matrix.emacs_version }} - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Run tests run: make check diff --git a/.gitignore b/.gitignore index 17d5c56..9c10b91 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ *.elc /dist + +# ELPA-generated files +/buttercup-autoloads.el +/buttercup-pkg.el diff --git a/buttercup-compat.el b/buttercup-compat.el index 56dbc79..40ec254 100644 --- a/buttercup-compat.el +++ b/buttercup-compat.el @@ -1,4 +1,4 @@ -;;; buttercup-compat.el --- Compatibility definitions for buttercup -*-lexical-binding:nil-*- +;;; buttercup-compat.el --- Compatibility definitions for buttercup -*- lexical-binding: t; -*- ;; Copyright (C) 2015 Jorgen Schaefer ;; Copyright (C) 2015 Free Software Foundation, Inc. @@ -29,31 +29,7 @@ ;;; Code: -;;;;;;;;;;;;;;;;;;;;;; -;;; Introduced in 24.4 - -(when (not (fboundp 'define-error)) - (defun define-error (name message &optional parent) - "Define NAME as a new error signal. -MESSAGE is a string that will be output to the echo area if such an error -is signaled without being caught by a `condition-case'. -PARENT is either a signal or a list of signals from which it inherits. -Defaults to `error'." - (unless parent (setq parent 'error)) - (let ((conditions - (if (consp parent) - (apply #'append - (mapcar (lambda (parent) - (cons parent - (or (get parent 'error-conditions) - (error "Unknown signal `%s'" parent)))) - parent)) - (cons parent (get parent 'error-conditions))))) - (put name 'error-conditions - (delete-dups (copy-sequence (cons name conditions)))) - (when message (put name 'error-message message))))) - -;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;; ;;; Introduced in 25.1 (when (not (fboundp 'directory-files-recursively)) @@ -68,7 +44,7 @@ If INCLUDE-DIRECTORIES, also include directories that have matching names." ;; also be offered. We shall suppress them. (tramp-mode (and tramp-mode (file-remote-p dir)))) (dolist (file (sort (file-name-all-completions "" dir) - 'string<)) + #'string<)) (unless (member file '("./" "../")) (if (directory-name-p file) (let* ((leaf (substring file 0 (1- (length file)))) diff --git a/buttercup.el b/buttercup.el index ad1c0e9..a754627 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 -;; Copyright (C) 2018-2023 Ola Nilsson +;; Copyright (C) 2018-2024 Ola Nilsson ;; Version: 1.33 ;; Author: Jorgen Schaefer @@ -64,9 +64,16 @@ "Bad test expression" 'buttercup-internals-error) +(eval-and-compile + (when (fboundp 'oclosure-define) ;Emacs≥29 + (oclosure-define (buttercup--thunk (:predicate buttercup--thunk-p)) + "An elisp expression as a function and original code." + expr))) + (defun buttercup--enclosed-expr (fun) - "Given a zero-arg function FUN, return its unevaluated expression. + "Given a FUN `buttercup-thunk', return its unevaluated expression. +For Emacs < 29: The function MUST be byte-compiled or have one of the following forms: @@ -77,6 +84,9 @@ and the return value will be EXPR, unevaluated. The quoted EXPR is useful if EXPR is a macro call, in which case the `quote' ensures access to the un-expanded form." (cl-assert (functionp fun) t "Expected FUN to be a function") + (if (and (fboundp 'buttercup--thunk-p) ;Emacs≥29 + (buttercup--thunk-p fun)) + (buttercup--thunk--expr fun) (pcase fun ;; This should be the normal case, a closure with unknown enclosed ;; variables, empty arglist and a body containing @@ -95,15 +105,15 @@ ensures access to the un-expanded form." (`(lambda nil (quote ,expr) (buttercup--mark-stackframe) ,_expanded) expr) - ;;; This is when FUN has been byte compiled, as when the entire - ;;; test file has been byte compiled. Check that it has an empty - ;;; arglist, that is all that is possible at this point. The - ;;; return value is byte compiled code, not the original - ;;; expressions. Also what is possible at this point. + ;; This is when FUN has been byte compiled, as when the entire + ;; test file has been byte compiled. Check that it has an empty + ;; arglist, that is all that is possible at this point. The + ;; return value is byte compiled code, not the original + ;; expressions. Also what is possible at this point. ((and (pred byte-code-function-p) (guard (member (aref fun 0) '(nil 0)))) (aref fun 1)) ;; Error - (_ (signal 'buttercup-enclosed-expression-error (format "Not a zero-arg one-expression closure: %S" fun))))) + (_ (signal 'buttercup-enclosed-expression-error (format "Not a zero-arg one-expression closure: %S" fun)))))) (defun buttercup--expr-and-value (fun) "Given a function, return its quoted expression and value. @@ -171,11 +181,15 @@ Does not have the IGNORE-MISSING and SPLIT parameters." (define-error 'buttercup-pending "Buttercup test is pending" 'buttercup-error-base) (defun buttercup--wrap-expr (expr) - "Wrap EXPR to be used by `buttercup-expect'." - `(lambda () - (quote ,expr) - (buttercup--mark-stackframe) - ,expr)) + "Wrap EXPR in a `buttercup--thunk' to be used by `buttercup-expect'." + (if (fboundp 'oclosure-lambda) ;Emacs≥29 + `(oclosure-lambda (buttercup--thunk (expr ',expr)) () + (buttercup--mark-stackframe) + ,expr) + `(lambda () + (quote ,expr) + (buttercup--mark-stackframe) + ,expr))) (defmacro expect (arg &optional matcher &rest args) "Expect a condition to be true. @@ -729,7 +743,7 @@ UNEVALUATED-EXPR if it did not raise any signal." (setq spy (funcall spy)) (cl-assert (symbolp spy)) (setq args (mapcar #'funcall args)) - (let* ((calls (mapcar 'spy-context-args (spy-calls-all spy)))) + (let* ((calls (mapcar #'spy-context-args (spy-calls-all spy)))) (cond ((not calls) (cons nil @@ -809,8 +823,10 @@ Return CHILD." (cons (buttercup-suite-or-spec-parent suite-or-spec) (buttercup-suite-or-spec-parents (buttercup-suite-or-spec-parent suite-or-spec))))) -(define-obsolete-function-alias 'buttercup-suite-parents 'buttercup-suite-or-spec-parents "emacs-buttercup 1.10") -(define-obsolete-function-alias 'buttercup-spec-parents 'buttercup-suite-or-spec-parents "emacs-buttercup 1.10") +(define-obsolete-function-alias 'buttercup-suite-parents + #'buttercup-suite-or-spec-parents "emacs-buttercup 1.10") +(define-obsolete-function-alias 'buttercup-spec-parents + #'buttercup-suite-or-spec-parents "emacs-buttercup 1.10") (defun buttercup-suites-total-specs-defined (suite-list) "Return the number of specs defined in all suites in SUITE-LIST." @@ -1370,11 +1386,11 @@ in a `buttercup-with-cleanup' environment.") (defun spy-calls-count-returned (spy) "Return the number of times SPY has been called successfully so far." - (cl-count-if 'spy-context-return-p (spy-calls-all spy))) + (cl-count-if #'spy-context-return-p (spy-calls-all spy))) (defun spy-calls-count-errors (spy) "Return the number of times SPY has been called and thrown errors so far." - (cl-count-if 'spy-context-thrown-p (spy-calls-all spy))) + (cl-count-if #'spy-context-thrown-p (spy-calls-all spy))) (defun spy-calls-args-for (spy index) "Return the context of the INDEXth call to SPY." @@ -1386,7 +1402,7 @@ in a `buttercup-with-cleanup' environment.") (defun spy-calls-all-args (spy) "Return the arguments for every recorded call to SPY." - (mapcar 'spy-context-args (spy-calls-all spy))) + (mapcar #'spy-context-args (spy-calls-all spy))) (defun spy-calls-most-recent (spy) "Return the context of the most recent call to SPY." @@ -1721,7 +1737,7 @@ Do not change the global value.") "Update SUITE-OR-SPEC with the result of calling FUNCTION with ARGS. Sets the `status', `failure-description', and `failure-stack' for failed and pending specs." - (let* ((result (apply 'buttercup--funcall function args)) + (let* ((result (apply #'buttercup--funcall function args)) (status (elt result 0)) (description (elt result 1)) (stack (elt result 2))) @@ -1955,7 +1971,7 @@ Colorize parts of the output if COLOR is non-nil." FMT and ARGS are passed to `format'." (send-string-to-terminal (apply #'format fmt args))) -(defun buttercup--display-warning (fn type message &optional level buffer-name) +(defun buttercup--display-warning (fn type message &optional level buffer-name &rest args) "Log all warnings to a special buffer while running buttercup specs. Emacs' normal display logic for warnings doesn't mix well with @@ -1975,8 +1991,8 @@ finishes." (cl-letf ((warning-minimum-level :emergency) ((symbol-function 'message) 'ignore)) - (funcall fn type message level buffer-name)) - (funcall fn type message level buffer-name))) + (apply fn type message level buffer-name args)) + (apply fn type message level buffer-name args))) (advice-add 'display-warning :around #'buttercup--display-warning) @@ -2028,7 +2044,7 @@ EVENT and ARG are described in `buttercup-reporter'." (with-current-buffer buf (let ((inhibit-read-only t)) (goto-char (point-max)) - (insert (apply 'format fmt args)))))) + (insert (apply #'format fmt args)))))) (unwind-protect (let ((buttercup-color)) (buttercup-reporter-batch event arg)) @@ -2072,7 +2088,7 @@ ARGS according to `debugger'." (unless (eq signal-type 'buttercup-pending) (buttercup--backtrace)))))) -(defalias 'buttercup--mark-stackframe 'ignore +(defalias 'buttercup--mark-stackframe #'ignore "Marker to find where the backtrace start.") (defun buttercup--backtrace () diff --git a/docs/writing-tests.md b/docs/writing-tests.md index 083f5fb..d940985 100644 --- a/docs/writing-tests.md +++ b/docs/writing-tests.md @@ -369,6 +369,21 @@ pending in results. (it "can be declared with `it' but without a body")) ``` +## Conditionally Skipping Specs + +Use the `assume` macro to conditionally skip a spec. + +```Emacs-Lisp +(describe "Conditionally skip specs" + (it "with the `assume' macro" + (assume (fboundp 'new-function) "`new-function' not availeble") + (expect (new-function)))) +``` + +If the first argument to `assume` evals to nil, the spec will be +marked as pending, and the second arg `message` will be added to the +output. + ## Spies Buttercup has test double functions called spies. While other diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el index d36634d..976ed7b 100644 --- a/tests/test-buttercup.el +++ b/tests/test-buttercup.el @@ -140,13 +140,24 @@ text properties using `ansi-color-apply'." ;; print remaining text (insert-owrt string)))))) +(defun buttercup--wrap-expr-and-eval (expr) + "Return the result of `eval'ing a wrapped EXPR. +When `buttercup--wrap-expr' uses `buttercup-thunk' oclosures, it +actually returns a form that has to be `eval'ed to get a +`buttercup-thunk'. This is not an issue when +`buttercup--wrap-expr' is used in the `expect' macro, because the +expansion of `expect' will be read/eval:ed anyway. But in the +tests the return will sometimes have to be explicitly evaled +before it's processed by other functions." + (eval (buttercup--wrap-expr expr) t)) + ;;;;;;;;;; ;;; helpers (describe "The buttercup--enclosed-expr function" (describe "should handle" (it "expressions wrapped by buttercup--wrap-expr" - (expect (buttercup--enclosed-expr (buttercup--wrap-expr '(ignore))) + (expect (buttercup--enclosed-expr (buttercup--wrap-expr-and-eval '(ignore))) :to-equal '(ignore))) (it "a closure with expression copy?" (expect (buttercup--enclosed-expr @@ -164,6 +175,7 @@ text properties using `ansi-color-apply'." (expect (buttercup--enclosed-expr (byte-compile-sexp '(lambda () '(ignore) (buttercup--mark-stackframe) (ignore)))))) (it "wrapped expression" + (assume (not (fboundp 'buttercup--thunk-p)) "Not with Oclosures") (expect (buttercup--enclosed-expr (byte-compile-sexp (buttercup--wrap-expr '(ignore)))))))) (describe "should error" (it "on a simple closure" @@ -223,45 +235,45 @@ text properties using `ansi-color-apply'." (let ((expansion (macroexpand '(expect (+ 1 1) :to-equal 2)))) (expect (length expansion) :to-equal 4) (expect (nth 0 expansion) :to-be 'buttercup-expect) - (expect (functionp (nth 1 expansion))) - (expect (buttercup--wrapper-fun-p (nth 1 expansion))) + (expect (functionp (eval (nth 1 expansion) t))) + (expect (buttercup--wrapper-fun-p (eval (nth 1 expansion) t))) (expect (nth 2 expansion) :to-be :to-equal) - (expect (functionp (nth 3 expansion))) - (expect (buttercup--wrapper-fun-p (nth 3 expansion))))) + (expect (functionp (eval (nth 3 expansion) t))) + (expect (buttercup--wrapper-fun-p (eval (nth 3 expansion) t))))) (it "with no matcher should use `:to-be-truthy' as the matcher" (let ((expansion (macroexpand '(expect (equal (+ 1 1) 2))))) (expect (length expansion) :to-equal 3) (expect (nth 0 expansion) :to-be 'buttercup-expect) - (expect (functionp (nth 1 expansion))) + (expect (functionp (eval (nth 1 expansion) t))) (expect (nth 2 expansion) :to-be :to-be-truthy)))) (describe "The `buttercup-expect' function" (describe "with a function as a matcher argument" (it "should not raise an error if the function returns true" (expect (buttercup-expect - (buttercup--wrap-expr t) + (buttercup--wrap-expr-and-eval t) #'eq - (buttercup--wrap-expr t)) + (buttercup--wrap-expr-and-eval t)) :not :to-throw 'buttercup-failed)) (it "should raise an error if the function returns false" (expect (buttercup-expect - (buttercup--wrap-expr t) + (buttercup--wrap-expr-and-eval t) #'eq - (buttercup--wrap-expr nil)) + (buttercup--wrap-expr-and-eval nil)) :to-throw 'buttercup-failed))) (describe "with a matcher argument" (it "should not raise an error if the matcher returns true" - (expect (buttercup-expect (buttercup--wrap-expr (ignore)) #'always) + (expect (buttercup-expect (buttercup--wrap-expr-and-eval (ignore)) #'always) :not :to-throw 'buttercup-failed)) (it "should raise an error if the matcher returns false" - (expect (buttercup-expect (buttercup--wrap-expr t) #'ignore) + (expect (buttercup-expect (buttercup--wrap-expr-and-eval t) #'ignore) :to-throw 'buttercup-failed)))) @@ -298,7 +310,7 @@ text properties using `ansi-color-apply'." (describe "The `buttercup-define-matcher' macro" (it "should create a matcher usable by apply-matcher" (expect (buttercup--apply-matcher - :test-matcher (mapcar #'buttercup--wrap-expr '(1 2))) + :test-matcher (mapcar #'buttercup--wrap-expr-and-eval '(1 2))) :to-equal 3))) @@ -306,19 +318,19 @@ text properties using `ansi-color-apply'." (it "should work with functions" (expect (buttercup--apply-matcher #'+ - (mapcar #'buttercup--wrap-expr '(1 2))) + (mapcar #'buttercup--wrap-expr-and-eval '(1 2))) :to-equal 3)) (it "should work with matchers" (expect (buttercup--apply-matcher - :test-matcher (mapcar #'buttercup--wrap-expr '(1 2))) + :test-matcher (mapcar #'buttercup--wrap-expr-and-eval '(1 2))) :to-equal 3)) (it "should fail if the matcher is not defined" (expect (buttercup--apply-matcher - :not-defined (mapcar #'buttercup--wrap-expr '(1 2))) + :not-defined (mapcar #'buttercup--wrap-expr-and-eval '(1 2))) :to-throw))) ;;;;;;;;;;;;;;;;;;;;; @@ -349,12 +361,12 @@ text properties using `ansi-color-apply'." (setq matcher-function (buttercup--find-matcher-function :to-be-truthy))) (it "should match for a truthy expression" (expect (buttercup--apply-matcher :to-be-truthy - (mapcar #'buttercup--wrap-expr '((not nil)))) + (mapcar #'buttercup--wrap-expr-and-eval '((not nil)))) :to-equal '(t . "Expected `(not nil)' to be nil, but instead it was `t'."))) (it "should not match for an untruthy expression" (expect (buttercup--apply-matcher :to-be-truthy - (mapcar #'buttercup--wrap-expr '((ignore)))) + (mapcar #'buttercup--wrap-expr-and-eval '((ignore)))) :to-equal '(nil . "Expected `(ignore)' to be non-nil, but instead it was nil.")))) @@ -362,7 +374,7 @@ text properties using `ansi-color-apply'." (it "should match if the args are `eq'" (cl-destructuring-bind (status . msg) - (buttercup--apply-matcher :to-be (mapcar #'buttercup--wrap-expr '('a 'a))) + (buttercup--apply-matcher :to-be (mapcar #'buttercup--wrap-expr-and-eval '('a 'a))) (expect status) (expect msg :to-match (rx "Expected `" @@ -371,7 +383,7 @@ text properties using `ansi-color-apply'." (it "should not match if the args are not `eq'" (cl-destructuring-bind (status . msg) - (buttercup--apply-matcher :to-be (mapcar #'buttercup--wrap-expr '('a 'b))) + (buttercup--apply-matcher :to-be (mapcar #'buttercup--wrap-expr-and-eval '('a 'b))) (expect status :not :to-be-truthy) (expect msg :to-match (rx "Expected `" @@ -381,13 +393,13 @@ text properties using `ansi-color-apply'." ;; Assumes (get 'equal 'ert-explainer) => 'ert--explain-equal (before-each (spy-on 'ert--explain-equal :and-call-through)) (it "should match if the args are `equal'" - (let ((res (buttercup--apply-matcher :to-equal (mapcar #'buttercup--wrap-expr '(0.2 0.2))))) + (let ((res (buttercup--apply-matcher :to-equal (mapcar #'buttercup--wrap-expr-and-eval '(0.2 0.2))))) ;; Check before using :to-equal to verify the return value (expect 'ert--explain-equal :to-have-been-called-times 1) (expect res :to-equal '(t . "Expected `0.2' not to be `equal' to `0.2', but it was.")))) (it "should not match if the args are not `equal'" - (let ((res (buttercup--apply-matcher :to-equal (mapcar #'buttercup--wrap-expr '(0.2 1.0))))) + (let ((res (buttercup--apply-matcher :to-equal (mapcar #'buttercup--wrap-expr-and-eval '(0.2 1.0))))) ;; Check before using :to-equal to verify the return value (expect 'ert--explain-equal :to-have-been-called-times 1) (expect @@ -398,11 +410,11 @@ text properties using `ansi-color-apply'." (it "should invert the car of the nested matcher's return value" (expect (buttercup--apply-matcher - :not (mapcar #'buttercup--wrap-expr '(1 :to-equal 2))) + :not (mapcar #'buttercup--wrap-expr-and-eval '(1 :to-equal 2))) :to-equal (cl-destructuring-bind (res . msg) (buttercup--apply-matcher - :to-equal (mapcar #'buttercup--wrap-expr '(1 2))) + :to-equal (mapcar #'buttercup--wrap-expr-and-eval '(1 2))) (cons (not res) msg))))) (describe ":to-have-same-items-as" @@ -411,7 +423,7 @@ text properties using `ansi-color-apply'." (status . msg) (buttercup--apply-matcher :to-have-same-items-as - (mapcar #'buttercup--wrap-expr '('(1 1 2 3 4) '(4 2 1 3)))) + (mapcar #'buttercup--wrap-expr-and-eval '('(1 1 2 3 4) '(4 2 1 3)))) (expect status) (expect msg :to-match (rx "Expected `" @@ -422,7 +434,7 @@ text properties using `ansi-color-apply'." (status . msg) (buttercup--apply-matcher :to-have-same-items-as - (mapcar #'buttercup--wrap-expr '('(1 2 3 4) '(4 2 3)))) + (mapcar #'buttercup--wrap-expr-and-eval '('(1 2 3 4) '(4 2 3)))) (expect status :not :to-be-truthy) (expect msg :to-match (rx "Expected `" @@ -434,7 +446,7 @@ text properties using `ansi-color-apply'." (status . msg) (buttercup--apply-matcher :to-have-same-items-as - (mapcar #'buttercup--wrap-expr '('(1 2 3 4) '(4 1 2 3 5)))) + (mapcar #'buttercup--wrap-expr-and-eval '('(1 2 3 4) '(4 1 2 3 5)))) (expect status :not :to-be-truthy) (expect msg :to-match (rx "Expected `" @@ -446,7 +458,7 @@ text properties using `ansi-color-apply'." (status . msg) (buttercup--apply-matcher :to-have-same-items-as - (mapcar #'buttercup--wrap-expr '('(1 2 3 4) '(4 1 3 5)))) + (mapcar #'buttercup--wrap-expr-and-eval '('(1 2 3 4) '(4 1 3 5)))) (expect status :not :to-be-truthy) (expect msg :to-match (rx "Expected `" @@ -458,14 +470,14 @@ text properties using `ansi-color-apply'." (expect (buttercup--apply-matcher :to-match - (mapcar #'buttercup--wrap-expr '("some string" "."))) + (mapcar #'buttercup--wrap-expr-and-eval '("some string" "."))) :to-equal '(t . "Expected some string not to match the regexp \".\", but it matched the substring \"s\" from position 0 to 1."))) (it "should show regex mismatches" (expect (buttercup--apply-matcher :to-match - (mapcar #'buttercup--wrap-expr '("some string" "[0-9]+"))) + (mapcar #'buttercup--wrap-expr-and-eval '("some string" "[0-9]+"))) :to-equal '(nil . "Expected some string to match the regexp \"[0-9]+\", but instead it was \"some string\".")))) (describe ":to-be-in" @@ -474,7 +486,7 @@ text properties using `ansi-color-apply'." (status . msg) (buttercup--apply-matcher :to-be-in - (mapcar #'buttercup--wrap-expr '('a '(b a c)))) + (mapcar #'buttercup--wrap-expr-and-eval '('a '(b a c)))) (expect status) (expect msg :to-match (rx "Expected `" @@ -485,7 +497,7 @@ text properties using `ansi-color-apply'." (status . msg) (buttercup--apply-matcher :to-be-in - (mapcar #'buttercup--wrap-expr '( ''a '(b d c)))) + (mapcar #'buttercup--wrap-expr-and-eval '( ''a '(b d c)))) (expect status :not :to-be-truthy) (expect msg :to-match (rx "Expected `" @@ -501,7 +513,7 @@ text properties using `ansi-color-apply'." (status . msg) (buttercup--apply-matcher :to-contain - (mapcar #'buttercup--wrap-expr '('(b a c) 'a))) + (mapcar #'buttercup--wrap-expr-and-eval '('(b a c) 'a))) (expect status) (expect msg :to-match "Expected `\\('(b a c)\\|(quote (b a c))\\)' to be a list not containing `a', but instead it was `(b a c)'."))) (it "should not match when the second argument is not a member of the first argument" @@ -509,72 +521,72 @@ text properties using `ansi-color-apply'." (status . msg) (buttercup--apply-matcher :to-contain - (mapcar #'buttercup--wrap-expr '('(b d c) 'a))) + (mapcar #'buttercup--wrap-expr-and-eval '('(b d c) 'a))) (expect status :not :to-be-truthy) (expect msg :to-match "Expected `\\('(b d c)\\|(quote (b d c))\\)' to be a list containing `a', but instead it was `(b d c)'.")))) (describe ":to-be-less-than" (it "should match when the first argument is less than the second argument" (expect (buttercup--apply-matcher :to-be-less-than - (mapcar #'buttercup--wrap-expr '(1 2))) + (mapcar #'buttercup--wrap-expr-and-eval '(1 2))) :to-equal '(t . "Expected `1' >= 2, but `1' was 1."))) (it "should not match when the first argument is equal to the second argument" (expect (buttercup--apply-matcher :to-be-less-than - (mapcar #'buttercup--wrap-expr '(2 2))) + (mapcar #'buttercup--wrap-expr-and-eval '(2 2))) :to-equal '(nil . "Expected `2' < 2, but `2' was 2."))) (it "should not match when the first argument is greater than the second argument" (expect (buttercup--apply-matcher :to-be-less-than - (mapcar #'buttercup--wrap-expr '(3 2))) + (mapcar #'buttercup--wrap-expr-and-eval '(3 2))) :to-equal '(nil . "Expected `3' < 2, but `3' was 3.")))) (describe ":to-be-greater-than" (it "should match when the first argument is greater than the second argument" (expect (buttercup--apply-matcher :to-be-greater-than - (mapcar #'buttercup--wrap-expr '(2 1))) + (mapcar #'buttercup--wrap-expr-and-eval '(2 1))) :to-equal '(t . "Expected `2' <= 1, but `2' was 2."))) (it "should not match when the first argument is equal to the second argument" (expect (buttercup--apply-matcher :to-be-greater-than - (mapcar #'buttercup--wrap-expr '(2 2))) + (mapcar #'buttercup--wrap-expr-and-eval '(2 2))) :to-equal '(nil . "Expected `2' > 2, but `2' was 2."))) (it "should not match when the first argument is greater than the second argument" (expect (buttercup--apply-matcher :to-be-greater-than - (mapcar #'buttercup--wrap-expr '(2 3))) + (mapcar #'buttercup--wrap-expr-and-eval '(2 3))) :to-equal '(nil . "Expected `2' > 3, but `2' was 2.")))) (describe ":to-be-weakly-less-than" (it "should match when the first argument is less than the second argument" (expect (buttercup--apply-matcher :to-be-weakly-less-than - (mapcar #'buttercup--wrap-expr '(1 2))) + (mapcar #'buttercup--wrap-expr-and-eval '(1 2))) :to-equal '(t . "Expected `1' > 2, but `1' was 1."))) (it "should match when the first argument is equal to the second argument" (expect (buttercup--apply-matcher :to-be-weakly-less-than - (mapcar #'buttercup--wrap-expr '(2 2))) + (mapcar #'buttercup--wrap-expr-and-eval '(2 2))) :to-equal '(t . "Expected `2' > 2, but `2' was 2."))) (it "should not match when the first argument is greater than the second argument" (expect (buttercup--apply-matcher :to-be-weakly-less-than - (mapcar #'buttercup--wrap-expr '(3 2))) + (mapcar #'buttercup--wrap-expr-and-eval '(3 2))) :to-equal '(nil . "Expected `3' <= 2, but `3' was 3.")))) (describe ":to-be-weakly-greater-than" (it "should match when the first argument is greater than the second argument" (expect (buttercup--apply-matcher :to-be-weakly-greater-than - (mapcar #'buttercup--wrap-expr '(2 1))) + (mapcar #'buttercup--wrap-expr-and-eval '(2 1))) :to-equal '(t . "Expected `2' < 1, but `2' was 2."))) (it "should match when the first argument is equal to the second argument" (expect (buttercup--apply-matcher :to-be-weakly-greater-than - (mapcar #'buttercup--wrap-expr '(2 2))) + (mapcar #'buttercup--wrap-expr-and-eval '(2 2))) :to-equal '(t . "Expected `2' < 2, but `2' was 2."))) (it "should not match when the first argument is greater than the second argument" (expect (buttercup--apply-matcher :to-be-weakly-greater-than - (mapcar #'buttercup--wrap-expr '(2 3))) + (mapcar #'buttercup--wrap-expr-and-eval '(2 3))) :to-equal '(nil . "Expected `2' >= 3, but `2' was 2.")))) (describe ":to-be-close-to" @@ -582,7 +594,7 @@ text properties using `ansi-color-apply'." (cl-destructuring-bind (status . msg) (buttercup--apply-matcher :to-be-close-to - (mapcar #'buttercup--wrap-expr '(0.01 0.011 2))) + (mapcar #'buttercup--wrap-expr-and-eval '(0.01 0.011 2))) (expect status) (expect msg :to-match @@ -591,7 +603,7 @@ text properties using `ansi-color-apply'." (cl-destructuring-bind (status . msg) (buttercup--apply-matcher :to-be-close-to - (mapcar #'buttercup--wrap-expr '(0.01 0.011 4))) + (mapcar #'buttercup--wrap-expr-and-eval '(0.01 0.011 4))) (expect status :not :to-be-truthy) (expect msg :to-match @@ -651,13 +663,13 @@ text properties using `ansi-color-apply'." ;; since this test does not need to signal an error, it can apply the full matcher (expect (buttercup--apply-matcher :to-throw - (mapcar #'buttercup--wrap-expr '((identity t)))) + (mapcar #'buttercup--wrap-expr-and-eval '((identity t)))) :to-equal '(nil . "Expected `(identity t)' to throw a signal, but instead it returned `t'"))) (it "and mention any specified signal" (expect (buttercup--apply-matcher :to-throw - (mapcar #'buttercup--wrap-expr '((identity t) 'arith-error))) + (mapcar #'buttercup--wrap-expr-and-eval '((identity t) 'arith-error))) :to-equal '(nil . "Expected `(identity t)' to throw a child signal of `arith-error', but instead it returned `t'"))) ) @@ -669,20 +681,20 @@ text properties using `ansi-color-apply'." (it "should not match if the spy has not been called" (expect (buttercup--apply-matcher :to-have-been-called - (mapcar #'buttercup--wrap-expr '('i-spy-with-my-little-eye))) + (mapcar #'buttercup--wrap-expr-and-eval '('i-spy-with-my-little-eye))) :not :to-be-truthy)) (it "should match if the spy has been called once" (i-spy-with-my-little-eye) (expect (buttercup--apply-matcher :to-have-been-called - (mapcar #'buttercup--wrap-expr '('i-spy-with-my-little-eye))) + (mapcar #'buttercup--wrap-expr-and-eval '('i-spy-with-my-little-eye))) :to-be-truthy)) (it "should match if the spy has been called multiple times" (dotimes (x 1000) (i-spy-with-my-little-eye)) (expect (buttercup--apply-matcher :to-have-been-called - (mapcar #'buttercup--wrap-expr '('i-spy-with-my-little-eye))) + (mapcar #'buttercup--wrap-expr-and-eval '('i-spy-with-my-little-eye))) :to-be-truthy)) ) (describe ":to-have-been-called-with" @@ -692,7 +704,7 @@ text properties using `ansi-color-apply'." (expect (buttercup--apply-matcher :to-have-been-called-with - (mapcar #'buttercup--wrap-expr '('i-spy-with-my-little-eye 123))) + (mapcar #'buttercup--wrap-expr-and-eval '('i-spy-with-my-little-eye 123))) :to-equal '(nil . @@ -708,7 +720,7 @@ text properties using `ansi-color-apply'." (expect (buttercup--apply-matcher :to-have-been-called-with - (mapcar #'buttercup--wrap-expr '('i-spy-with-my-little-eye 234))) + (mapcar #'buttercup--wrap-expr-and-eval '('i-spy-with-my-little-eye 234))) :to-equal '(nil . @@ -724,7 +736,7 @@ text properties using `ansi-color-apply'." (i-spy-with-my-little-eye 'KLM) (expect (buttercup--apply-matcher :to-have-been-called-with - (mapcar #'buttercup--wrap-expr '('i-spy-with-my-little-eye 789 789))) + (mapcar #'buttercup--wrap-expr-and-eval '('i-spy-with-my-little-eye 789 789))) :to-equal t)) (it "should match if the spy has been called multiple times with the specified arguments" (dotimes (x 10) @@ -732,7 +744,7 @@ text properties using `ansi-color-apply'." (i-spy-with-my-little-eye 456)) (expect (buttercup--apply-matcher :to-have-been-called-with - (mapcar #'buttercup--wrap-expr '('i-spy-with-my-little-eye 456))) + (mapcar #'buttercup--wrap-expr-and-eval '('i-spy-with-my-little-eye 456))) :to-be-truthy)) ) (describe ":to-have-been-called-times" @@ -742,7 +754,7 @@ text properties using `ansi-color-apply'." (i-spy-with-my-little-eye) (expect (buttercup--apply-matcher :to-have-been-called-times - (mapcar #'buttercup--wrap-expr '('i-spy-with-my-little-eye 2))) + (mapcar #'buttercup--wrap-expr-and-eval '('i-spy-with-my-little-eye 2))) :to-equal '(nil . "Expected `i-spy-with-my-little-eye' to have been called 2 times, but it was called 1 time"))) (it "should not match if the spy has been called more times" @@ -750,7 +762,7 @@ text properties using `ansi-color-apply'." (i-spy-with-my-little-eye)) (expect (buttercup--apply-matcher :to-have-been-called-times - (mapcar #'buttercup--wrap-expr '('i-spy-with-my-little-eye 4))) + (mapcar #'buttercup--wrap-expr-and-eval '('i-spy-with-my-little-eye 4))) :to-equal '(nil . "Expected `i-spy-with-my-little-eye' to have been called 4 times, but it was called 6 times"))) (it "should match if the spy has been called the correct number of times" @@ -758,13 +770,13 @@ text properties using `ansi-color-apply'." (i-spy-with-my-little-eye)) (expect (buttercup--apply-matcher :to-have-been-called-times - (mapcar #'buttercup--wrap-expr '('i-spy-with-my-little-eye 6))) + (mapcar #'buttercup--wrap-expr-and-eval '('i-spy-with-my-little-eye 6))) :to-equal '(t . "Expected `i-spy-with-my-little-eye' to not have been called exactly 6 times, but it was."))) (it "should match if the spy has been called 0 times" (expect (buttercup--apply-matcher :to-have-been-called-times - (mapcar #'buttercup--wrap-expr '('i-spy-with-my-little-eye 0))) + (mapcar #'buttercup--wrap-expr-and-eval '('i-spy-with-my-little-eye 0))) :to-equal '(t . "Expected `i-spy-with-my-little-eye' to not have been called exactly 0 times, but it was."))))) @@ -1386,7 +1398,7 @@ text properties using `ansi-color-apply'." (it "returns false if the spy was not called" (expect (buttercup--apply-matcher :to-have-been-called - (list (buttercup--wrap-expr ''test-function))) + (list (buttercup--wrap-expr-and-eval ''test-function))) :to-be nil)) @@ -1394,7 +1406,7 @@ text properties using `ansi-color-apply'." (test-function 1 2 3) (expect (buttercup--apply-matcher :to-have-been-called - (list (buttercup--wrap-expr ''test-function))) + (list (buttercup--wrap-expr-and-eval ''test-function))) :to-be t))) @@ -1405,7 +1417,7 @@ text properties using `ansi-color-apply'." (it "returns false if the spy was not called at all" (expect (buttercup--apply-matcher :to-have-been-called-with - (mapcar #'buttercup--wrap-expr '('test-function '1 '2 '3))) + (mapcar #'buttercup--wrap-expr-and-eval '('test-function '1 '2 '3))) :to-equal (cons nil "Expected `test-function' to have been called with (1 2 3), but it was not called at all"))) @@ -1414,7 +1426,7 @@ text properties using `ansi-color-apply'." (test-function 3 2 1) (expect (buttercup--apply-matcher :to-have-been-called-with - (mapcar #'buttercup--wrap-expr '('test-function 1 2 3))) + (mapcar #'buttercup--wrap-expr-and-eval '('test-function 1 2 3))) :to-equal (cons nil "Expected `test-function' to have been called with (1 2 3), but it was called with (3 2 1)"))) @@ -1423,7 +1435,7 @@ text properties using `ansi-color-apply'." (test-function 1 2 3) (expect (buttercup--apply-matcher :to-have-been-called-with - (mapcar #'buttercup--wrap-expr '('test-function 1 2 3))) + (mapcar #'buttercup--wrap-expr-and-eval '('test-function 1 2 3))) :to-be t))) @@ -1434,7 +1446,7 @@ text properties using `ansi-color-apply'." (it "returns error if the spy was called less than expected" (expect (buttercup--apply-matcher :to-have-been-called-times - (mapcar #'buttercup--wrap-expr '('test-function 1))) + (mapcar #'buttercup--wrap-expr-and-eval '('test-function 1))) :to-equal (cons nil "Expected `test-function' to have been called 1 time, but it was called 0 times"))) @@ -1444,7 +1456,7 @@ text properties using `ansi-color-apply'." (test-function) (expect (buttercup--apply-matcher :to-have-been-called-times - (mapcar #'buttercup--wrap-expr '('test-function 1))) + (mapcar #'buttercup--wrap-expr-and-eval '('test-function 1))) :to-equal (cons nil "Expected `test-function' to have been called 1 time, but it was called 2 times"))) @@ -1454,7 +1466,7 @@ text properties using `ansi-color-apply'." (test-function) (expect (buttercup--apply-matcher :to-have-been-called-times - (mapcar #'buttercup--wrap-expr '('test-function 2))) + (mapcar #'buttercup--wrap-expr-and-eval '('test-function 2))) :to-equal (cons t "Expected `test-function' to not have been called exactly 2 times, but it was."))) @@ -1463,7 +1475,7 @@ text properties using `ansi-color-apply'." (test-function) (expect (buttercup--apply-matcher :to-have-been-called-times - (mapcar #'buttercup--wrap-expr '('test-function 3))) + (mapcar #'buttercup--wrap-expr-and-eval '('test-function 3))) :to-equal (cons nil "Expected `test-function' to have been called 3 times, but it was called 2 times"))) @@ -1471,7 +1483,7 @@ text properties using `ansi-color-apply'." (it "use singular expected word in error message" (expect (buttercup--apply-matcher :to-have-been-called-times - (mapcar #'buttercup--wrap-expr '('test-function 1))) + (mapcar #'buttercup--wrap-expr-and-eval '('test-function 1))) :to-equal (cons nil "Expected `test-function' to have been called 1 time, but it was called 0 times"))) @@ -1480,7 +1492,7 @@ text properties using `ansi-color-apply'." (test-function) (expect (buttercup--apply-matcher :to-have-been-called-times - (mapcar #'buttercup--wrap-expr '('test-function 2))) + (mapcar #'buttercup--wrap-expr-and-eval '('test-function 2))) :to-equal (cons nil "Expected `test-function' to have been called 2 times, but it was called 1 time")))) @@ -1584,7 +1596,7 @@ text properties using `ansi-color-apply'." (expect (test-function-throws-on-negative -5) :to-throw) (expect (buttercup--apply-matcher :to-have-been-called - (list (buttercup--wrap-expr ''test-function-throws-on-negative))) + (list (buttercup--wrap-expr-and-eval ''test-function-throws-on-negative))) :to-be t)) @@ -1593,7 +1605,7 @@ text properties using `ansi-color-apply'." (expect (test-function-throws-on-negative -5) :to-throw) (expect (buttercup--apply-matcher :to-have-been-called-times - (mapcar #'buttercup--wrap-expr '('test-function-throws-on-negative 2))) + (mapcar #'buttercup--wrap-expr-and-eval '('test-function-throws-on-negative 2))) :to-equal '(t . "Expected `test-function-throws-on-negative' to not have been called exactly 2 times, but it was."))) @@ -1602,12 +1614,12 @@ text properties using `ansi-color-apply'." (expect (test-function-throws-on-negative -5) :to-throw) (expect (buttercup--apply-matcher :to-have-been-called-with - (mapcar #'buttercup--wrap-expr '('test-function-throws-on-negative 5))) + (mapcar #'buttercup--wrap-expr-and-eval '('test-function-throws-on-negative 5))) :to-be t) (expect (buttercup--apply-matcher :to-have-been-called-with - (mapcar #'buttercup--wrap-expr '('test-function-throws-on-negative -5))) + (mapcar #'buttercup--wrap-expr-and-eval '('test-function-throws-on-negative -5))) :to-be t))