Skip to content

Commit

Permalink
Collect stacktraces for errors in matchers
Browse files Browse the repository at this point in the history
Fake the last frame to show the matchers name.
  • Loading branch information
snogge committed Aug 26, 2024
1 parent f3f12da commit 2d54bd0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
44 changes: 43 additions & 1 deletion buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -2142,9 +2142,51 @@ ARGS according to `debugger'."
(eq 'let (cadr frame))
(equal '((buttercup--stackframe-marker 1)) (car (cddr frame)))
)
;; TODO: What about an error in a matcher?
;; TODO: What about :to-throw?
;; buttercup--update-with-funcall (spec ...
;; apply buttercup--funcall
;; buttercup--funcall -- sets the debugger
;; apply FUNCTION
;; FUNCTION -- spec body function
;; condition-case -- from buttercup-with-converted-ert-signals
;; (let ((buttercup--stackframe-marker 1))
;; (buttercup-expect
;; (buttercup--apply-matcher
;; (apply to-throw-matcher
;; (to-throw-matcher
;; We need a new debugger here, the
;; condition-case can not be used to collect
;; backtrace.
;; What about an error in a matcher?
;; (buttercup-expect
;; (buttercup--apply-matcher
;; (apply some-kind-of-function
;; (matcher
;; ACTUAL CODE
(and (eq 'buttercup--apply-matcher (cadr frame))
;; The two preceeding frames are not of user interest
(pop frame-list) (pop frame-list)
;; Add a fake frame for the matcher function
(push (cons t
(cons (car (cddr frame))
(mapcar (lambda (x)
(if (buttercup--wrapper-fun-p x)
(buttercup--enclosed-expr x)
x))
(cadr (cddr frame)))))
frame-list))
;; TODO: What about signals in before and after blocks?
;; BEFORE-EACH:
;; buttercup--run-suite
;; (let* ...
;; (dolist (f (buttercup-suite-before-all ...
;; (buttercup--update-with-funcall suite f
;; (apply buttercup--funcall
;; (buttercup-funcall f
;; (f)
;; Currently, buttercup silently ignores error in
;; (before|after)-(all|each). As long as that is the case,
;; there is nothing we can do about stacktraces.
)
(cl-return frame-list))
(push frame frame-list)))
Expand Down
22 changes: 22 additions & 0 deletions tests/test-buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,28 @@ before it's processed by other functions."
(mapcar #'buttercup-spec-failure-stack
(buttercup-suite-children (car test-suites)))))
(expect (buttercup-output) :to-equal "")))
(describe "should be collected for errors in"
(it "matchers"
(put :--failing-matcher 'buttercup-matcher
(lambda (&rest _) (/ 1 0)))
(with-local-buttercup
:reporter #'backtrace-reporter
(describe "One suite with"
(it "a bad matcher"
(expect 1 :--failing-matcher 1)))
(buttercup-run :no-error))
(put :--failing-matcher 'buttercup-matcher nil)
(expect (buttercup-output) :to-equal
(concat
(make-string 40 ?=) "\n"
"One suite with a bad matcher\n"
"\n"
"Traceback (most recent call last):\n"
" :--failing-matcher(1 1)\n"
" /(1 0)\n"
"error: (arith-error)\n\n"
)))
)
(describe "with style"
:var (test-suites long-string)
;; Set up tests to test
Expand Down

0 comments on commit 2d54bd0

Please sign in to comment.