testscript: remove temp dirs when finishing once again#290
Merged
mvdan merged 1 commit intorogpeppe:masterfrom Feb 25, 2025
Merged
testscript: remove temp dirs when finishing once again#290mvdan merged 1 commit intorogpeppe:masterfrom
mvdan merged 1 commit intorogpeppe:masterfrom
Conversation
rogpeppe
approved these changes
Feb 24, 2025
Owner
rogpeppe
left a comment
There was a problem hiding this comment.
LGTM with one small suggestion.
testscript/exe.go
Outdated
| 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() |
Owner
There was a problem hiding this comment.
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(...))
Collaborator
Author
There was a problem hiding this comment.
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.
1fc10ab to
4f35e07
Compare
rogpeppe
approved these changes
Feb 25, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(see commit message)