From 3bdc4242094d0a07aea1843cfbf422268c66457b Mon Sep 17 00:00:00 2001 From: Torgny Lyon Date: Sat, 2 May 2020 17:52:46 +0200 Subject: [PATCH] Call teardowns in cleanup only when interrupted This is an attempt to fix issue #112. --- shunit2 | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/shunit2 b/shunit2 index 2850370..7b43825 100755 --- a/shunit2 +++ b/shunit2 @@ -130,7 +130,6 @@ __shunit_reportGenerated=${SHUNIT_FALSE} # Is report generated. __shunit_script='' # Filename of unittest script (standalone mode). __shunit_skip=${SHUNIT_FALSE} # Is skipping enabled. __shunit_suite='' # Suite of tests to execute. -__shunit_clean=${SHUNIT_FALSE} # _shunit_cleanup() was already called. # ANSI colors (populated by _shunit_configureColor()). __shunit_ansi_none='' @@ -1006,22 +1005,17 @@ _shunit_cleanup() { _shunit_error "unrecognized trap value (${_shunit_name_})" ;; esac + if ${__SHUNIT_BUILTIN} [ "${_shunit_name_}" != 'EXIT' ]; then _shunit_warn "trapped and now handling the (${_shunit_name_}) signal" - fi - - # Do our work. - if ${__SHUNIT_BUILTIN} [ ${__shunit_clean} -eq ${SHUNIT_FALSE} ]; then # Ensure tear downs are only called once. - __shunit_clean=${SHUNIT_TRUE} - tearDown || _shunit_warn 'tearDown() returned non-zero return code.' oneTimeTearDown || \ _shunit_warn 'oneTimeTearDown() returned non-zero return code.' - - command rm -fr "${__shunit_tmpDir}" fi + command rm -fr "${__shunit_tmpDir}" + if ${__SHUNIT_BUILTIN} [ "${_shunit_name_}" != 'EXIT' ]; then # Handle all non-EXIT signals. trap - 0 # Disable EXIT trap.