Skip to content

Commit 8408579

Browse files
committed
Rewrite buttercup-expect with pcase
Replace the special case of (null matcher) with using the :to-be-truthy matcher. buttercup-expect is probably never called without a matcher as the expect macro will pass the :to-be-truthy matcher if none is given.
1 parent 925af15 commit 8408579

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

buttercup.el

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -220,24 +220,14 @@ the arguments is delayed until the containing spec is executed."
220220
See the macro documentation for details and the definition of
221221
ARG, MATCHER and ARGS."
222222
(cl-assert (cl-every #'buttercup--wrapper-fun-p (cons arg args)) t)
223-
(if (not matcher)
224-
(progn
225-
(cl-assert (not args) t)
226-
(when (not (funcall arg))
227-
(buttercup-fail "Expected %S to be non-nil"
228-
(buttercup--enclosed-expr arg))))
229-
(let ((result (buttercup--apply-matcher matcher (cons arg args))))
230-
(if (consp result)
231-
(when (not (car result))
232-
(buttercup-fail "%s" (cdr result)))
233-
(when (not result)
234-
(buttercup-fail "Expected %S %S %s"
235-
(buttercup--enclosed-expr arg)
236-
matcher
237-
(mapconcat (lambda (obj)
238-
(format "%S" (funcall obj)))
239-
args
240-
" ")))))))
223+
(pcase (buttercup--apply-matcher (or matcher :to-be-truthy) (cons arg args))
224+
(`(,result . ,message) (unless result (buttercup-fail message)))
225+
(result (unless result (buttercup-fail "Expected %S %S %s"
226+
(buttercup--enclosed-expr arg)
227+
matcher
228+
(mapconcat (lambda (obj)
229+
(format "%S" (funcall obj)))
230+
args " "))))))
241231

242232
(defun buttercup-fail (format &rest args)
243233
"Fail the current test with the given description.

0 commit comments

Comments
 (0)