From 97ec9758769297fb1a1eb278510dd551f3556b6f Mon Sep 17 00:00:00 2001 From: Walheimat Date: Thu, 16 Nov 2023 21:43:14 +0100 Subject: [PATCH] fix: wrap setup and body execution in unwind-protect --- CHANGELOG.md | 2 ++ bydi.el | 11 +++++--- test/bydi-test.el | 65 ++++++++++++++++++++++++++++++----------------- 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc83ec6..71f59b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Fixed - The package name in the Makefile. +- The execution of `bydi` is now wrapped by special form + `unwind-protect` to avoid a faulty test from breaking other tests. ## [v0.5.3] diff --git a/bydi.el b/bydi.el index 49a7060..79f5d99 100644 --- a/bydi.el +++ b/bydi.el @@ -117,9 +117,14 @@ of this form." (bydi-mock--sometimes t) ,@(bydi-mock--mocks instructions)) - (bydi--setup) - ,@body - (bydi--teardown)))) + + (unwind-protect + + (progn + (bydi--setup) + ,@body) + + (bydi--teardown))))) ;;; -- Calling macros diff --git a/test/bydi-test.el b/test/bydi-test.el index 0f77868..4402b24 100644 --- a/test/bydi-test.el +++ b/test/bydi-test.el @@ -34,9 +34,11 @@ (lambda (&rest r) (interactive) (apply 'bydi--record (list 'bydi-ra r))))) - (bydi--setup) - (should (always)) - (bydi--teardown)))) + (unwind-protect + (progn + (bydi--setup) + (should (always))) + (bydi--teardown))))) (ert-deftest bydi-with-mock--old-usage () (bydi-match-expansion @@ -58,9 +60,11 @@ (interactive) (apply 'bydi--record (list 'format r)) (apply (lambda (a &rest _args) a) r)))) - (bydi--setup) - (should (always)) - (bydi--teardown)))) + (unwind-protect + (progn + (bydi--setup) + (should (always))) + (bydi--teardown))))) (ert-deftest bydi-with-mock--explicit () (bydi-match-expansion @@ -94,9 +98,11 @@ (interactive) (apply 'bydi--record (list 'buffer-live-p r)) (apply #'always r)))) - (bydi--setup) - (should (always)) - (bydi--teardown)))) + (unwind-protect + (progn + (bydi--setup) + (should (always))) + (bydi--teardown))))) (ert-deftest bydi-with-mock--spies-and-watchers () (bydi-match-expansion @@ -115,9 +121,12 @@ (interactive) (apply 'bydi--record (list 'abbrev-table-p r)) (apply #'bydi-rt r)))) - (bydi--setup) - (should (always)) - (bydi--teardown)))) + + (unwind-protect + (progn + (bydi--setup) + (should (always))) + (bydi--teardown))))) (ert-deftest bydi-with-mock--shorthands () (bydi-match-expansion @@ -145,9 +154,11 @@ (interactive) (apply 'bydi--record (list 'derived-mode-p r)) (funcall #'bydi-mock--sometimes)))) - (bydi--setup) - (should (always)) - (bydi--teardown)))) + (unwind-protect + (progn + (bydi--setup) + (should (always))) + (bydi--teardown))))) (ert-deftest bydi-with-mock--single-function () (bydi-match-expansion @@ -162,9 +173,11 @@ (lambda (&rest r) (interactive) (apply 'bydi--record (list 'bydi-rf r))))) - (bydi--setup) - (should (always)) - (bydi--teardown)))) + (unwind-protect + (progn + (bydi--setup) + (should (always))) + (bydi--teardown))))) (ert-deftest bydi-with-mock--unmockable () (bydi-with-mock (bydi-mock--check) @@ -185,9 +198,11 @@ (apply 'bydi--record (list 'new-line r)) (apply #'ignore r)))) - (bydi--setup) - nil - (bydi--teardown)))) + (unwind-protect + (progn + (bydi--setup) + nil) + (bydi--teardown))))) (bydi-was-called bydi-mock--check))) (ert-deftest bydi-with-mock--returning-nil () @@ -207,9 +222,11 @@ (interactive) (apply 'bydi--record (list 'ignore r))))) - (bydi--setup) - nil - (bydi--teardown))) + (unwind-protect + (progn + (bydi--setup) + nil) + (bydi--teardown)))) (bydi-was-called-with bydi--warn "Returning 'nil' may lead to unexpected results")))