Skip to content

Commit

Permalink
Do not collect backtraces for failed specs
Browse files Browse the repository at this point in the history
There is no reason to collect backtraces for expect form where the
matcher detects a mismatch.  It's all buttercup infrastructure at that
point.
  • Loading branch information
snogge committed Aug 22, 2024
1 parent cee5f80 commit 4e8db2c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
6 changes: 3 additions & 3 deletions buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -2107,8 +2107,9 @@ ARGS according to `debugger'."
;; args is (error (signal . data) ....) where the tail
;; may be empty
(cl-destructuring-bind (signal-type . data) (cl-second args)
(unless (eq signal-type 'buttercup-pending)
(buttercup--backtrace))))))
(cl-case signal-type
((buttercup-pending buttercup-failed))
(otherwise (buttercup--backtrace)))))))

(defalias 'buttercup--mark-stackframe #'ignore
"Marker to find where the backtrace start.")
Expand Down Expand Up @@ -2137,7 +2138,6 @@ ARGS according to `debugger'."
;; condition-case -- from buttercup-with-converted-ert-signals
;; progn -- the same
;; ACTUAL CODE
;; TODO: matchers that do not match should not collect backtrace
;; TODO: What about an error in a matcher?
;; TODO: What about :to-throw?
;; TODO: What about signals in before and after blocks?
Expand Down
42 changes: 26 additions & 16 deletions tests/test-buttercup.el
Original file line number Diff line number Diff line change
Expand Up @@ -1969,22 +1969,32 @@ before it's processed by other functions."
(fmakunbound 'bc-bt-foo)
(fmakunbound 'bc-bt-bar)
(fmakunbound 'bc-bt-baz))
(it "should be printed for each failed spec"
(with-local-buttercup
:reporter #'backtrace-reporter
(describe "suite"
(it "expect 2" (expect (+ 1 2) :to-equal 2))
(it "expect nil" (expect nil)))
(buttercup-run :noerror))
(expect (buttercup-output) :to-match
(rx string-start
(= 2 (seq (= 40 ?=) "\n"
"suite expect " (or "2" "nil") "\n"
"\n"
"Traceback (most recent call last):\n"
(* (seq " " (+ not-newline) "\n"))
(or "FAILED" "error") ": " (+ not-newline) "\n\n"))
string-end)))
(it "should not be collected or printed for failed specs"
(let (test-suites)
(spy-on 'buttercup--backtrace :and-call-through)
(with-local-buttercup
:reporter #'backtrace-reporter
(describe "suite"
(it "expect 2" (expect (+ 1 2) :to-equal 2))
(it "expect nil" (expect nil)))
(buttercup-run :noerror)
(setq test-suites buttercup-suites))
(expect 'buttercup--backtrace :not :to-have-been-called)
;; Checking both if buttercup--backtrace have been called and
;; the failure-stack value might be overkill
(cl-loop for spec in (buttercup-suite-children (car test-suites))
if (buttercup-spec-failure-stack spec)
collect (buttercup-spec-failure-stack spec) into stacks
finally (expect stacks :to-be nil))
(expect (buttercup-output) :to-match
(rx-let ((failure-report (name)
(seq (= 40 ?=) "\n"
"suite expect " name "\n"
"FAILED: " (+ not-newline) "\n\n")))
(rx string-start
(failure-report "2")
(failure-report "nil")
string-end)))))
(describe "with style"
:var (test-suites long-string)
;; Set up tests to test
Expand Down

0 comments on commit 4e8db2c

Please sign in to comment.