Skip to content

Commit

Permalink
Separate the :to-throw failure types to enable better messages
Browse files Browse the repository at this point in the history
Instead of using buttercup--test-expectation, unroll the various
cases.  This is prepatory work for using the explained difference for
arguments.
  • Loading branch information
snogge committed Oct 18, 2023
1 parent f967fdf commit 26c090b
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -692,20 +692,30 @@ UNEVALUATED-EXPR if it did not raise any signal."
"a signal")
?a (if expected-signal-args
(format " with args `%S'" expected-signal-args)
""))))
(if (null thrown-signal)
;; Match is not possible unless a signal was raied
(cons nil (buttercup--simple-format spec "Expected `%E' to throw %s%a, but instead it returned `%e'"))
;; non-matching signal
(buttercup--test-expectation matched
:expect-match-phrase
(buttercup--simple-format
spec
"Expected `%E' to throw %s%a, but instead it threw `%S'%A")
:expect-mismatch-phrase
(buttercup--simple-format
spec
"Expected `%E' not to throw %s%a, but it threw `%S'%A"))))))
"")
?q (lambda () (format "%S" explained-signal-args))
)))
(cond
(matched ;; should be the most likely result
`(t . ,(buttercup--simple-format
spec "Expected `%E' not to throw %s%a, but it threw `%S'%A")))
((null thrown-signal) ; no signal raised
`(nil . ,(buttercup--simple-format
spec "Expected `%E' to throw %s%a, but instead it returned `%e'")))
((and explained-signal-args (not matching-signal-symbol)) ; neither symbol nor args matched
`(nil . ,(buttercup--simple-format
spec
"Expected `%E' to throw %s%a, but instead it threw `%S'%A")))
(explained-signal-args ; symbol matched
`(nil . ,(buttercup--simple-format
spec
"Expected `%E' to throw %s%a, but instead it threw `%S'%A")))
((not matching-signal-symbol) ; args matched
`(nil . ,(buttercup--simple-format
spec
"Expected `%E' to throw %s%a, but instead it threw `%S'%A")))
(t (error "`buttercup--handle-to-throw' could not handle args %S %S"
thrown-signal expected-signal))))))

(buttercup-define-matcher :to-have-been-called (spy)
(cl-assert (symbolp (funcall spy)))
Expand Down

0 comments on commit 26c090b

Please sign in to comment.