emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/buttercup 8dda6ef8c9 2/9: Refactor the expect macro


From: ELPA Syncer
Subject: [nongnu] elpa/buttercup 8dda6ef8c9 2/9: Refactor the expect macro
Date: Wed, 10 Aug 2022 18:58:13 -0400 (EDT)

branch: elpa/buttercup
commit 8dda6ef8c9e4f5f49a5c2b834ea83802b5ca5bf3
Author: Ola Nilsson <ola.nilsson@gmail.com>
Commit: Ola Nilsson <ola.nilsson@gmail.com>

    Refactor the expect macro
    
    Extract the wrapping of expressions into a separate function
    buttercup--wrap-expr.  This reduces code duplication.
---
 buttercup.el | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/buttercup.el b/buttercup.el
index f32647b788..418dd5ecae 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -123,6 +123,13 @@ a call to `save-match-data', as `format-spec' modifies 
that."
 
 (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))
+
 (defmacro expect (arg &optional matcher &rest args)
   "Expect a condition to be true.
 
@@ -137,19 +144,9 @@ This macro knows three forms:
 
 \(expect ARG)
   Fail the current test if ARG is not true."
-  (let ((wrapped-args
-         (mapcar (lambda (expr) `(lambda ()
-                                   (quote ,expr)
-                                   (buttercup--mark-stackframe)
-                                   ,expr))
-                 args)))
-    `(buttercup-expect
-      (lambda ()
-        (quote ,arg)
-        (buttercup--mark-stackframe)
-        ,arg)
-      ,(or matcher :to-be-truthy)
-      ,@wrapped-args)))
+  `(buttercup-expect ,(buttercup--wrap-expr arg)
+                     ,(or matcher :to-be-truthy)
+                     ,@(mapcar #'buttercup--wrap-expr args)))
 
 (defun buttercup-expect (arg &optional matcher &rest args)
   "The function for the `expect' macro.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]