Skip to content

Commit b6de2bb

Browse files
jbergstroempgrange
authored andcommitted
chore(perf): cache prepare/teardown lookup
1 parent 7495e45 commit b6de2bb

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
@@ -276,15 +276,15 @@ run_tests() {
276276
notify_test_skipped "$skipped_test"
277277
done
278278

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

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

0 commit comments

Comments
 (0)