Skip to content

Commit add32f8

Browse files
committed
Collect stacktraces for errors in matchers
Fake the last frame to show the matchers name.
1 parent 0444816 commit add32f8

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

buttercup.el

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2143,9 +2143,51 @@ ARGS according to `debugger'."
21432143
(eq 'let (cadr frame))
21442144
(equal '((buttercup--stackframe-marker 1)) (car (cddr frame)))
21452145
)
2146-
;; TODO: What about an error in a matcher?
21472146
;; TODO: What about :to-throw?
2147+
;; buttercup--update-with-funcall (spec ...
2148+
;; apply buttercup--funcall
2149+
;; buttercup--funcall -- sets the debugger
2150+
;; apply FUNCTION
2151+
;; FUNCTION -- spec body function
2152+
;; condition-case -- from buttercup-with-converted-ert-signals
2153+
;; (let ((buttercup--stackframe-marker 1))
2154+
;; (buttercup-expect
2155+
;; (buttercup--apply-matcher
2156+
;; (apply to-throw-matcher
2157+
;; (to-throw-matcher
2158+
;; We need a new debugger here, the
2159+
;; condition-case can not be used to collect
2160+
;; backtrace.
2161+
;; When the error happens in the matcher function
2162+
;; (buttercup-expect
2163+
;; (buttercup--apply-matcher
2164+
;; (apply some-kind-of-function
2165+
;; (matcher
2166+
;; ACTUAL CODE
2167+
(and (eq 'buttercup--apply-matcher (cadr frame))
2168+
;; The two preceeding frames are not of user interest
2169+
(pop frame-list) (pop frame-list)
2170+
;; Add a fake frame for the matcher function
2171+
(push (cons t
2172+
(cons (car (cddr frame))
2173+
(mapcar (lambda (x)
2174+
(if (buttercup--wrapper-fun-p x)
2175+
(buttercup--enclosed-expr x)
2176+
x))
2177+
(cadr (cddr frame)))))
2178+
frame-list))
21482179
;; TODO: What about signals in before and after blocks?
2180+
;; BEFORE-EACH:
2181+
;; buttercup--run-suite
2182+
;; (let* ...
2183+
;; (dolist (f (buttercup-suite-before-all ...
2184+
;; (buttercup--update-with-funcall suite f
2185+
;; (apply buttercup--funcall
2186+
;; (buttercup-funcall f
2187+
;; (f)
2188+
;; Currently, buttercup silently ignores error in
2189+
;; (before|after)-(all|each). As long as that is the case,
2190+
;; there is nothing we can do about stacktraces.
21492191
)
21502192
(cl-return frame-list))
21512193
(push frame frame-list)))

tests/test-buttercup.el

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,6 +2028,28 @@ before it's processed by other functions."
20282028
(mapcar #'buttercup-spec-failure-stack
20292029
(buttercup-suite-children (car test-suites)))))
20302030
(expect (buttercup-output) :to-equal "")))
2031+
(describe "should be collected for errors in"
2032+
(it "matchers"
2033+
(put :--failing-matcher 'buttercup-matcher
2034+
(lambda (&rest _) (/ 1 0)))
2035+
(with-local-buttercup
2036+
:reporter #'backtrace-reporter
2037+
(describe "One suite with"
2038+
(it "a bad matcher"
2039+
(expect 1 :--failing-matcher 1)))
2040+
(buttercup-run :no-error))
2041+
(put :--failing-matcher 'buttercup-matcher nil)
2042+
(expect (buttercup-output) :to-equal
2043+
(concat
2044+
(make-string 40 ?=) "\n"
2045+
"One suite with a bad matcher\n"
2046+
"\n"
2047+
"Traceback (most recent call last):\n"
2048+
" :--failing-matcher(1 1)\n"
2049+
" /(1 0)\n"
2050+
"error: (arith-error)\n\n"
2051+
)))
2052+
)
20312053
(describe "with style"
20322054
:var (test-suites long-string)
20332055
;; Set up tests to test

0 commit comments

Comments
 (0)