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

testscript: remove temp dirs when finishing once again #290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mvdan
Copy link
Collaborator

@mvdan mvdan commented Feb 24, 2025

(see commit message)

@mvdan mvdan requested a review from rogpeppe February 24, 2025 17:06
Copy link
Owner

@rogpeppe rogpeppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one small suggestion.

exit := m.Run()
// The [os.Exit] below prevents defers from running, so we must clean up here.
// The defer above is still useful in case we fail before we get to this point.
cleanup()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively (and arguably slightly cleaner) you could factor all the Main code into a separate function (e.g. main1) that returns int, and change Main to just do os.Exit(main1(...))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done; PTAL again as I ended up only factoring out part of the Main code, given that the other branch has no control over whether the user's command calls os.Exit.

The recent transition from RunMain to Main meant that we started
calling os.Exit directly when Main finished.
However, we failed to spot that os.Exit would make our earlier deferred
cleanup of the temporary directory not run at all.

Spotted because my /tmp started getting filled up after a few hours
of development, and I found a suspiciously large number of
testscript-looking directories.
@mvdan mvdan force-pushed the testscript-cleanup branch from 1fc10ab to 4f35e07 Compare February 24, 2025 17:20
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

Successfully merging this pull request may close these issues.

2 participants