Skip to content

Commit

Permalink
fix: wrap setup and body execution in unwind-protect
Browse files Browse the repository at this point in the history
  • Loading branch information
Walheimat committed Nov 16, 2023
1 parent 5b7b0f2 commit 97ec975
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
11 changes: 8 additions & 3 deletions bydi.el
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
65 changes: 41 additions & 24 deletions test/bydi-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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 ()
Expand All @@ -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")))

Expand Down

0 comments on commit 97ec975

Please sign in to comment.