Skip to content

Commit

Permalink
Exclude signal args in :to-throw messages unless specified
Browse files Browse the repository at this point in the history
Unless the test should match signal arguments, exclude them from the
expect message.
  • Loading branch information
snogge committed Oct 5, 2023
1 parent 0a281ed commit 38467b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
9 changes: 6 additions & 3 deletions buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,10 @@ UNEVALUATED-EXPR if it did not raise any signal."
?e (lambda () (format "%S" expr-value))
?t (lambda () (format "%S" thrown-signal))
?S (lambda () (format "%S" thrown-signal-symbol))
?A (lambda () (format "%S" thrown-signal-args))
?A (lambda ()
(if expected-signal-args
(format " with args `%S'" thrown-signal-args)
""))
?s (if expected-signal-symbol
(format "a child signal of `%S'" expected-signal-symbol)
"a signal")
Expand All @@ -693,11 +696,11 @@ UNEVALUATED-EXPR if it did not raise any signal."
:expect-match-phrase
(buttercup--simple-format
spec
"Expected `%E' to throw %s%a, but instead it threw `%S' with args %A")
"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' with args %A"))))))
"Expected `%E' not to throw %s%a, but it threw `%S'%A"))))))

(buttercup-define-matcher :to-have-been-called (spy)
(cl-assert (symbolp (funcall spy)))
Expand Down
18 changes: 9 additions & 9 deletions tests/test-buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -603,49 +603,49 @@ text properties using `ansi-color-apply'."
(list 'overflow-error (concat "Foo" "bar"))
'(myfunc) nil)
:to-equal
'(t . "Expected `(myfunc)' not to throw a child signal of `overflow-error' with args `(\"Foobar\")', but it threw `overflow-error' with args (\"Foobar\")")))
'(t . "Expected `(myfunc)' not to throw a child signal of `overflow-error' with args `(\"Foobar\")', but it threw `overflow-error' with args `(\"Foobar\")'")))
(it "should match the error symbol without args"
(expect (buttercup--handle-to-throw '(overflow-error "Foobar")
'(overflow-error)
'(myfunc) nil)
:to-equal
'(t . "Expected `(myfunc)' not to throw a child signal of `overflow-error', but it threw `overflow-error' with args (\"Foobar\")")))
'(t . "Expected `(myfunc)' not to throw a child signal of `overflow-error', but it threw `overflow-error'")))
(it "should match the with no error signal specified"
(expect (buttercup--handle-to-throw '(overflow-error "Foobar")
'()
'(myfunc) nil)
:to-equal
'(t . "Expected `(myfunc)' not to throw a signal, but it threw `overflow-error' with args (\"Foobar\")")))
'(t . "Expected `(myfunc)' not to throw a signal, but it threw `overflow-error'")))
(it "should match a child signal"
(expect (buttercup--handle-to-throw '(overflow-error "Foobar")
'(arith-error)
'(myfunc) nil)
:to-equal
'(t . "Expected `(myfunc)' not to throw a child signal of `arith-error', but it threw `overflow-error' with args (\"Foobar\")")))
'(t . "Expected `(myfunc)' not to throw a child signal of `arith-error', but it threw `overflow-error'")))
(it "should match child signals and equal arguments"
(expect (buttercup--handle-to-throw '(overflow-error "Foobar")
`(arith-error ,(concat "Foo" "bar"))
'(myfunc) nil)
:to-equal
'(t . "Expected `(myfunc)' not to throw a child signal of `arith-error' with args `(\"Foobar\")', but it threw `overflow-error' with args (\"Foobar\")")))
'(t . "Expected `(myfunc)' not to throw a child signal of `arith-error' with args `(\"Foobar\")', but it threw `overflow-error' with args `(\"Foobar\")'")))
(it "should not match with different arguments"
(expect (buttercup--handle-to-throw '(overflow-error "Foobar")
(list 'overflow-error (concat "Foo" "bar" "baz"))
'(myfunc) nil)
:to-equal
'(nil . "Expected `(myfunc)' to throw a child signal of `overflow-error' with args `(\"Foobarbaz\")', but instead it threw `overflow-error' with args (\"Foobar\")")))
'(nil . "Expected `(myfunc)' to throw a child signal of `overflow-error' with args `(\"Foobarbaz\")', but instead it threw `overflow-error' with args `(\"Foobar\")'")))
(it "should not match an unrelated symbol"
(expect (buttercup--handle-to-throw '(void-variable "Foobar")
(list 'overflow-error (concat "Foo" "bar"))
'(myfunc) nil)
:to-equal
'(nil . "Expected `(myfunc)' to throw a child signal of `overflow-error' with args `(\"Foobar\")', but instead it threw `void-variable' with args (\"Foobar\")")))
'(nil . "Expected `(myfunc)' to throw a child signal of `overflow-error' with args `(\"Foobar\")', but instead it threw `void-variable' with args `(\"Foobar\")'")))
(it "should not match a parent signal"
(expect (buttercup--handle-to-throw '(arith-error "Foobar")
`(overflow-error )
`(overflow-error)
'(myfunc) nil)
:to-equal
'(nil . "Expected `(myfunc)' to throw a child signal of `overflow-error', but instead it threw `arith-error' with args (\"Foobar\")")))
'(nil . "Expected `(myfunc)' to throw a child signal of `overflow-error', but instead it threw `arith-error'")))
(describe "should not match when no signal is raised"
(it "and not mention unspecified signal"
;; since this test does not need to signal an error, it can apply the full matcher
Expand Down

0 comments on commit 38467b6

Please sign in to comment.