[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] scratch/el-mock 24337b85e8 28/64: Preserve ERT backtrace
From: |
Stefan Monnier |
Subject: |
[nongnu] scratch/el-mock 24337b85e8 28/64: Preserve ERT backtrace |
Date: |
Mon, 28 Aug 2023 23:01:40 -0400 (EDT) |
branch: scratch/el-mock
commit 24337b85e8a24ac7c620d988741cf2fc61211ba9
Author: Philipp Stephani <phst@google.com>
Commit: Philipp Stephani <phst@google.com>
Preserve ERT backtrace
Remove use of ‘condition-case’. This construct throws away the
backtrace, making debugging failing tests much harder. Use the existing
‘unwind-protect’ instead.
---
el-mock.el | 9 ++++-----
test/el-mock-test.el | 17 +++++++++++++++++
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/el-mock.el b/el-mock.el
index 953bcde7d1..ada4e7dc8b 100644
--- a/el-mock.el
+++ b/el-mock.el
@@ -149,17 +149,16 @@ When you adapt Emacs Lisp Mock to a testing framework,
wrap test method around t
-stubbed-functions
-mocked-functions
(in-mocking t)
- any-error)
+ (any-error t))
;; (setplist 'mock-original-func nil)
;; (setplist 'mock-call-count nil)
(unwind-protect
- (condition-case e
+ (prog1
(funcall body-fn)
- (error (setq any-error e)))
+ (setq any-error nil))
(mapc #'stub/teardown -stubbed-functions)
(unwind-protect
- (if any-error
- (signal (car any-error) (cdr any-error))
+ (unless any-error
(mock-verify))
(mapc #'mock/teardown -mocked-functions)))))
diff --git a/test/el-mock-test.el b/test/el-mock-test.el
index 70c202e43b..b539be8b47 100644
--- a/test/el-mock-test.el
+++ b/test/el-mock-test.el
@@ -364,3 +364,20 @@
(mock (foo 1))
(foo)))
)
+
+(defun el-mock-test--signal ()
+ (error "Foo"))
+
+
+(ert-deftest preserve-stacktrace ()
+ "Test that mocking doesn’t mess with the backtrace recorded by
+‘ert-run-test’."
+ (let ((result (ert-run-test
+ (make-ert-test
+ :body (lambda ()
+ (with-mock (el-mock-test--signal)))))))
+ (should (ert-test-failed-p result))
+ (should (equal (ert-test-failed-condition result)
+ '(error "Foo")))
+ (should (equal (car-safe (ert-test-failed-backtrace result))
+ '(t el-mock-test--signal)))))
- [nongnu] branch scratch/el-mock created (now 80ded09125), Stefan Monnier, 2023/08/28
- [nongnu] scratch/el-mock 3ab575c661 01/64: first commit, Stefan Monnier, 2023/08/28
- [nongnu] scratch/el-mock e5ff8a688a 02/64: Add el-mock.el, Stefan Monnier, 2023/08/28
- [nongnu] scratch/el-mock bdcebf9f72 03/64: Add README note., Stefan Monnier, 2023/08/28
- [nongnu] scratch/el-mock a99d6514a0 04/64: Add @rejeep as maintainer., Stefan Monnier, 2023/08/28
- [nongnu] scratch/el-mock 10c9fac555 07/64: ad-safe-fset is obsolete (replaced by fset), Stefan Monnier, 2023/08/28
- [nongnu] scratch/el-mock 3069931de7 12/64: v1.25.1, Stefan Monnier, 2023/08/28
- [nongnu] scratch/el-mock 24337b85e8 28/64: Preserve ERT backtrace,
Stefan Monnier <=
- [nongnu] scratch/el-mock 8afde8b145 05/64: Change URL., Stefan Monnier, 2023/08/28
- [nongnu] scratch/el-mock bd129d9a63 08/64: Merge branch 'ad-safe-fset-obsolete', Stefan Monnier, 2023/08/28
- [nongnu] scratch/el-mock 718e821e9c 09/64: Release v1.25.0., Stefan Monnier, 2023/08/28
- [nongnu] scratch/el-mock 6d040af21e 10/64: Skip empty messages, Stefan Monnier, 2023/08/28
- [nongnu] scratch/el-mock b61b8f76a1 14/64: Remove how to save note, Stefan Monnier, 2023/08/28
- [nongnu] scratch/el-mock 5ee1a1a5de 15/64: Move tests from el-mock.el, Stefan Monnier, 2023/08/28
- [nongnu] scratch/el-mock e349674b8a 18/64: Add LICENSE file, Stefan Monnier, 2023/08/28
- [nongnu] scratch/el-mock 8e9f1fbfec 31/64: Fix tests for Emacs 25.1, Stefan Monnier, 2023/08/28
- [nongnu] scratch/el-mock e072098b76 06/64: Add Cask., Stefan Monnier, 2023/08/28
- [nongnu] scratch/el-mock 12aa28e785 11/64: Merge branch 'gracjan-empty-message', Stefan Monnier, 2023/08/28