Skip to content
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

Cleanup actions are only run if no tests failed #80

Closed
jluebbe opened this issue Aug 9, 2018 · 8 comments
Closed

Cleanup actions are only run if no tests failed #80

jluebbe opened this issue Aug 9, 2018 · 8 comments

Comments

@jluebbe
Copy link

jluebbe commented Aug 9, 2018

The cleanup helper documentation says:

Public: Schedule cleanup commands to be run unconditionally when all tests
have run.

This can be used to clean up things like test databases. It is not needed to
clean up temporary files, as test_done already does that.

The test_done() function actually only runs the cleanup actions if the $test_failure variable is 0 (no failed tests). As we use this to stop a local dbus-daemon, we have leftover processes as soon as a single test case fails. It works fine if we add test_eval_ "$final_cleanup" to the *) case as well.

Is this behavior intended? If so, I was confused by the documentation.

@jluebbe jluebbe changed the title Cleanup actions are only run if no tests failed. Cleanup actions are only run if no tests failed Aug 9, 2018
@felipec
Copy link
Owner

felipec commented May 16, 2021

I think this behavior is intended. At least the git test suite does the same thing.

@chriscool
Copy link
Collaborator

Yeah, this should probably be explained better in the doc.

@felipec
Copy link
Owner

felipec commented Mar 20, 2023

@jluebbe I think what you want is implemented in Git upstream with test_atexit. That's called truly unconditionally when the tests are done. Even if the test crashes.

@LeSpocky
Copy link
Contributor

Stumbled over the same thing. Documentation mismatches behavior! What fix would you prefer in a PR?

@felipec
Copy link
Owner

felipec commented Aug 7, 2023

@LeSpocky What explained in my previous comment: port test_atexit from Junio's git so that can be used to specify actions that should be done at the end regardless if tests fail or not.

@LeSpocky
Copy link
Contributor

LeSpocky commented Aug 7, 2023

You mean this one? https://github.com/git/git/blob/master/t/test-lib-functions.sh#L1364

Thing is: final_cleanup is not present in upstream Git test suite, but according to sharness docs it serves the same purpose as test_atexit as far as I understand both docs. Or let me ask the other way round: what would be the purpose of final_cleanup after adding test_atexit in sharness? How would both differ and would it really be necessary to have two of them? The problem at hand for sharness here is: documentation mismatches behaviour. Either one has to be fixed.

@felipec
Copy link
Owner

felipec commented Aug 23, 2023

You mean this one? https://github.com/git/git/blob/master/t/test-lib-functions.sh#L1364

No, this one: https://github.com/git/git/blob/master/t/test-lib-functions.sh#L1397

Thing is: final_cleanup is not present in upstream Git test suite, but according to sharness docs it serves the same purpose as test_atexit as far as I understand both docs.

I don't think so. One says it runs at unconditionally at the end of the test script, and the other unconditionally after all the tasks have been run. It's not the same.

Or let me ask the other way round: what would be the purpose of final_cleanup after adding test_atexit in sharness?

I don't know.

How would both differ and would it really be necessary to have two of them?

It's probably not necessary to have both of them. But I believe test_atexit can be added without removing final_cleanup.

Eventually we probably should get rid of final_cleanup as most people would want to use test_atexit instead. But we could live with both for a while.

@felipec
Copy link
Owner

felipec commented Apr 24, 2024

After reading the original commit bfa91e4 it seems clear the intention was to serve as git's test_atexit, but the wording was not the best.

So I've updated the code to make cleanup work as test_atexit, now it's run on failure too, and if the script ends in the middle, or when running in interactive mode, the final-cleanup stuff is executed.

There are some subtle differences with test_atexit probably not important for the vast majority of people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants