-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
oneTimeTearDown()/tearDown() is being called an additional time at the end of execution #112
Comments
Looking into it, I only see warnings being raised if these functions do not exit successfully, but do not see why they would be called at the end of execution. |
These are being called as part of the EXIT trap. Related to #108. |
Right, I wasn't familiarized with the entire topology. Looked things over and there is still a fundamental flaw since the exit code at the end of the script gets caught by the trap on successful runs so the 0 signal triggers
will trigger the tear downs again. I don't know what @kward's perspective is and whether the idea was to have termination always happen from within |
This can be used as sort of a hacky workaround:
|
I tried adding the above code inside tearDown() but get the following error - is there something else that needs to be enabled or set? in oneTimeSetUp the test script: #! /bin/sh #Load test helpers. testOne() { testTwo() { setUp() { tearDown() { oneTimeSetUp() { oneTimeTearDown() { #Load and run shUnit2. |
My workaround is to create a directory in oneTimeSetUp and wrap the tear down code inside a check for that directory inside oneTimeTearDown - second time around, directory is not there, so code is skipped |
This is an attempt to fix issue kward#112.
* tearDown actually runs an additional time after all test_* functions have been called. kward/shunit2#112
* GitHub Action's macOS image provides a different version of shunit2. * shnit2 runs tearDown an additional time after all test_* functions have been called. kward/shunit2#112
Is this still a problem in the HEAD release? |
Yes. |
Yes, tested on release 2.1.8. My output looks like this:
|
Here is a simple test that exhibits the issue
#! /bin/bash
# assume this test script is in a subdirectory under the shunit directory;
a sibling of examples
# Load test helpers.
. ../shunit2_test_helpers
testOne() {
assertTrue 0
}
testTwo() {
assertTrue 0
}
setUp() {
echo "in setUp"
}
tearDown() {
echo "in tearDown"
}
oneTimeSetUp() {
#oneTimeTearDown gets called one extra time at exit, to prevent that add
and check a guard file
#touch "${SHUNIT_TMPDIR}/guard.tmp"
echo "in oneTimeSetUp"
}
oneTimeTearDown() {
#oneTimeTearDown gets called one extra time at exit, to prevent that add
and check a guard file
#if [ -f "${SHUNIT_TMPDIR}/guard.tmp" ]; then
echo "in oneTimeTearDown"
#fi
}
# Load and run shUnit2.
. ../shunit2
…On Tue, Nov 23, 2021 at 5:04 AM David Bajger ***@***.***> wrote:
Yes, tested on release 2.1.8. My output looks like this:
Calling teardown...
Ran 4 tests.
OK
Calling teardown...
PharoLauncherCommonFunctions.sh: line 45: ./pharo-launcher.sh: No such file or directory
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#112 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACX7JVGCV3JIOL4VEQB2HLUNNRKTANCNFSM4GXHLOGA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
--
Steve Cline ***@***.*** http://www.clines.org
http://www.linkedin.com/in/stevecline
"Be right, and then be easy to live with, if possible, but in that order."
- Ezra Taft Benson
encrypted email to ***@***.***
|
I had the same problem. The following modification resolved my issue.
|
Additional oneTimeTearDown() was called at shunit2 exit because there seemed to be no set for __shunit_clean flag. Fix for kward#112
Could we please get one of the PR/suggestions to fix this merged into main on kward and get a new release? I just bumped into this and it took some troubleshooting to figure it out. Would be great to avoid having shunit2 executing the Here's some of the suggestions I've found: Thank you very much 👍 N.B. @williamdes are you the "savior" once again 💯 ? |
An alternative to this is to set a global env. var in E.g. oneTimeSetUp()
{
SOME_SETUP_LOGIC_HERE
export avoidDoubleTearDownExecution="true"
}
....
....
oneTimeTearDown()
{
if [[ "${avoidDoubleTeadDownExecution}" == "true" ]]; then
SOME_TEARDOWN_LOGIC_HERE
unset -v avoidDoubleTearDownExecution
fi
} The above makes the tear down, in clean cases, where what's in #108 is not needed, only run once. Enjoy 🥇 |
I have been pulling master and had functions that were executing within these hooks and saw what seems to be some unintended behavior. Example file as show below:
Output:
The text was updated successfully, but these errors were encountered: