@@ -77,14 +77,22 @@ function _zunit_execute_test() {
77
77
# and the error will be reported back to the test runner
78
78
setopt ERR_EXIT
79
79
80
+ # Add an exit handler which calls the teardown function if it is
81
+ # defined and the test exits early
82
+ if (( \$ +functions[__zunit_test_teardown] )); then
83
+ zshexit() {
84
+ __zunit_test_teardown >/dev/null 2>&1
85
+ }
86
+ fi
87
+
80
88
# Create some local variables to store test state in
81
89
integer _zunit_assertion_count=0
82
90
integer state
83
91
local output
84
92
typeset -a lines
85
93
86
94
# If a setup function is defined, run it now
87
- if (( $+functions[__zunit_test_setup] )); then
95
+ if (( \ $ +functions[__zunit_test_setup] )); then
88
96
__zunit_test_setup >/dev/null 2>&1
89
97
fi
90
98
@@ -93,10 +101,13 @@ function _zunit_execute_test() {
93
101
${body}
94
102
95
103
# If a teardown function is defined, run it now
96
- if (( $+functions[__zunit_test_teardown] )); then
104
+ if (( \ $ +functions[__zunit_test_teardown] )); then
97
105
__zunit_test_teardown >/dev/null 2>&1
98
106
fi
99
107
108
+ # Remove the error handler
109
+ zshexit() {}
110
+
100
111
# Check the assertion count, and if it is 0, return
101
112
# the warning exit code
102
113
[[ \$ _zunit_assertion_count -gt 0 ]] || return 248
@@ -127,7 +138,6 @@ function _zunit_execute_test() {
127
138
return 126
128
139
fi
129
140
130
-
131
141
# Check if a time limit has been specified. We only do this if
132
142
# the ZSH version is at least 5.1.0, since older versions of ZSH
133
143
# are unable to handle asynchronous processes in the way we need
0 commit comments