Skip to content

Commit ca72321

Browse files
committed
chore(perf): cache prepare/teardown lookup
1 parent 8b7b59d commit ca72321

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

bash_unit

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,15 @@ run_tests() {
274274
notify_test_skipped "$skipped_test"
275275
done
276276

277+
local has_setup=0 has_teardown=0
278+
declare -F | "$GREP" ' setup$' >/dev/null && has_setup=1
279+
declare -F | "$GREP" ' teardown$' >/dev/null && has_teardown=1
280+
277281
for test in $tests_to_run
278282
do
279283
(
280284
local status=0
281-
declare -F | "$GREP" ' setup$' >/dev/null && setup
282-
# make sure teardown runs even if the test fails
283-
local has_teardown=0
284-
# shellcheck disable=SC2034 # foo appears unused. Verify it or export it.
285-
declare -F | "$GREP" ' teardown$' >/dev/null && has_teardown=1
285+
((has_setup)) && setup
286286
trap '((has_teardown)) && teardown' EXIT
287287

288288
# NOTE: we do *not* want to use the || or && syntax with the subshell

0 commit comments

Comments
 (0)